2018-04-25 01:40:55 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#include <boost/tokenizer.hpp>
|
|
|
|
|
2020-05-12 01:09:11 +02:00
|
|
|
namespace ircd
|
|
|
|
{
|
|
|
|
struct string_separator;
|
2022-05-02 00:40:48 +02:00
|
|
|
struct char_separator;
|
2020-05-12 01:09:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct [[gnu::visibility("internal")]]
|
|
|
|
ircd::string_separator
|
|
|
|
{
|
2022-05-02 01:09:49 +02:00
|
|
|
const string_view &delim;
|
2020-05-12 01:09:11 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2022-05-02 00:40:48 +02:00
|
|
|
struct [[gnu::visibility("internal")]]
|
|
|
|
ircd::char_separator
|
|
|
|
{
|
2022-05-02 01:09:49 +02:00
|
|
|
const char &delim;
|
2022-05-02 00:40:48 +02:00
|
|
|
|
|
|
|
template<class iterator,
|
|
|
|
class token>
|
|
|
|
bool operator()(iterator &next, iterator end, token &ret) const noexcept;
|
|
|
|
void reset() noexcept;
|
|
|
|
|
|
|
|
char_separator(const char &delim) noexcept;
|
|
|
|
~char_separator() noexcept;
|
|
|
|
};
|
|
|
|
|
2020-05-12 01:09:11 +02:00
|
|
|
//
|
|
|
|
// interface
|
|
|
|
//
|
|
|
|
|
2022-07-18 21:28:47 +02:00
|
|
|
ircd::pair<ircd::string_view>
|
|
|
|
ircd::tokens_split(const string_view &str,
|
|
|
|
const char sep,
|
|
|
|
const size_t at,
|
|
|
|
const size_t skip)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const ssize_t before(at);
|
|
|
|
const ssize_t after
|
|
|
|
{
|
|
|
|
(before - 1) + ssize_t(skip)
|
|
|
|
};
|
|
|
|
|
|
|
|
return pair<string_view>
|
|
|
|
{
|
|
|
|
tokens_before(str, sep, before),
|
|
|
|
tokens_after(str, sep, after)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::pair<ircd::string_view>
|
|
|
|
ircd::tokens_split(const string_view &str,
|
|
|
|
const string_view &sep,
|
|
|
|
const size_t at,
|
|
|
|
const size_t skip)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const ssize_t before(at);
|
|
|
|
const ssize_t after
|
|
|
|
{
|
|
|
|
(before - 1) + ssize_t(skip)
|
|
|
|
};
|
|
|
|
|
|
|
|
return pair<string_view>
|
|
|
|
{
|
|
|
|
tokens_before(str, sep, before),
|
|
|
|
tokens_after(str, sep, after)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-25 01:40:55 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::tokens_before(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep,
|
|
|
|
const size_t i)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2020-02-27 02:49:30 +01:00
|
|
|
assert(sep != '\0');
|
2020-05-12 01:23:04 +02:00
|
|
|
const char _sep[2]
|
|
|
|
{
|
|
|
|
sep, '\0'
|
|
|
|
};
|
|
|
|
|
|
|
|
return tokens_before(str, _sep, i);
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::tokens_before(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep,
|
2022-05-02 01:09:49 +02:00
|
|
|
const size_t i)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2020-05-12 01:23:04 +02:00
|
|
|
using delim = string_separator;
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
const delim d{sep};
|
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
string_view ret;
|
|
|
|
auto it(begin(view));
|
|
|
|
for(size_t j(0); it != end(view) && j < i; ++it, j++)
|
2020-05-12 01:23:04 +02:00
|
|
|
ret =
|
|
|
|
{
|
|
|
|
begin(view)->data(), it->data() + it->size()
|
|
|
|
};
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::tokens_after(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep,
|
|
|
|
const ssize_t i)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2020-02-27 02:49:30 +01:00
|
|
|
assert(sep != '\0');
|
2020-05-12 01:23:04 +02:00
|
|
|
const char _sep[2]
|
|
|
|
{
|
|
|
|
sep, '\0'
|
|
|
|
};
|
|
|
|
|
|
|
|
return tokens_after(str, _sep, i);
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::tokens_after(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep,
|
2022-05-02 01:09:49 +02:00
|
|
|
const ssize_t i)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2020-05-12 01:23:04 +02:00
|
|
|
using delim = string_separator;
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
const delim d{sep};
|
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
auto it(begin(view));
|
2022-01-23 20:07:06 +01:00
|
|
|
for(ssize_t j(0); it != end(view); ++it, j++)
|
2018-04-25 01:40:55 +02:00
|
|
|
if(j > i)
|
2020-05-12 01:23:04 +02:00
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
it->data(), str.data() + str.size()
|
|
|
|
};
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::token_first(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep)
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2020-02-27 02:49:30 +01:00
|
|
|
assert(sep != '\0');
|
2020-05-12 01:23:04 +02:00
|
|
|
const char _sep[2]
|
|
|
|
{
|
|
|
|
sep, '\0'
|
|
|
|
};
|
|
|
|
|
|
|
|
return token(str, _sep, 0);
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::token_first(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep)
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
return token(str, sep, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::token_last(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep)
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2020-02-27 02:49:30 +01:00
|
|
|
assert(sep != '\0');
|
2020-05-12 01:23:04 +02:00
|
|
|
const char _sep[2]
|
|
|
|
{
|
|
|
|
sep, '\0'
|
|
|
|
};
|
|
|
|
|
|
|
|
return token_last(str, _sep);
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::token_last(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep)
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2020-05-12 01:23:04 +02:00
|
|
|
using delim = string_separator;
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
const delim d{sep};
|
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
auto it(begin(view));
|
|
|
|
if(it == end(view))
|
|
|
|
return str.empty()? str : throw std::out_of_range("token out of range");
|
|
|
|
|
|
|
|
string_view ret(*it);
|
|
|
|
for(++it; it != end(view); ++it)
|
|
|
|
ret = *it;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::token(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep,
|
|
|
|
const size_t i,
|
2018-04-25 01:40:55 +02:00
|
|
|
const string_view &def)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept try
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2020-05-12 01:23:04 +02:00
|
|
|
return token(str, sep, i);
|
|
|
|
}
|
|
|
|
catch(const std::out_of_range &)
|
|
|
|
{
|
|
|
|
return def;
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::token(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep,
|
2022-05-02 01:09:49 +02:00
|
|
|
const size_t i,
|
2018-04-25 01:40:55 +02:00
|
|
|
const string_view &def)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept try
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
return token(str, sep, i);
|
|
|
|
}
|
|
|
|
catch(const std::out_of_range &)
|
|
|
|
{
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::token(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep,
|
|
|
|
const size_t i)
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2020-05-12 01:23:04 +02:00
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2022-05-02 00:40:48 +02:00
|
|
|
using delim = char_separator;
|
2020-05-12 01:23:04 +02:00
|
|
|
|
2022-05-02 00:40:48 +02:00
|
|
|
const delim d{sep};
|
2020-05-12 01:23:04 +02:00
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
return *at(begin(view), end(view), i);
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::token(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep,
|
2022-05-02 01:09:49 +02:00
|
|
|
const size_t i)
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2020-05-12 01:23:04 +02:00
|
|
|
using delim = string_separator;
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
const delim d{sep};
|
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
return *at(begin(view), end(view), i);
|
|
|
|
}
|
|
|
|
|
2019-03-10 02:03:52 +01:00
|
|
|
bool
|
|
|
|
ircd::token_exists(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep,
|
2019-03-10 02:03:52 +01:00
|
|
|
const string_view &tok)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2019-03-10 02:03:52 +01:00
|
|
|
{
|
2020-05-12 01:23:04 +02:00
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2022-05-02 00:40:48 +02:00
|
|
|
using delim = char_separator;
|
2020-05-12 01:23:04 +02:00
|
|
|
|
2022-05-02 00:40:48 +02:00
|
|
|
const delim d{sep};
|
2020-05-12 01:23:04 +02:00
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::find(begin(view), end(view), tok) != end(view);
|
2019-03-10 02:03:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::token_exists(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep,
|
2019-03-10 02:03:52 +01:00
|
|
|
const string_view &tok)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2019-03-10 02:03:52 +01:00
|
|
|
{
|
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2020-05-12 01:23:04 +02:00
|
|
|
using delim = string_separator;
|
2019-03-10 02:03:52 +01:00
|
|
|
|
|
|
|
const delim d{sep};
|
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::find(begin(view), end(view), tok) != end(view);
|
|
|
|
}
|
|
|
|
|
2018-04-25 01:40:55 +02:00
|
|
|
size_t
|
|
|
|
ircd::token_count(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2020-05-12 01:23:04 +02:00
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2022-05-02 00:40:48 +02:00
|
|
|
using delim = char_separator;
|
2020-05-12 01:23:04 +02:00
|
|
|
|
2022-05-02 00:40:48 +02:00
|
|
|
const delim d{sep};
|
2020-05-12 01:23:04 +02:00
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::distance(begin(view), end(view));
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::token_count(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2020-05-12 01:23:04 +02:00
|
|
|
using delim = string_separator;
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
const delim d{sep};
|
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::distance(begin(view), end(view));
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::tokens(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep_,
|
2018-04-25 01:40:55 +02:00
|
|
|
const mutable_buffer &buf,
|
|
|
|
const token_view &closure)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2022-05-02 00:40:48 +02:00
|
|
|
assert(sep_ != '\0');
|
2020-05-12 01:23:04 +02:00
|
|
|
const char _sep[2]
|
|
|
|
{
|
2022-05-02 00:40:48 +02:00
|
|
|
sep_, '\0'
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view sep
|
|
|
|
{
|
|
|
|
_sep
|
2020-05-12 01:23:04 +02:00
|
|
|
};
|
|
|
|
|
2022-05-02 00:40:48 +02:00
|
|
|
return tokens(str, sep, buf, closure);
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::tokens(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep,
|
2018-04-25 01:40:55 +02:00
|
|
|
const mutable_buffer &buf,
|
|
|
|
const token_view &closure)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
char *ptr(data(buf));
|
|
|
|
char *const stop(data(buf) + size(buf));
|
|
|
|
tokens(str, sep, [&closure, &ptr, &stop]
|
2020-11-28 01:56:56 +01:00
|
|
|
(const string_view &token) -> bool
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
const size_t terminated_size(token.size() + 1);
|
|
|
|
const size_t remaining(std::distance(ptr, stop));
|
|
|
|
if(remaining < terminated_size)
|
2020-11-28 01:56:56 +01:00
|
|
|
return false;
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
char *const dest(ptr);
|
|
|
|
ptr += strlcpy(dest, token.data(), terminated_size);
|
2020-11-28 01:56:56 +01:00
|
|
|
return closure(string_view(dest, token.size()));
|
2018-04-25 01:40:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return std::distance(data(buf), ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::tokens(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep,
|
|
|
|
const size_t limit,
|
2018-04-25 01:40:55 +02:00
|
|
|
const token_view &closure)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
2020-05-12 01:23:04 +02:00
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2022-05-02 00:40:48 +02:00
|
|
|
using delim = char_separator;
|
2020-05-12 01:23:04 +02:00
|
|
|
|
2022-05-02 00:40:48 +02:00
|
|
|
const delim d{sep};
|
2020-05-12 01:23:04 +02:00
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t i(0);
|
|
|
|
for(auto it(begin(view)); i < limit && it != end(view); ++it, i++)
|
2020-11-28 01:56:56 +01:00
|
|
|
if(!closure(*it))
|
|
|
|
break;
|
2020-05-12 01:23:04 +02:00
|
|
|
|
|
|
|
return i;
|
2018-04-25 01:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::tokens(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep,
|
2022-05-02 01:09:49 +02:00
|
|
|
const size_t limit,
|
2018-04-25 01:40:55 +02:00
|
|
|
const token_view &closure)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2018-04-25 01:40:55 +02:00
|
|
|
{
|
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2020-05-12 01:23:04 +02:00
|
|
|
using delim = string_separator;
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
const delim d{sep};
|
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t i(0);
|
|
|
|
for(auto it(begin(view)); i < limit && it != end(view); ++it, i++)
|
2020-11-28 01:56:56 +01:00
|
|
|
if(!closure(*it))
|
|
|
|
break;
|
2018-04-25 01:40:55 +02:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-03-10 02:03:13 +01:00
|
|
|
bool
|
|
|
|
ircd::tokens(const string_view &str,
|
2022-05-02 01:09:49 +02:00
|
|
|
const char sep,
|
2020-11-28 01:56:56 +01:00
|
|
|
const token_view &closure)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2019-03-10 02:03:13 +01:00
|
|
|
{
|
2020-05-12 01:23:04 +02:00
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2022-05-02 00:40:48 +02:00
|
|
|
using delim = char_separator;
|
2020-05-12 01:23:04 +02:00
|
|
|
|
2022-05-02 00:40:48 +02:00
|
|
|
const delim d{sep};
|
2020-05-12 01:23:04 +02:00
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
for(auto it(begin(view)); it != end(view); ++it)
|
|
|
|
if(!closure(*it))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2019-03-10 02:03:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::tokens(const string_view &str,
|
2020-05-12 01:25:51 +02:00
|
|
|
const string_view &sep,
|
2020-11-28 01:56:56 +01:00
|
|
|
const token_view &closure)
|
2022-06-24 04:18:05 +02:00
|
|
|
noexcept
|
2019-03-10 02:03:13 +01:00
|
|
|
{
|
|
|
|
using type = string_view;
|
|
|
|
using iter = typename type::const_iterator;
|
2020-05-12 01:23:04 +02:00
|
|
|
using delim = string_separator;
|
2019-03-10 02:03:13 +01:00
|
|
|
|
|
|
|
const delim d{sep};
|
|
|
|
const boost::tokenizer<delim, iter, type> view
|
|
|
|
{
|
|
|
|
str, d
|
|
|
|
};
|
|
|
|
|
|
|
|
for(auto it(begin(view)); it != end(view); ++it)
|
|
|
|
if(!closure(*it))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-12 01:09:11 +02:00
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
2022-05-02 00:40:48 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// char_separator
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::char_separator::char_separator(const char &delim)
|
|
|
|
noexcept
|
|
|
|
:delim
|
|
|
|
{
|
|
|
|
delim
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::char_separator::~char_separator()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::char_separator::reset()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
//TODO: ???
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class iterator,
|
|
|
|
class token>
|
|
|
|
bool
|
|
|
|
ircd::char_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;
|
|
|
|
}
|