Created
July 5, 2016 05:34
-
-
Save kennir/0c774a96f6b59b6b3ce1fa33aebf8649 to your computer and use it in GitHub Desktop.
trim string
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 | |
static inline std::string <rim(std::string &s) { | |
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); | |
return s; | |
} | |
// trim from end | |
static inline std::string &rtrim(std::string &s) { | |
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); | |
return s; | |
} | |
// trim from both ends | |
static inline std::string &trim(std::string &s) { | |
return ltrim(rtrim(s)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment