diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-10-19 19:38:23 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-10-19 19:57:58 -0700 |
| commit | b1d5d8e8baf4bd5132de4415a0168432600ce998 (patch) | |
| tree | 86a29d2b753c53be0b1c321d3c4bcd52a1be57e9 | |
| parent | c4ceadcc8882a2849a332de933f41cd8499a51dc (diff) | |
| download | vcpkg-b1d5d8e8baf4bd5132de4415a0168432600ce998.tar.gz vcpkg-b1d5d8e8baf4bd5132de4415a0168432600ce998.zip | |
Introduce Strings::replace_all()
| -rw-r--r-- | toolsrc/include/vcpkg/base/strings.h | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/base/strings.cpp | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg/base/strings.h b/toolsrc/include/vcpkg/base/strings.h index d263e3b6b..5b03286de 100644 --- a/toolsrc/include/vcpkg/base/strings.h +++ b/toolsrc/include/vcpkg/base/strings.h @@ -76,6 +76,8 @@ namespace vcpkg::Strings return join(delimiter, v, [](const Element& x) -> const Element& { return x; }); } + std::string replace_all(std::string&& s, const std::string& search, const std::string& rep); + void trim(std::string* s); std::string trimmed(const std::string& s); diff --git a/toolsrc/src/vcpkg/base/strings.cpp b/toolsrc/src/vcpkg/base/strings.cpp index af41eed9a..36efc3adc 100644 --- a/toolsrc/src/vcpkg/base/strings.cpp +++ b/toolsrc/src/vcpkg/base/strings.cpp @@ -114,6 +114,17 @@ namespace vcpkg::Strings #endif } + std::string replace_all(std::string&& s, const std::string& search, const std::string& rep) + { + size_t pos = 0; + while ((pos = s.find(search, pos)) != std::string::npos) + { + s.replace(pos, search.size(), rep); + pos += rep.size(); + } + return std::move(s); + } + void trim(std::string* s) { s->erase(std::find_if_not(s->rbegin(), s->rend(), details::isspace).base(), s->end()); |
