diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2016-12-16 16:02:19 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2016-12-16 16:02:19 -0800 |
| commit | a5c3fddfe7bc4f765a0efdd9b109709f2fb4ae9c (patch) | |
| tree | 043d9722d107036dd84ab7212ffd62f421fa1e25 | |
| parent | bd50778cb53d7071d65159f0aa67e685a6628e19 (diff) | |
| download | vcpkg-a5c3fddfe7bc4f765a0efdd9b109709f2fb4ae9c.tar.gz vcpkg-a5c3fddfe7bc4f765a0efdd9b109709f2fb4ae9c.zip | |
Add Strings::trim_all_and_remove_whitespace_strings()
| -rw-r--r-- | toolsrc/include/vcpkg_Strings.h | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Strings.cpp | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg_Strings.h b/toolsrc/include/vcpkg_Strings.h index 92c24298c..a117a1a81 100644 --- a/toolsrc/include/vcpkg_Strings.h +++ b/toolsrc/include/vcpkg_Strings.h @@ -73,4 +73,6 @@ namespace vcpkg {namespace Strings void trim(std::string* s); std::string trimmed(const std::string& s); + + void trim_all_and_remove_whitespace_strings(std::vector<std::string>* strings); }} diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 4859a480b..403900dae 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -9,6 +9,7 @@ namespace vcpkg {namespace Strings {namespace details { + // To disambiguate between two overloads static const auto isspace = [](const char c) { return std::isspace(c); @@ -105,4 +106,13 @@ namespace vcpkg {namespace Strings auto whitespace_back = std::find_if_not(s.rbegin(), s.rend(), details::isspace).base(); return (whitespace_back <= whitespace_front ? std::string() : std::string(whitespace_front, whitespace_back)); } + + void trim_all_and_remove_whitespace_strings(std::vector<std::string>* strings) + { + strings->erase(std::remove_if(strings->begin(), strings->end(), [](std::string& s)-> bool + { + trim(&s); + return s == ""; + }), strings->end()); + } }} |
