mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd: Add overloads for counted character leading/trailing strip.
This commit is contained in:
parent
f12a4bfdd1
commit
0231e26c76
1 changed files with 26 additions and 0 deletions
|
@ -31,11 +31,13 @@ namespace ircd
|
||||||
string_view lstrip(const string_view &str, const char &c = ' ');
|
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);
|
||||||
string_view lstrip(string_view str, const string_view &c, size_t n);
|
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
|
// return view without trailing occurrences of c
|
||||||
string_view rstrip(const string_view &str, const char &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);
|
||||||
string_view rstrip(string_view str, const string_view &c, size_t n);
|
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
|
// 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 char &c = ' ');
|
||||||
|
@ -478,6 +480,18 @@ ircd::rstrip(string_view str,
|
||||||
return 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
|
/// Remove trailing instances of c from the returned view
|
||||||
inline ircd::string_view
|
inline ircd::string_view
|
||||||
ircd::rstrip(const string_view &str,
|
ircd::rstrip(const string_view &str,
|
||||||
|
@ -512,6 +526,18 @@ ircd::lstrip(string_view str,
|
||||||
return 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.
|
/// Remove leading instances of c from the returned view.
|
||||||
inline ircd::string_view
|
inline ircd::string_view
|
||||||
ircd::lstrip(const string_view &str,
|
ircd::lstrip(const string_view &str,
|
||||||
|
|
Loading…
Reference in a new issue