mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
ircd::tokens: Add a string separator functor.
This commit is contained in:
parent
613464c476
commit
890dc6f003
1 changed files with 76 additions and 0 deletions
|
@ -10,6 +10,29 @@
|
|||
|
||||
#include <boost/tokenizer.hpp>
|
||||
|
||||
namespace ircd
|
||||
{
|
||||
struct string_separator;
|
||||
};
|
||||
|
||||
struct [[gnu::visibility("internal")]]
|
||||
ircd::string_separator
|
||||
{
|
||||
string_view delim;
|
||||
|
||||
template<class iterator,
|
||||
class token>
|
||||
bool operator()(iterator &next, iterator end, token &ret) const noexcept;
|
||||
void reset() noexcept;
|
||||
|
||||
string_separator(const string_view &delim) noexcept;
|
||||
~string_separator() noexcept;
|
||||
};
|
||||
|
||||
//
|
||||
// interface
|
||||
//
|
||||
|
||||
ircd::string_view
|
||||
ircd::tokens_before(const string_view &str,
|
||||
const char &sep,
|
||||
|
@ -360,3 +383,56 @@ ircd::tokens(const string_view &str,
|
|||
|
||||
std::for_each(begin(view), end(view), closure);
|
||||
}
|
||||
|
||||
//
|
||||
// string_separator
|
||||
//
|
||||
|
||||
ircd::string_separator::string_separator(const string_view &delim)
|
||||
noexcept
|
||||
:delim
|
||||
{
|
||||
delim
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::string_separator::~string_separator()
|
||||
noexcept
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ircd::string_separator::reset()
|
||||
noexcept
|
||||
{
|
||||
//TODO: ???
|
||||
}
|
||||
|
||||
template<class iterator,
|
||||
class token>
|
||||
bool
|
||||
ircd::string_separator::operator()(iterator &start,
|
||||
iterator stop,
|
||||
token &ret)
|
||||
const noexcept
|
||||
{
|
||||
do
|
||||
{
|
||||
if(start == stop)
|
||||
return false;
|
||||
|
||||
const string_view input
|
||||
{
|
||||
start, stop
|
||||
};
|
||||
|
||||
string_view remain;
|
||||
std::tie(ret, remain) = ircd::split(input, delim);
|
||||
start = remain?
|
||||
begin(remain):
|
||||
stop;
|
||||
}
|
||||
while(!ret);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue