diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index b3ae9d79f5..7da364bc60 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -166,7 +166,7 @@ std::string cmGeneratorExpression::StripEmptyListElements( } static std::string extractAllGeneratorExpressions( - std::string const& input, + cm::string_view input, std::map>* collected) { std::string result; @@ -176,9 +176,9 @@ static std::string extractAllGeneratorExpressions( std::stack colons; // indices of ":" while ((pos = input.find("$<", lastPos)) != std::string::npos) { result += input.substr(lastPos, pos - lastPos); - starts.push(input.c_str() + pos); + starts.push(input.data() + pos); pos += 2; - char const* c = input.c_str() + pos; + char const* c = input.data() + pos; char const* const cStart = c; for (; *c; ++c) { if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) { @@ -209,7 +209,7 @@ static std::string extractAllGeneratorExpressions( } std::string::size_type const traversed = (c - cStart) + 1; if (!*c) { - result += "$<" + input.substr(pos, traversed); + result += cmStrCat("$<", input.substr(pos, traversed)); } pos += traversed; lastPos = pos; @@ -220,7 +220,7 @@ static std::string extractAllGeneratorExpressions( return cmGeneratorExpression::StripEmptyListElements(result); } -static std::string stripAllGeneratorExpressions(std::string const& input) +static std::string stripAllGeneratorExpressions(cm::string_view input) { return extractAllGeneratorExpressions(input, nullptr); } @@ -243,7 +243,7 @@ static void prefixItems(std::string const& content, std::string& result, } static std::string stripExportInterface( - std::string const& input, cmGeneratorExpression::PreprocessContext context, + cm::string_view input, cmGeneratorExpression::PreprocessContext context, cm::string_view importPrefix) { std::string result; @@ -282,7 +282,7 @@ static std::string stripExportInterface( assert(false && "Invalid position found"); } nestingLevel = 1; - char const* c = input.c_str() + pos; + char const* c = input.data() + pos; char const* const cStart = c; for (; *c; ++c) { if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) { @@ -300,7 +300,8 @@ static std::string stripExportInterface( result += input.substr(pos, c - cStart); } else if (context == cmGeneratorExpression::InstallInterface && foundGenex == FoundGenex::InstallInterface) { - std::string const content = input.substr(pos, c - cStart); + std::string const content = + static_cast(input.substr(pos, c - cStart)); if (!importPrefix.empty()) { prefixItems(content, result, importPrefix); } else { @@ -390,7 +391,7 @@ void cmGeneratorExpression::Split(std::string const& input, } } -std::string cmGeneratorExpression::Preprocess(std::string const& input, +std::string cmGeneratorExpression::Preprocess(cm::string_view input, PreprocessContext context, cm::string_view importPrefix) { diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 3897e67b61..a84b7ac7b2 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -65,7 +65,7 @@ public: InstallInterface }; - static std::string Preprocess(std::string const& input, + static std::string Preprocess(cm::string_view input, PreprocessContext context, cm::string_view importPrefix = {}); diff --git a/Source/cmStringReplaceHelper.cxx b/Source/cmStringReplaceHelper.cxx index 6dad0b07ed..0e1845776e 100644 --- a/Source/cmStringReplaceHelper.cxx +++ b/Source/cmStringReplaceHelper.cxx @@ -20,8 +20,7 @@ cmStringReplaceHelper::cmStringReplaceHelper(std::string const& regex, this->ParseReplaceExpression(); } -bool cmStringReplaceHelper::Replace(std::string const& input, - std::string& output) +bool cmStringReplaceHelper::Replace(cm::string_view input, std::string& output) { output.clear(); @@ -36,7 +35,7 @@ bool cmStringReplaceHelper::Replace(std::string const& input, auto& re = this->RegularExpression; std::string::size_type base = 0; unsigned optNonEmpty = 0; - while (re.find(input, base, optAnchor | optNonEmpty)) { + while (re.find(input.data(), base, optAnchor | optNonEmpty)) { if (this->Makefile) { this->Makefile->ClearMatches(); this->Makefile->StoreMatches(re); diff --git a/Source/cmStringReplaceHelper.h b/Source/cmStringReplaceHelper.h index ffe998341a..ef1c259955 100644 --- a/Source/cmStringReplaceHelper.h +++ b/Source/cmStringReplaceHelper.h @@ -6,6 +6,8 @@ #include #include +#include + #include "cmsys/RegularExpression.hxx" class cmMakefile; @@ -25,7 +27,7 @@ public: return this->ValidReplaceExpression; } - bool Replace(std::string const& input, std::string& output); + bool Replace(cm::string_view input, std::string& output); std::string const& GetError() { return this->ErrorString; } diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx index b76dd661c1..9c029f507f 100644 --- a/Source/cmTimestamp.cxx +++ b/Source/cmTimestamp.cxx @@ -36,7 +36,7 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -std::string cmTimestamp::CurrentTime(std::string const& formatString, +std::string cmTimestamp::CurrentTime(cm::string_view formatString, bool utcFlag) const { // get current time with microsecond resolution @@ -63,11 +63,12 @@ std::string cmTimestamp::CurrentTime(std::string const& formatString, } return this->CreateTimestampFromTimeT(currentTimeT, microseconds, - formatString, utcFlag); + static_cast(formatString), + utcFlag); } std::string cmTimestamp::FileModificationTime(char const* path, - std::string const& formatString, + cm::string_view formatString, bool utcFlag) const { std::string real_path = @@ -89,8 +90,8 @@ std::string cmTimestamp::FileModificationTime(char const* path, } uv_fs_req_cleanup(&req); - return this->CreateTimestampFromTimeT(mtime, microseconds, formatString, - utcFlag); + return this->CreateTimestampFromTimeT( + mtime, microseconds, static_cast(formatString), utcFlag); } std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT, diff --git a/Source/cmTimestamp.h b/Source/cmTimestamp.h index 1057cc9f1b..f6bff01952 100644 --- a/Source/cmTimestamp.h +++ b/Source/cmTimestamp.h @@ -8,6 +8,8 @@ #include #include +#include + /** \class cmTimestamp * \brief Utility class to generate string representation of a timestamp * @@ -15,10 +17,10 @@ class cmTimestamp { public: - std::string CurrentTime(std::string const& formatString, bool utcFlag) const; + std::string CurrentTime(cm::string_view formatString, bool utcFlag) const; std::string FileModificationTime(char const* path, - std::string const& formatString, + cm::string_view formatString, bool utcFlag) const; std::string CreateTimestampFromTimeT(time_t timeT, std::string formatString, diff --git a/Source/cmUuid.cxx b/Source/cmUuid.cxx index bc2ff59622..4f1f9a390f 100644 --- a/Source/cmUuid.cxx +++ b/Source/cmUuid.cxx @@ -10,7 +10,7 @@ static std::array const kUuidGroups = { { 4, 2, 2, 2, 6 } }; std::string cmUuid::FromMd5(std::vector const& uuidNamespace, - std::string const& name) const + cm::string_view name) const { std::vector hashInput; this->CreateHashInput(uuidNamespace, name, hashInput); @@ -24,7 +24,7 @@ std::string cmUuid::FromMd5(std::vector const& uuidNamespace, } std::string cmUuid::FromSha1(std::vector const& uuidNamespace, - std::string const& name) const + cm::string_view name) const { std::vector hashInput; this->CreateHashInput(uuidNamespace, name, hashInput); @@ -38,7 +38,7 @@ std::string cmUuid::FromSha1(std::vector const& uuidNamespace, } void cmUuid::CreateHashInput(std::vector const& uuidNamespace, - std::string const& name, + cm::string_view name, std::vector& output) const { output = uuidNamespace; @@ -46,7 +46,7 @@ void cmUuid::CreateHashInput(std::vector const& uuidNamespace, if (!name.empty()) { output.resize(output.size() + name.size()); - memcpy(output.data() + uuidNamespace.size(), name.c_str(), name.size()); + memcpy(output.data() + uuidNamespace.size(), name.data(), name.size()); } } @@ -67,7 +67,7 @@ std::string cmUuid::FromDigest(unsigned char const* digest, return this->BinaryToString(uuid); } -bool cmUuid::StringToBinary(std::string const& input, +bool cmUuid::StringToBinary(cm::string_view input, std::vector& output) const { output.clear(); @@ -126,7 +126,7 @@ std::string cmUuid::ByteToHex(unsigned char inputByte) const return result; } -bool cmUuid::StringToBinaryImpl(std::string const& input, +bool cmUuid::StringToBinaryImpl(cm::string_view input, std::vector& output) const { if (input.size() % 2) { diff --git a/Source/cmUuid.h b/Source/cmUuid.h index cf51ecef31..f6d70679de 100644 --- a/Source/cmUuid.h +++ b/Source/cmUuid.h @@ -7,6 +7,8 @@ #include #include +#include + /** \class cmUuid * \brief Utility class to generate UUIDs as defined by RFC4122 * @@ -15,25 +17,25 @@ class cmUuid { public: std::string FromMd5(std::vector const& uuidNamespace, - std::string const& name) const; + cm::string_view name) const; std::string FromSha1(std::vector const& uuidNamespace, - std::string const& name) const; + cm::string_view name) const; - bool StringToBinary(std::string const& input, + bool StringToBinary(cm::string_view input, std::vector& output) const; private: std::string ByteToHex(unsigned char byte) const; void CreateHashInput(std::vector const& uuidNamespace, - std::string const& name, + cm::string_view name, std::vector& output) const; std::string FromDigest(unsigned char const* digest, unsigned char version) const; - bool StringToBinaryImpl(std::string const& input, + bool StringToBinaryImpl(cm::string_view input, std::vector& output) const; std::string BinaryToString(unsigned char const* input) const;