mirror of
https://github.com/matrix-construct/construct
synced 2024-10-02 05:38:53 +02:00
ircd::util: Add ctype() template for testing string ranges.
This commit is contained in:
parent
ccbd507c35
commit
296fd9183b
2 changed files with 23 additions and 0 deletions
|
@ -32,6 +32,7 @@ namespace ircd
|
||||||
template<class T> struct vector_view;
|
template<class T> struct vector_view;
|
||||||
template<class T = string_view> struct byte_view;
|
template<class T = string_view> struct byte_view;
|
||||||
template<> struct byte_view<string_view>;
|
template<> struct byte_view<string_view>;
|
||||||
|
template<int (&test)(int) = std::isprint> auto ctype(const string_view &s);
|
||||||
|
|
||||||
bool operator!(const string_view &);
|
bool operator!(const string_view &);
|
||||||
}
|
}
|
||||||
|
@ -241,3 +242,10 @@ ircd::operator!(const string_view &str)
|
||||||
{
|
{
|
||||||
return str.empty();
|
return str.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<int (&test)(int)>
|
||||||
|
auto
|
||||||
|
ircd::ctype(const string_view &s)
|
||||||
|
{
|
||||||
|
return ctype<test>(std::begin(s), std::end(s));
|
||||||
|
}
|
||||||
|
|
|
@ -1037,5 +1037,20 @@ until(it_a a,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Convenience loop to test std::is* on a character sequence
|
||||||
|
template<int (&test)(int) = std::isprint>
|
||||||
|
ssize_t
|
||||||
|
ctype(const char *begin,
|
||||||
|
const char *const &end)
|
||||||
|
{
|
||||||
|
size_t i(0);
|
||||||
|
for(; begin != end; ++begin, ++i)
|
||||||
|
if(!test(static_cast<unsigned char>(*begin)))
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
} // namespace ircd
|
} // namespace ircd
|
||||||
|
|
Loading…
Reference in a new issue