From b1d5d8e8baf4bd5132de4415a0168432600ce998 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 19 Oct 2017 19:38:23 -0700 Subject: Introduce Strings::replace_all() --- toolsrc/src/vcpkg/base/strings.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'toolsrc/src') 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()); -- cgit v1.2.3