diff options
Diffstat (limited to 'utils.h')
-rw-r--r-- | utils.h | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -9,4 +9,18 @@ void split (std::vector<std::string> &vec, std::string str, std::string del) { } else { vec.push_back(str); } } +// trim +static inline void ltrim(std::string &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); +} +static inline void rtrim(std::string &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { + return !std::isspace(ch); + }).base(), s.end()); +} +static inline void trim(std::string &s) { ltrim(s); rtrim(s); } + + #endif |