Created
April 3, 2019 11:54
-
-
Save andijcr/6429363f7946eaedfb6f7b9f1b4c091a to your computer and use it in GitHub Desktop.
simple in-place trim functions, copied from somewhere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// trim from start (in place) | |
void ltrim(std::string &s) { | |
s.erase(s.begin(), std::find_if(s.begin(), s.end(), | |
[](int ch) { return !std::isspace(ch); })); | |
} | |
// trim from end (in place) | |
void rtrim(std::string &s) { | |
s.erase(std::find_if(s.rbegin(), s.rend(), | |
[](int ch) { return !std::isspace(ch); }) | |
.base(), | |
s.end()); | |
} | |
// trim from both ends (in place) | |
void trim(std::string &s) { | |
ltrim(s); | |
rtrim(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment