Skip to content

Commit

Permalink
Add initial ctype.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaxyM authored Sep 15, 2024
1 parent 96db627 commit d74b8fc
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/crap/locale
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
84 changes: 84 additions & 0 deletions include/crap/locale.d/ctype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef CRAP_LOCALE_CTYPE
#define CRAP_LOCALE_CTYPE

#include <locale>
#include <type_traits>

#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 <class> struct ctype;

template <> struct ctype <char>
{ //Defaults for C standard.
using char_type = char;
template <char_type ... Chars> using string_type = string<char_type, Chars...>;
template <class> struct is;
template <char Char>
struct is<std :: pair<std :: integral_constant<char, Char>, ctypeBase :: digit> >;
template <char Char>
struct is<std :: pair<ctypeBase :: digit>, std :: integral_constant<char, Char> >;
};

template <> struct ctype <wchar_t>
{ //Requires execution encoding.
};

template <char Char> struct :: ;
struct ctype <char> ::
is<std :: pair<std :: integral_constant<char, Char>, 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<char, Char, comparatorsForType <char> :: 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 <char Char> struct :: ;
struct ctype <char> ::
is<std :: pair<ctypeBase :: digit, std :: integral_constant<char, Char> > >
: ctype <char> ::
is<std :: pair<std :: integral_constant<char, Char>, ctypeBase :: digit> >
{
};
}

template <char Char>
inline constexpr crap :: ctype <char> ::
is <std :: pair<std :: integral_constant<char, Char>, ctypeBase :: digit> > ::
operator typename crap :: ctype <char> ::
is <std :: pair<std :: integral_constant<char, Char>, ctypeBase :: digit> > ::
value_type () const noexcept
{
return crap :: ctype <char> ::
is <std :: pair<std :: integral_constant<char, Char>, ctypeBase :: digit> > ::
value;
}
#if (crap_lib_integral_constant_callable >= 201304L)

template <char Char>
inline constexpr crap :: ctype <char> ::
is <std :: pair<std :: integral_constant<char, Char>, ctypeBase :: digit> > ::
value_type crap :: ctype <char> ::
is <std :: pair<std :: integral_constant<char, Char>, ctypeBase :: digit> > ::
operator () () const noexcept
{
return crap :: ctype <char> ::
is <std :: pair<std :: integral_constant<char, Char>, ctypeBase :: digit> > ::
value;
}
#endif
#endif

0 comments on commit d74b8fc

Please sign in to comment.