diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-01-23 15:13:12 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-01-23 15:13:12 -0800 |
| commit | 3a6571a0191df8ff000384937a6254f378ca23cf (patch) | |
| tree | b1a4c78efef26896769c69db7cd5b500a7c877f4 | |
| parent | 6d3ab4579d50f74cbe43373fa16ba875a97a8717 (diff) | |
| download | vcpkg-3a6571a0191df8ff000384937a6254f378ca23cf.tar.gz vcpkg-3a6571a0191df8ff000384937a6254f378ca23cf.zip | |
Add Strings::split() function
| -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; + } } |
