diff --git a/include/ircd/stringops.h b/include/ircd/stringops.h index 6a9cc8cf8..3f92aed1c 100644 --- a/include/ircd/stringops.h +++ b/include/ircd/stringops.h @@ -31,11 +31,13 @@ namespace ircd string_view lstrip(const string_view &str, const char &c = ' '); string_view lstrip(string_view str, const string_view &c); string_view lstrip(string_view str, const string_view &c, size_t n); + string_view lstrip(string_view str, const char &c, size_t n); // return view without trailing occurrences of c string_view rstrip(const string_view &str, const char &c = ' '); string_view rstrip(string_view str, const string_view &c); string_view rstrip(string_view str, const string_view &c, size_t n); + string_view rstrip(string_view str, const char &c, size_t n); // return view without leading and trailing occurrences of c string_view strip(const string_view &str, const char &c = ' '); @@ -478,6 +480,18 @@ ircd::rstrip(string_view str, return str; } +/// Remove trailing instances of c from the returned view +inline ircd::string_view +ircd::rstrip(string_view str, + const char &c, + size_t n) +{ + while(endswith(str, c) && n--) + str.pop_back(); + + return str; +} + /// Remove trailing instances of c from the returned view inline ircd::string_view ircd::rstrip(const string_view &str, @@ -512,6 +526,18 @@ ircd::lstrip(string_view str, return str; } +/// Remove n leading instances of c from the returned view +inline ircd::string_view +ircd::lstrip(string_view str, + const char &c, + size_t n) +{ + while(startswith(str, c) && n--) + str.pop_front(); + + return str; +} + /// Remove leading instances of c from the returned view. inline ircd::string_view ircd::lstrip(const string_view &str,