diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-10-20 16:43:44 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-10-23 16:11:13 -0700 |
| commit | 23702360ce912b1827afe5559de936cc9a24cd0c (patch) | |
| tree | 4fe500c5d9f6993699d82a966e78b9698e5c96f5 /toolsrc | |
| parent | 92d1a53215b2cc23dc090368d5218d42e195c478 (diff) | |
| download | vcpkg-23702360ce912b1827afe5559de936cc9a24cd0c.tar.gz vcpkg-23702360ce912b1827afe5559de936cc9a24cd0c.zip | |
Merge trim() and trimmed() functions
Diffstat (limited to 'toolsrc')
| -rw-r--r-- | toolsrc/include/vcpkg/base/strings.h | 4 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/base/strings.cpp | 16 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/vcpkgpaths.cpp | 2 |
3 files changed, 7 insertions, 15 deletions
diff --git a/toolsrc/include/vcpkg/base/strings.h b/toolsrc/include/vcpkg/base/strings.h index 5b03286de..ee1b2fc28 100644 --- a/toolsrc/include/vcpkg/base/strings.h +++ b/toolsrc/include/vcpkg/base/strings.h @@ -78,9 +78,7 @@ namespace vcpkg::Strings 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); + std::string trim(std::string&& s); void trim_all_and_remove_whitespace_strings(std::vector<std::string>* strings); diff --git a/toolsrc/src/vcpkg/base/strings.cpp b/toolsrc/src/vcpkg/base/strings.cpp index 36efc3adc..27cfcbe71 100644 --- a/toolsrc/src/vcpkg/base/strings.cpp +++ b/toolsrc/src/vcpkg/base/strings.cpp @@ -125,24 +125,18 @@ namespace vcpkg::Strings return std::move(s); } - void trim(std::string* s) + std::string trim(std::string&& s) { - s->erase(std::find_if_not(s->rbegin(), s->rend(), details::isspace).base(), s->end()); - s->erase(s->begin(), std::find_if_not(s->begin(), s->end(), details::isspace)); - } - - std::string trimmed(const std::string& s) - { - auto whitespace_back = std::find_if_not(s.rbegin(), s.rend(), details::isspace).base(); - auto whitespace_front = std::find_if_not(s.begin(), whitespace_back, details::isspace); - return std::string(whitespace_front, whitespace_back); + s.erase(std::find_if_not(s.rbegin(), s.rend(), details::isspace).base(), s.end()); + s.erase(s.begin(), std::find_if_not(s.begin(), s.end(), details::isspace)); + return std::move(s); } void trim_all_and_remove_whitespace_strings(std::vector<std::string>* strings) { for (std::string& s : *strings) { - trim(&s); + s = trim(std::move(s)); } Util::erase_remove_if(*strings, [](const std::string& s) { return s.empty(); }); diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp index ef9e383bc..363319767 100644 --- a/toolsrc/src/vcpkg/vcpkgpaths.cpp +++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp @@ -91,7 +91,7 @@ namespace vcpkg Checks::exit_with_code(VCPKG_LINE_INFO, rc.exit_code); } - const fs::path actual_downloaded_path = Strings::trimmed(rc.output); + const fs::path actual_downloaded_path = Strings::trim(std::string{rc.output}); std::error_code ec; const auto eq = fs::stdfs::equivalent(expected_downloaded_path, actual_downloaded_path, ec); Checks::check_exit(VCPKG_LINE_INFO, |
