aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
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