mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 16:34:13 +01:00
fixup! ircd: Add tokens_after() util.
This commit is contained in:
parent
91cd0327bd
commit
98c51be27d
1 changed files with 20 additions and 14 deletions
|
@ -23,20 +23,6 @@
|
||||||
#include <RB_INC_BOOST_TOKENIZER_HPP
|
#include <RB_INC_BOOST_TOKENIZER_HPP
|
||||||
#include <RB_INC_BOOST_LEXICAL_CAST_HPP
|
#include <RB_INC_BOOST_LEXICAL_CAST_HPP
|
||||||
|
|
||||||
ircd::string_view
|
|
||||||
ircd::tokens_after(const string_view &str,
|
|
||||||
const char *const &sep,
|
|
||||||
const size_t &i)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
const auto t(token(str, sep, i + 1));
|
|
||||||
return { t.data(), str.data() + str.size() };
|
|
||||||
}
|
|
||||||
catch(const std::out_of_range &e)
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::string_view
|
ircd::string_view
|
||||||
ircd::token_first(const string_view &str,
|
ircd::token_first(const string_view &str,
|
||||||
const char *const &sep)
|
const char *const &sep)
|
||||||
|
@ -44,6 +30,26 @@ ircd::token_first(const string_view &str,
|
||||||
return token(str, sep, 0);
|
return token(str, sep, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ircd::string_view
|
||||||
|
ircd::tokens_after(const string_view &str,
|
||||||
|
const char *const &sep,
|
||||||
|
const size_t &i)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
auto it(begin(view));
|
||||||
|
for(size_t j(0); it != end(view); ++it, j++)
|
||||||
|
if(j > i)
|
||||||
|
return string_view{it->data(), str.data() + str.size()};
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
ircd::string_view
|
ircd::string_view
|
||||||
ircd::token_last(const string_view &str,
|
ircd::token_last(const string_view &str,
|
||||||
const char *const &sep)
|
const char *const &sep)
|
||||||
|
|
Loading…
Reference in a new issue