summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-09-06 18:58:35 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-17 15:36:04 +0000
commitd2d79601ff3701b82a9647ac4019d71b063a7804 (patch)
treeb71e219b876b36b4b972aed76e8ee518915d7e84
parentAdd a test case for invalid accept where q is f (diff)
downloadicespider-d2d79601ff3701b82a9647ac4019d71b063a7804.tar.bz2
icespider-d2d79601ff3701b82a9647ac4019d71b063a7804.tar.xz
icespider-d2d79601ff3701b82a9647ac4019d71b063a7804.zip
Utils for trimming string_view
-rw-r--r--icespider/core/util.cpp19
-rw-r--r--icespider/core/util.h5
2 files changed, 24 insertions, 0 deletions
diff --git a/icespider/core/util.cpp b/icespider/core/util.cpp
new file mode 100644
index 0000000..62de195
--- /dev/null
+++ b/icespider/core/util.cpp
@@ -0,0 +1,19 @@
+#include "util.h"
+
+namespace IceSpider {
+ void
+ remove_trailing(std::string_view & in, const char c)
+ {
+ if (const auto n = in.find_last_not_of(c); n != std::string_view::npos) {
+ in.remove_suffix(in.length() - n - 1);
+ }
+ }
+
+ void
+ remove_leading(std::string_view & in, const char c)
+ {
+ if (const auto n = in.find_first_not_of(c); n != std::string_view::npos) {
+ in.remove_prefix(n);
+ }
+ }
+}
diff --git a/icespider/core/util.h b/icespider/core/util.h
index fcaf93c..9a673e4 100644
--- a/icespider/core/util.h
+++ b/icespider/core/util.h
@@ -121,4 +121,9 @@ private:
}()};
};
+namespace IceSpider {
+ void remove_trailing(std::string_view & in, const char c);
+ void remove_leading(std::string_view & in, const char c);
+}
+
#endif