From d2d79601ff3701b82a9647ac4019d71b063a7804 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 6 Sep 2021 18:58:35 +0100 Subject: Utils for trimming string_view --- icespider/core/util.cpp | 19 +++++++++++++++++++ icespider/core/util.h | 5 +++++ 2 files changed, 24 insertions(+) create mode 100644 icespider/core/util.cpp 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 -- cgit v1.2.3