diff --git a/include/crap/locale b/include/crap/locale index 096b89f..9c356de 100644 --- a/include/crap/locale +++ b/include/crap/locale @@ -1,6 +1,8 @@ #ifndef CRAP_LOCALE #define CRAP_LOCALE +#include "locale.d/ctype.h" +#include "locale.d/ctypebase.h" #include "locale.d/hasfacet.h" #include "locale.d/isalnumvalue.h" #include "locale.d/isalphavalue.h" diff --git a/include/crap/locale.d/ctype.h b/include/crap/locale.d/ctype.h new file mode 100644 index 0000000..b1534d5 --- /dev/null +++ b/include/crap/locale.d/ctype.h @@ -0,0 +1,84 @@ +#ifndef CRAP_LOCALE_CTYPE +#define CRAP_LOCALE_CTYPE + +#include +#include + +#include "ctypebase.h" +#include "../algorithm.d/findvalue.h" +#include "../functional.d/comparatorsfortype.h" +#include "../string.d/string.h" +#include "../version.d/libintegralconstantcallable.h" + +namespace crap +{ + template struct ctype; + + template <> struct ctype + { //Defaults for C standard. + using char_type = char; + template using string_type = string; + template struct is; + template + struct is, ctypeBase :: digit> >; + template + struct is, std :: integral_constant >; + }; + + template <> struct ctype + { //Requires execution encoding. + }; + + template struct :: ; + struct ctype :: + is, ctypeBase :: digit> > + { //Assume ASCII, UTF-8 single octet or pure basic character set. + private: + //If certain of ASCII, ASCII superset or any encoding where digits are ordered, use binary search. + using result = findValue :: template + EqualTo, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'>; + public: + constexpr const static bool value = (result :: value != result :: npos); + using value_type = decltype(value); + constexpr operator value_type () const noexcept; +#if (crap_lib_integral_constant_callable >= 201304L) + constexpr value_type operator () () const noexcept; +#endif + }; + + template struct :: ; + struct ctype :: + is > > + : ctype :: + is, ctypeBase :: digit> > + { + }; +} + +template +inline constexpr crap :: ctype :: + is , ctypeBase :: digit> > :: +operator typename crap :: ctype :: + is , ctypeBase :: digit> > :: +value_type () const noexcept +{ + return crap :: ctype :: + is , ctypeBase :: digit> > :: + value; +} +#if (crap_lib_integral_constant_callable >= 201304L) + +template +inline constexpr crap :: ctype :: + is , ctypeBase :: digit> > :: +value_type crap :: ctype :: + is , ctypeBase :: digit> > :: +operator () () const noexcept +{ + return crap :: ctype :: + is , ctypeBase :: digit> > :: + value; +} +#endif +#endif +