0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-29 12:18:54 +02:00

ircd: Move ctype<> into util::; add valid(string_view) boolean convenience.

This commit is contained in:
Jason Volk 2018-02-14 14:03:04 -08:00
parent a66f0f9423
commit 025909e1eb
2 changed files with 19 additions and 12 deletions

View file

@ -15,8 +15,6 @@ namespace ircd
{
struct string_view;
template<int (&test)(int) = std::isprint> auto ctype(const string_view &s);
const char *data(const string_view &);
size_t size(const string_view &);
bool empty(const string_view &);
@ -257,13 +255,3 @@ ircd::data(const string_view &str)
{
return str.data();
}
/// ctype test for a string_view. Returns the character position where the
/// test fails. Returns -1 on success. The test is a function specified in
/// the template simply as `ctype<std::isprint>(string_view{"hi"});`
template<int (&test)(int)>
auto
ircd::ctype(const string_view &s)
{
return ctype<test>(std::begin(s), std::end(s));
}

View file

@ -217,6 +217,25 @@ ctype(const char *begin,
return -1;
}
/// ctype test for a string_view. Returns the character position where the
/// test fails. Returns -1 on success. The test is a function specified in
/// the template simply as `ctype<std::isprint>(string_view{"hi"});`
template<int (&test)(int)>
ssize_t
ctype(const string_view &s)
{
return ctype<test>(begin(s), end(s));
}
/// convenience wrapper for ctype(string_view) to avoid the -1 test for
/// success in any intuitive boolean statement.
template<int (&test)(int)>
bool
valid(const string_view &s)
{
return ctype<test>(s) == -1L;
}
/// Zero testing functor (work in progress)
///
struct is_zero