OpenBarnyard
 
Loading...
Searching...
No Matches
T2CharTraits.h
Go to the documentation of this file.
1#pragma once
2
3#include <cctype>
4#include <type_traits>
5
7
8//-----------------------------------------------------------------------------
9// Purpose: Helper class that gives you the required methods to operate
10// with characters of different types using the same interface
11//-----------------------------------------------------------------------------
12template <typename CharT>
14{
15public:
16 using CharType = CharT;
17 using UCharType = std::make_unsigned_t<CharT>;
18 constexpr static TSIZE CharSize = sizeof( CharType );
19 constexpr static CharType NullChar = 0;
20
21public:
22 static TBOOL IsSpace( TINT a_cChar ) { TUNREACHABLE(); }
23 static TBOOL IsUpperCase( TINT a_cChar ) { TUNREACHABLE(); }
24 static TBOOL IsLowerCase( TINT a_cChar ) { TUNREACHABLE(); }
25 static CharType ToUpperCase( TINT a_cChar ) { TUNREACHABLE(); }
26 static CharType ToLowerCase( TINT a_cChar ) { TUNREACHABLE(); }
27};
28
31
32//-----------------------------------------------------------------------------
33// TCHAR - 1 byte character
34//-----------------------------------------------------------------------------
35
36template <>
38{
39 return isspace( a_cChar ) != 0;
40}
41
42template <>
44{
45 return isupper( a_cChar ) != 0 || isalpha( a_cChar ) == 0;
46}
47
48template <>
50{
51 return islower( a_cChar ) != 0 || isalpha( a_cChar ) == 0;
52}
53
54template <>
56{
57 return (TCHAR)toupper( a_cChar );
58}
59
60template <>
62{
63 return (TCHAR)tolower( a_cChar );
64}
65
66//-----------------------------------------------------------------------------
67// TWCHAR - 2 bytes character
68//-----------------------------------------------------------------------------
69
70template <>
72{
73 return iswspace( a_cChar ) != 0;
74}
75
76template <>
78{
79 return iswupper( a_cChar ) != 0 || iswalpha( a_cChar ) == 0;
80}
81
82template <>
84{
85 return iswlower( a_cChar ) != 0 || iswalpha( a_cChar ) == 0;
86}
87
88template <>
90{
91 return (TWCHAR)towupper( a_cChar );
92}
93
94template <>
96{
97 return (TWCHAR)towlower( a_cChar );
98}
99
#define TINLINE
Definition Defines.h:73
#define TUNREACHABLE()
Definition Defines.h:142
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
T2CharTraits< TCHAR > T2Char8
T2CharTraits< TWCHAR > T2Char16
wchar_t TWCHAR
Definition Typedefs.h:21
size_t TSIZE
Definition Typedefs.h:9
char TCHAR
Definition Typedefs.h:20
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
std::make_unsigned_t< CharT > UCharType
static CharType ToLowerCase(TINT a_cChar)
static CharType ToUpperCase(TINT a_cChar)
static TBOOL IsUpperCase(TINT a_cChar)
static TBOOL IsSpace(TINT a_cChar)
static TBOOL IsLowerCase(TINT a_cChar)
static constexpr TSIZE CharSize
static constexpr CharType NullChar