summaryrefslogtreecommitdiff
path: root/Source/cmQtAutoGen.cxx
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2019-08-26 14:47:45 +0200
committerSebastian Holtermann <sebholt@xwmw.org>2019-08-27 17:31:45 +0200
commit8586077baae74c90056704c022aad8357788fa38 (patch)
tree3f5da61ae22ecf0c4b535c26bcdc42570fa1ad92 /Source/cmQtAutoGen.cxx
parent52a8fb2d532ca44ad9d995fc9c0d910177f594d2 (diff)
downloadcmake-8586077baae74c90056704c022aad8357788fa38.tar.gz
Autogen: Modernize cmQtAutoGen methods using cm::string_view
Diffstat (limited to 'Source/cmQtAutoGen.cxx')
-rw-r--r--Source/cmQtAutoGen.cxx104
1 files changed, 39 insertions, 65 deletions
diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx
index 9d29e5c951..dc7424e07e 100644
--- a/Source/cmQtAutoGen.cxx
+++ b/Source/cmQtAutoGen.cxx
@@ -12,6 +12,7 @@
#include <algorithm>
#include <array>
+#include <initializer_list>
#include <sstream>
#include <utility>
@@ -21,7 +22,7 @@
/// @arg valueOpts list of options that accept a value
void MergeOptions(std::vector<std::string>& baseOpts,
std::vector<std::string> const& newOpts,
- std::vector<std::string> const& valueOpts, bool isQt5)
+ std::initializer_list<cm::string_view> valueOpts, bool isQt5)
{
typedef std::vector<std::string>::iterator Iter;
typedef std::vector<std::string>::const_iterator CIter;
@@ -117,60 +118,42 @@ std::string const& cmQtAutoGen::GeneratorNameUpper(GenT genType)
std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc)
{
- std::string res;
- std::vector<std::string> lst;
+ std::array<cm::string_view, 3> lst;
+ decltype(lst)::size_type num = 0;
if (moc) {
- lst.emplace_back("AUTOMOC");
+ lst.at(num++) = "AUTOMOC";
}
if (uic) {
- lst.emplace_back("AUTOUIC");
+ lst.at(num++) = "AUTOUIC";
}
if (rcc) {
- lst.emplace_back("AUTORCC");
+ lst.at(num++) = "AUTORCC";
}
- switch (lst.size()) {
+ switch (num) {
case 1:
- res += lst.at(0);
- break;
+ return std::string(lst[0]);
case 2:
- res += lst.at(0);
- res += " and ";
- res += lst.at(1);
- break;
+ return cmStrCat(lst[0], " and ", lst[1]);
case 3:
- res += lst.at(0);
- res += ", ";
- res += lst.at(1);
- res += " and ";
- res += lst.at(2);
- break;
+ return cmStrCat(lst[0], ", ", lst[1], " and ", lst[2]);
default:
break;
}
- return res;
+ return std::string();
}
-std::string cmQtAutoGen::Quoted(std::string const& text)
+std::string cmQtAutoGen::Quoted(cm::string_view text)
{
- const std::array<std::pair<const char*, const char*>, 9> replaces = {
- { { "\\", "\\\\" },
- { "\"", "\\\"" },
- { "\a", "\\a" },
- { "\b", "\\b" },
- { "\f", "\\f" },
- { "\n", "\\n" },
- { "\r", "\\r" },
- { "\t", "\\t" },
- { "\v", "\\v" } }
- };
+ static std::initializer_list<std::pair<const char*, const char*>> const
+ replacements = { { "\\", "\\\\" }, { "\"", "\\\"" }, { "\a", "\\a" },
+ { "\b", "\\b" }, { "\f", "\\f" }, { "\n", "\\n" },
+ { "\r", "\\r" }, { "\t", "\\t" }, { "\v", "\\v" } };
- std::string res = text;
- for (auto const& pair : replaces) {
+ std::string res(text);
+ for (auto const& pair : replacements) {
cmSystemTools::ReplaceString(res, pair.first, pair.second);
}
- res = '"' + res;
- res += '"';
- return res;
+ return cmStrCat('"', res, '"');
}
std::string cmQtAutoGen::QuotedCommand(std::vector<std::string> const& command)
@@ -191,37 +174,31 @@ std::string cmQtAutoGen::QuotedCommand(std::vector<std::string> const& command)
return res;
}
-std::string cmQtAutoGen::SubDirPrefix(std::string const& filename)
+std::string cmQtAutoGen::SubDirPrefix(cm::string_view filename)
{
- std::string::size_type slash_pos = filename.rfind('/');
- if (slash_pos == std::string::npos) {
+ auto slashPos = filename.rfind('/');
+ if (slashPos == cm::string_view::npos) {
return std::string();
}
- return filename.substr(0, slash_pos + 1);
+ return std::string(filename.substr(0, slashPos + 1));
}
-std::string cmQtAutoGen::AppendFilenameSuffix(std::string const& filename,
- std::string const& suffix)
+std::string cmQtAutoGen::AppendFilenameSuffix(cm::string_view filename,
+ cm::string_view suffix)
{
- std::string res;
- auto pos = filename.rfind('.');
- if (pos != std::string::npos) {
- const auto it_dot = filename.begin() + pos;
- res.assign(filename.begin(), it_dot);
- res.append(suffix);
- res.append(it_dot, filename.end());
- } else {
- res = filename;
- res.append(suffix);
+ auto dotPos = filename.rfind('.');
+ if (dotPos == cm::string_view::npos) {
+ return cmStrCat(filename, suffix);
}
- return res;
+ return cmStrCat(filename.substr(0, dotPos), suffix,
+ filename.substr(dotPos, filename.size() - dotPos));
}
void cmQtAutoGen::UicMergeOptions(std::vector<std::string>& baseOpts,
std::vector<std::string> const& newOpts,
bool isQt5)
{
- static std::vector<std::string> const valueOpts = {
+ static std::initializer_list<cm::string_view> const valueOpts = {
"tr", "translate", "postfix", "generator",
"include", // Since Qt 5.3
"g"
@@ -233,9 +210,9 @@ void cmQtAutoGen::RccMergeOptions(std::vector<std::string>& baseOpts,
std::vector<std::string> const& newOpts,
bool isQt5)
{
- static std::vector<std::string> const valueOpts = { "name", "root",
- "compress",
- "threshold" };
+ static std::initializer_list<cm::string_view> const valueOpts = {
+ "name", "root", "compress", "threshold"
+ };
MergeOptions(baseOpts, newOpts, valueOpts, isQt5);
}
@@ -349,9 +326,8 @@ bool cmQtAutoGen::RccLister::list(std::string const& qrcFile,
// Log command
if (verbose) {
- std::string msg =
- cmStrCat("Running command:\n", QuotedCommand(cmd), '\n');
- cmSystemTools::Stdout(msg);
+ cmSystemTools::Stdout(
+ cmStrCat("Running command:\n", QuotedCommand(cmd), '\n'));
}
result = cmSystemTools::RunSingleCommand(
@@ -362,12 +338,10 @@ bool cmQtAutoGen::RccLister::list(std::string const& qrcFile,
error =
cmStrCat("The rcc list process failed for ", Quoted(qrcFile), '\n');
if (!rccStdOut.empty()) {
- error += rccStdOut;
- error += "\n";
+ error += cmStrCat(rccStdOut, '\n');
}
if (!rccStdErr.empty()) {
- error += rccStdErr;
- error += "\n";
+ error += cmStrCat(rccStdErr, '\n');
}
return false;
}