diff options
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 3ba3640..e0005a0 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -176,36 +176,37 @@ void cmSystemTools::ExpandRegistryValues(std::string& source, } #endif -std::string cmSystemTools::EscapeQuotes(const std::string& str) +std::string cmSystemTools::EscapeQuotes(cm::string_view str) { std::string result; result.reserve(str.size()); - for (const char* ch = str.c_str(); *ch != '\0'; ++ch) { - if (*ch == '"') { + for (const char ch : str) { + if (ch == '"') { result += '\\'; } - result += *ch; + result += ch; } return result; } -std::string cmSystemTools::HelpFileName(std::string name) +std::string cmSystemTools::HelpFileName(cm::string_view str) { + std::string name(str); cmSystemTools::ReplaceString(name, "<", ""); cmSystemTools::ReplaceString(name, ">", ""); return name; } -std::string cmSystemTools::TrimWhitespace(const std::string& s) +std::string cmSystemTools::TrimWhitespace(cm::string_view str) { - std::string::const_iterator start = s.begin(); - while (start != s.end() && cm_isspace(*start)) { + auto start = str.begin(); + while (start != str.end() && cm_isspace(*start)) { ++start; } - if (start == s.end()) { - return ""; + if (start == str.end()) { + return std::string(); } - std::string::const_iterator stop = s.end() - 1; + auto stop = str.end() - 1; while (cm_isspace(*stop)) { --stop; } @@ -1121,7 +1122,7 @@ void cmSystemTools::GlobDirs(const std::string& path, } } -void cmSystemTools::ExpandListArgument(const std::string& arg, +void cmSystemTools::ExpandListArgument(cm::string_view arg, std::vector<std::string>& argsOut, bool emptyArgs) { @@ -1129,25 +1130,29 @@ void cmSystemTools::ExpandListArgument(const std::string& arg, if (!emptyArgs && arg.empty()) { return; } + // if there are no ; in the name then just copy the current string - if (arg.find(';') == std::string::npos) { - argsOut.push_back(arg); + if (arg.find(';') == cm::string_view::npos) { + argsOut.emplace_back(arg); return; } + std::string newArg; - const char* last = arg.c_str(); // Break the string at non-escaped semicolons not nested in []. int squareNesting = 0; - for (const char* c = last; *c; ++c) { + cm::string_view::iterator last = arg.begin(); + cm::string_view::iterator const cend = arg.end(); + for (cm::string_view::iterator c = last; c != cend; ++c) { switch (*c) { case '\\': { // We only want to allow escaping of semicolons. Other // escapes should not be processed here. - const char* next = c + 1; - if (*next == ';') { - newArg.append(last, c - last); + cm::string_view::iterator cnext = c + 1; + if ((cnext != cend) && *cnext == ';') { + newArg.append(last, c); // Skip over the escape character - last = c = next; + last = cnext; + c = cnext; } } break; case '[': { @@ -1160,7 +1165,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg, // Break the string here if we are not nested inside square // brackets. if (squareNesting == 0) { - newArg.append(last, c - last); + newArg.append(last, c); // Skip over the semicolon last = c + 1; if (!newArg.empty() || emptyArgs) { @@ -1175,15 +1180,15 @@ void cmSystemTools::ExpandListArgument(const std::string& arg, } break; } } - newArg.append(last); + newArg.append(last, cend); if (!newArg.empty() || emptyArgs) { // Add the last argument if the string is not empty. - argsOut.push_back(newArg); + argsOut.push_back(std::move(newArg)); } } std::vector<std::string> cmSystemTools::ExpandedListArgument( - const std::string& arg, bool emptyArgs) + cm::string_view arg, bool emptyArgs) { std::vector<std::string> argsOut; ExpandListArgument(arg, argsOut, emptyArgs); |