0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd: Add overloads for counted character leading/trailing strip.

This commit is contained in:
Jason Volk 2020-01-23 20:55:13 -08:00
parent f12a4bfdd1
commit 0231e26c76

View file

@ -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,