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

ircd: Add non-throwing/defaulting token() overload.

This commit is contained in:
Jason Volk 2018-03-03 23:29:38 -08:00
parent 92bef88b6c
commit 505b3b5115
2 changed files with 26 additions and 0 deletions

View file

@ -75,6 +75,8 @@ namespace ircd
size_t token_count(const string_view &str, const char *const &sep);
string_view token(const string_view &str, const char &sep, const size_t &at);
string_view token(const string_view &str, const char *const &sep, const size_t &at);
string_view token(const string_view &str, const char &sep, const size_t &at, const string_view &def);
string_view token(const string_view &str, const char *const &sep, const size_t &at, const string_view &def);
string_view token_last(const string_view &str, const char &sep);
string_view token_last(const string_view &str, const char *const &sep);
string_view token_first(const string_view &str, const char &sep);

View file

@ -98,6 +98,30 @@ ircd::token_last(const string_view &str,
return ret;
}
ircd::string_view
ircd::token(const string_view &str,
const char &sep,
const size_t &i,
const string_view &def)
{
const char ssep[2] { sep, '\0' };
return token(str, ssep, i, def);
}
ircd::string_view
ircd::token(const string_view &str,
const char *const &sep,
const size_t &i,
const string_view &def)
try
{
return token(str, sep, i);
}
catch(const std::out_of_range &)
{
return def;
}
ircd::string_view
ircd::token(const string_view &str,
const char &sep,