Skip to content

Instantly share code, notes, and snippets.

@RklAlx
Created October 16, 2013 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RklAlx/7004935 to your computer and use it in GitHub Desktop.
Save RklAlx/7004935 to your computer and use it in GitHub Desktop.
std::string trim
static inline std::string &ltrim(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;
}
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;
}
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