aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorjacopograndi <jacopo.grandi@outlook.it>2022-01-06 18:33:02 +0100
committerjacopograndi <jacopo.grandi@outlook.it>2022-01-06 18:33:11 +0100
commit72a3388c042f4812e2db33f6d6a1b757392a18a6 (patch)
treec3d56aad98eefd7114809c969e1e3613f4604d12 /utils.h
parent25d2986b09bd348d58da878f0da8151b3363b534 (diff)
day08
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/utils.h b/utils.h
index f713da8..b96f570 100644
--- a/utils.h
+++ b/utils.h
@@ -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