diff options
| -rw-r--r-- | toolsrc/include/vcpkg_Strings.h | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Strings.cpp | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg_Strings.h b/toolsrc/include/vcpkg_Strings.h index 28853cb5d..cb5d2334c 100644 --- a/toolsrc/include/vcpkg_Strings.h +++ b/toolsrc/include/vcpkg_Strings.h @@ -75,4 +75,6 @@ namespace vcpkg::Strings std::string trimmed(const std::string& s); void trim_all_and_remove_whitespace_strings(std::vector<std::string>* strings); + + std::vector<std::string> split(const std::string& s, const std::string& delimiter); } diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index cf7d3b0ee..16477a45c 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -119,4 +119,25 @@ namespace vcpkg::Strings return s == ""; }), strings->end()); } + + std::vector<std::string> split(const std::string& s, const std::string& delimiter) + { + std::vector<std::string> output; + + size_t i = 0; + size_t pos = s.find(delimiter); + while (pos != std::string::npos) + { + output.push_back(s.substr(i, pos - i)); + i = ++pos; + pos = s.find(delimiter, pos); + + if (pos == std::string::npos) + { + output.push_back(s.substr(i, s.length())); + } + } + + return output; + } } |
