From 238a473b0823f2f46bb012369c2133486764b1dc Mon Sep 17 00:00:00 2001 From: Jason Volk <jason@zemos.net> Date: Thu, 23 Jul 2020 12:54:52 -0700 Subject: [PATCH] ircd: Add strip(n) proxy overloads to interface. --- include/ircd/stringops.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/ircd/stringops.h b/include/ircd/stringops.h index f96a9c1e9..d24e38ea4 100644 --- a/include/ircd/stringops.h +++ b/include/ircd/stringops.h @@ -46,6 +46,8 @@ namespace ircd // return view without leading and trailing occurrences of c string_view strip(const string_view &str, const char &c = ' '); string_view strip(const string_view &str, const string_view &c); + string_view strip(const string_view &str, const string_view &c, const size_t n); + string_view strip(const string_view &str, const char &c, const size_t n); // split view on first match of delim; delim not included; if no delim then .second empty std::pair<string_view, string_view> split(const string_view &str, const char &delim = ' '); @@ -437,6 +439,24 @@ ircd::split(const string_view &str, pair { str, string_view{} }; } +/// Remove n leading and trailing instances of c from the returned view +inline ircd::string_view +ircd::strip(const string_view &str, + const string_view &c, + const size_t n) +{ + return lstrip(rstrip(str, c, n), c, n); +} + +/// Remove n leading and trailing instances of c from the returned view +inline ircd::string_view +ircd::strip(const string_view &str, + const char &c, + const size_t n) +{ + return lstrip(rstrip(str, c, n), c, n); +} + /// Remove leading and trailing instances of c from the returned view inline ircd::string_view ircd::strip(const string_view &str,