0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-01 18:34:18 +01:00

ircd::tokens: Add token_exists() set membership test.

This commit is contained in:
Jason Volk 2019-03-09 17:03:52 -08:00
parent 312e4958f7
commit d763a15edb
2 changed files with 29 additions and 0 deletions

View file

@ -76,6 +76,8 @@ namespace ircd
// Convenience to get individual tokens
size_t token_count(const string_view &str, const char &sep);
size_t token_count(const string_view &str, const char *const &sep);
bool token_exists(const string_view &str, const char &sep, const string_view &token);
bool token_exists(const string_view &str, const char *const &, const string_view &token);
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);

View file

@ -173,6 +173,33 @@ ircd::token(const string_view &str,
return *at(begin(view), end(view), i);
}
bool
ircd::token_exists(const string_view &str,
const char &sep,
const string_view &tok)
{
const char ssep[2] { sep, '\0' };
return token_exists(str, ssep, tok);
}
bool
ircd::token_exists(const string_view &str,
const char *const &sep,
const string_view &tok)
{
using type = string_view;
using iter = typename type::const_iterator;
using delim = boost::char_separator<char>;
const delim d{sep};
const boost::tokenizer<delim, iter, type> view
{
str, d
};
return std::find(begin(view), end(view), tok) != end(view);
}
size_t
ircd::token_count(const string_view &str,
const char &sep)