diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-06 18:42:22 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-06 18:42:22 +0100 |
commit | 9f7b0cd76272068588d0a7220408f91390c5b583 (patch) | |
tree | 49a517f0303c951023554ba6b3fb8cc3d5eb1234 /2021/utils.h | |
parent | 72a3388c042f4812e2db33f6d6a1b757392a18a6 (diff) |
moved
Diffstat (limited to '2021/utils.h')
-rw-r--r-- | 2021/utils.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/2021/utils.h b/2021/utils.h new file mode 100644 index 0000000..b96f570 --- /dev/null +++ b/2021/utils.h @@ -0,0 +1,26 @@ +#ifndef UTILS_H +#define UTILS_H + +void split (std::vector<std::string> &vec, std::string str, std::string del) { + auto token = str.find(del); + if (token != std::string::npos) { + vec.push_back(str.substr(0, token)); + split(vec, str.substr(token+del.size()), 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 |