diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-06 18:33:02 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-06 18:33:11 +0100 |
commit | 72a3388c042f4812e2db33f6d6a1b757392a18a6 (patch) | |
tree | c3d56aad98eefd7114809c969e1e3613f4604d12 /utils.h | |
parent | 25d2986b09bd348d58da878f0da8151b3363b534 (diff) |
day08
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 |