diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index de4109b113..1c73d5ae24 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1614,14 +1614,27 @@ cm::optional cmSystemTools::GetEnvVar(std::string const& var) return result; } -std::vector cmSystemTools::SplitEnvPath(std::string const& value) +std::vector cmSystemTools::SplitEnvPath(cm::string_view in) { #if defined(_WIN32) && !defined(__CYGWIN__) static cm::string_view sep = ";"_s; #else static cm::string_view sep = ":"_s; #endif - std::vector paths = cmTokenize(value, sep); + std::vector paths; + cm::string_view::size_type e = 0; + for (;;) { + cm::string_view::size_type b = in.find_first_not_of(sep, e); + if (b == cm::string_view::npos) { + break; + } + e = in.find_first_of(sep, b); + if (e == cm::string_view::npos) { + paths.emplace_back(in.substr(b)); + break; + } + paths.emplace_back(in.substr(b, e - b)); + } for (std::string& p : paths) { SystemTools::ConvertToUnixSlashes(p); } diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index d74a6e1c16..dab96f0638 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -399,7 +399,8 @@ public: std::string const& in); static cm::optional GetEnvVar(std::string const& var); - static std::vector SplitEnvPath(std::string const& value); + + static std::vector SplitEnvPath(cm::string_view in); static std::string ToNormalizedPathOnDisk(std::string p);