mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 07:20:55 +01:00
ircd: Move ctype<> into util::; add valid(string_view) boolean convenience.
This commit is contained in:
parent
a66f0f9423
commit
025909e1eb
2 changed files with 19 additions and 12 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue