diff --git a/include/ircd/string_view.h b/include/ircd/string_view.h index 5e948f102..929dae691 100644 --- a/include/ircd/string_view.h +++ b/include/ircd/string_view.h @@ -32,6 +32,7 @@ namespace ircd template struct vector_view; template struct byte_view; template<> struct byte_view; + template auto ctype(const string_view &s); bool operator!(const string_view &); } @@ -241,3 +242,10 @@ ircd::operator!(const string_view &str) { return str.empty(); } + +template +auto +ircd::ctype(const string_view &s) +{ + return ctype(std::begin(s), std::end(s)); +} diff --git a/include/ircd/util.h b/include/ircd/util.h index feaded6c2..90d72fa59 100644 --- a/include/ircd/util.h +++ b/include/ircd/util.h @@ -1037,5 +1037,20 @@ until(it_a a, } +/// Convenience loop to test std::is* on a character sequence +template +ssize_t +ctype(const char *begin, + const char *const &end) +{ + size_t i(0); + for(; begin != end; ++begin, ++i) + if(!test(static_cast(*begin))) + return i; + + return -1; +} + + } // namespace util } // namespace ircd