summaryrefslogtreecommitdiff
path: root/src/str.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/str.cc')
-rw-r--r--src/str.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/str.cc b/src/str.cc
index e5b70ed..129e0f3 100644
--- a/src/str.cc
+++ b/src/str.cc
@@ -76,4 +76,19 @@ std::string_view trim(std::string_view str) {
return str.substr(s, e - s);
}
+std::string_view ltrim(std::string_view str) {
+ size_t s = 0;
+ size_t const e = str.size();
+ while (s < e && is_space(str[s]))
+ ++s;
+ return str.substr(s, e - s);
+}
+
+std::string_view rtrim(std::string_view str) {
+ size_t e = str.size();
+ while (e > 0 && is_space(str[e - 1]))
+ --e;
+ return str.substr(0, e);
+}
+
} // namespace str