OpenBarnyard
 
Loading...
Searching...
No Matches
T2StringTraits.h
Go to the documentation of this file.
1#pragma once
2#include "T2CharTraits.h"
3#include "T2String8.h"
4#include "T2String16.h"
5
7
8//-----------------------------------------------------------------------------
9// Purpose: Helper class that gives you the required methods to operate
10// with strings of different char types using specified char traits
11//-----------------------------------------------------------------------------
12template <typename CharT, typename TCharTraits = T2CharTraits<CharT>>
14{
15public:
16 using CharTraits = TCharTraits;
17 using CharType = typename TCharTraits::CharType;
18 using UCharType = typename TCharTraits::UCharType;
19
20public:
21 static TINT FormatV( CharType* a_pcString, TINT size, const CharType* a_pcFormat, va_list args ) { TUNREACHABLE(); }
22 static TINT FormatV( CharType* a_pcString, const CharType* a_pcFormat, va_list args ) { TUNREACHABLE(); }
23
24 static TINT Format( CharType* a_pcString, TINT size, const CharType* a_pcFormat, ... ) { TUNREACHABLE(); }
25 static TINT Format( CharType* a_pcString, const CharType* a_pcFormat, ... ) { TUNREACHABLE(); }
26
27 static TINT Compare( const CharType* str1, const CharType* str2, TSIZE size = -1 ) { TUNREACHABLE(); }
28 static TINT CompareNoCase( const CharType* str1, const CharType* str2, TSIZE size = -1 ) { TUNREACHABLE(); }
29
30 static CharType* Copy( CharType* dst, const CharType* src, TSIZE size = -1 ) { TUNREACHABLE(); }
31 static CharType* CopySafe( CharType* dst, const CharType* src, TSIZE size ) { TUNREACHABLE(); }
32
33 static CharType* Concat( CharType* dst, const CharType* src, TSIZE size = -1 ) { TUNREACHABLE(); }
34
35 static CharType* FindChar( CharType* str, CharType character ) { TUNREACHABLE(); }
36 static const CharType* FindChar( const CharType* str, CharType character ) { TUNREACHABLE(); }
37 static CharType* FindString( CharType* str, const CharType* substr ) { TUNREACHABLE(); }
38 static const CharType* FindString( const CharType* str, const CharType* substr ) { TUNREACHABLE(); }
39
40 static TSIZE Length( const CharType* str ) { TUNREACHABLE(); }
41
42 static TBOOL IsLowerCase( const CharType* str ) { TUNREACHABLE(); }
43 static TBOOL IsUpperCase( const CharType* str ) { TUNREACHABLE(); }
44
45 static void ToLowerCase( CharType* str ) { TUNREACHABLE(); }
46 static void ToUpperCase( CharType* str ) { TUNREACHABLE(); }
47
48 static void IntToString( TINT value, CharType* dst, TINT unused, TINT radix ) { TUNREACHABLE(); }
49 static void IntToString( TINT value, CharType* dst, TINT radix ) { TUNREACHABLE(); }
50
51 static TINT StringToInt( const CharType* src ) { TUNREACHABLE(); }
52 static TFLOAT StringToFloat( const CharType* src ) { TUNREACHABLE(); }
53
55 static const CharType* SkipSpaces( const CharType* str ) { TUNREACHABLE(); }
56};
57
58//-----------------------------------------------------------------------------
59// TCHAR - 1 byte character
60//-----------------------------------------------------------------------------
61
62template <>
63TINLINE TINT T2StringTraits<TCHAR>::FormatV( CharType* a_pcString, TINT size, const CharType* a_pcFormat, va_list args )
64{
65 return T2String8::FormatV( a_pcString, size, a_pcFormat, args );
66}
67
68template <>
69TINLINE TINT T2StringTraits<TCHAR>::FormatV( CharType* a_pcString, const CharType* a_pcFormat, va_list args )
70{
71 return T2String8::FormatV( a_pcString, a_pcFormat, args );
72}
73
74template <>
75TINLINE TINT T2StringTraits<TCHAR>::Format( CharType* a_pcString, TINT size, const CharType* a_pcFormat, ... )
76{
77 va_list args;
78
79 va_start( args, a_pcFormat );
80 TINT iResult = FormatV( a_pcString, size, a_pcFormat, args );
81 va_end( args );
82
83 return iResult;
84}
85
86template <>
87TINLINE TINT T2StringTraits<TCHAR>::Format( CharType* a_pcString, const CharType* a_pcFormat, ... )
88{
89 va_list args;
90
91 va_start( args, a_pcFormat );
92 TINT iResult = FormatV( a_pcString, a_pcFormat, args );
93 va_end( args );
94
95 return iResult;
96}
97
98template <>
99TINLINE TINT T2StringTraits<TCHAR>::Compare( const CharType* str1, const CharType* str2, TSIZE size /*= -1 */ )
100{
101 return T2String8::Compare( str1, str2, size );
102}
103
104template <>
105TINLINE TINT T2StringTraits<TCHAR>::CompareNoCase( const CharType* str1, const CharType* str2, TSIZE size /*= -1 */ )
106{
107 return T2String8::CompareNoCase( str1, str2, size );
108}
109
110template <>
112{
113 return T2String8::Copy( dst, src, size );
114}
115
116template <>
121
122template <>
124{
125 return T2String8::Concat( dst, src, size );
126}
127
128template <>
133
134template <>
136{
137 return T2String8::FindChar( str, character );
138}
139
140template <>
145
146template <>
148{
149 return T2String8::FindString( str, substr );
150}
151
152template <>
154{
155 return T2String8::Length( str );
156}
157
158template <>
163
164template <>
169
170template <>
175
176template <>
181
182template <>
184{
185 T2String8::IntToString( value, dst, unused, radix );
186}
187
188template <>
190{
191 T2String8::IntToString( value, dst, radix );
192}
193
194template <>
199
200template <>
205
206template <>
211
212template <>
217
218//-----------------------------------------------------------------------------
219// TWCHAR - 2 bytes character
220//-----------------------------------------------------------------------------
221
222template <>
223TINLINE TINT T2StringTraits<TWCHAR>::FormatV( CharType* a_pcString, TINT size, const CharType* a_pcFormat, va_list args )
224{
225 return T2String16::FormatV( a_pcString, size, a_pcFormat, args );
226}
227
228template <>
229TINLINE TINT T2StringTraits<TWCHAR>::FormatV( CharType* a_pcString, const CharType* a_pcFormat, va_list args )
230{
231 return T2String16::FormatV( a_pcString, a_pcFormat, args );
232}
233
234template <>
235TINLINE TINT T2StringTraits<TWCHAR>::Format( CharType* a_pcString, TINT size, const CharType* a_pcFormat, ... )
236{
237 va_list args;
238
239 va_start( args, a_pcFormat );
240 TINT iResult = FormatV( a_pcString, size, a_pcFormat, args );
241 va_end( args );
242
243 return iResult;
244}
245
246template <>
247TINLINE TINT T2StringTraits<TWCHAR>::Format( CharType* a_pcString, const CharType* a_pcFormat, ... )
248{
249 va_list args;
250
251 va_start( args, a_pcFormat );
252 TINT iResult = FormatV( a_pcString, a_pcFormat, args );
253 va_end( args );
254
255 return iResult;
256}
257
258template <>
259TINLINE TINT T2StringTraits<TWCHAR>::Compare( const CharType* str1, const CharType* str2, TSIZE size /*= -1 */ )
260{
261 return T2String16::Compare( str1, str2, size );
262}
263
264template <>
265TINLINE TINT T2StringTraits<TWCHAR>::CompareNoCase( const CharType* str1, const CharType* str2, TSIZE size /*= -1 */ )
266{
267 return T2String16::CompareNoCase( str1, str2, size );
268}
269
270template <>
272{
273 return T2String16::Copy( dst, src, size );
274}
275
276template <>
281
282template <>
284{
285 return T2String16::Concat( dst, src, size );
286}
287
288template <>
293
294template <>
296{
297 return T2String16::FindChar( str, character );
298}
299
300template <>
305
306template <>
308{
309 return T2String16::FindString( str, substr );
310}
311
312template <>
314{
315 return T2String16::Length( str );
316}
317
318template <>
323
324template <>
329
330template <>
335
336template <>
341
342template <>
344{
345 T2String16::IntToString( value, dst, unused, radix );
346}
347
348template <>
350{
351 T2String16::IntToString( value, dst, radix );
352}
353
354template <>
359
360template <>
365
366template <>
371
372template <>
377
#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
size_t TSIZE
Definition Typedefs.h:9
float TFLOAT
Definition Typedefs.h:4
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
static TWCHAR * FindString(TWCHAR *str, const TWCHAR *substr)
static void ToUpperCase(TWCHAR *str)
static TWCHAR * Copy(TWCHAR *dst, const TWCHAR *src, TSIZE size=-1)
static TINT FormatV(TWCHAR *a_pcString, TINT size, const TWCHAR *a_pcFormat, va_list args)
static TWCHAR * CopySafe(TWCHAR *dst, const TWCHAR *src, TSIZE size)
static TSIZE Length(const TWCHAR *str)
static TWCHAR * SkipSpaces(TWCHAR *str)
static void ToLowerCase(TWCHAR *str)
static TINT CompareNoCase(const TWCHAR *str1, const TWCHAR *str2, TSIZE size=-1)
static TINT Compare(const TWCHAR *str1, const TWCHAR *str2, TSIZE size=-1)
static TFLOAT StringToFloat(const TWCHAR *src)
static TINT StringToInt(const TWCHAR *src)
static TWCHAR * Concat(TWCHAR *dst, const TWCHAR *src, TSIZE size=-1)
static void IntToString(TINT value, TWCHAR *dst, TINT unused, TINT radix)
static TBOOL IsUpperCase(const TWCHAR *str)
static TBOOL IsLowerCase(const TWCHAR *str)
static TWCHAR * FindChar(TWCHAR *str, TWCHAR character)
static TCHAR * FindChar(TCHAR *str, TCHAR character)
static TSIZE Length(const TCHAR *str)
static TCHAR * SkipSpaces(TCHAR *str)
static void ToUpperCase(TCHAR *str)
static TBOOL IsLowerCase(const TCHAR *str)
static TINT FormatV(TCHAR *a_pcString, TINT size, const TCHAR *a_pcFormat, va_list args)
Definition T2String8.cpp:22
static void IntToString(TINT value, TCHAR *dst, TINT unused, TINT radix)
static TFLOAT StringToFloat(const TCHAR *src)
static void ToLowerCase(TCHAR *str)
static TBOOL IsUpperCase(const TCHAR *str)
static TCHAR * Concat(TCHAR *dst, const TCHAR *src, TSIZE size=-1)
Definition T2String8.cpp:76
static TCHAR * CopySafe(TCHAR *dst, const TCHAR *src, TSIZE size)
Definition T2String8.cpp:84
static TINT Compare(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
Definition T2String8.cpp:52
static TINT CompareNoCase(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
Definition T2String8.cpp:60
static TCHAR * Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)
Definition T2String8.cpp:68
static TCHAR * FindString(TCHAR *str, const TCHAR *substr)
static TINT StringToInt(const TCHAR *src)
static TINT Format(CharType *a_pcString, const CharType *a_pcFormat,...)
static CharType * Concat(CharType *dst, const CharType *src, TSIZE size=-1)
static TINT CompareNoCase(const CharType *str1, const CharType *str2, TSIZE size=-1)
static void ToLowerCase(CharType *str)
typename TCharTraits::CharType CharType
static TINT Format(CharType *a_pcString, TINT size, const CharType *a_pcFormat,...)
static TINT Compare(const CharType *str1, const CharType *str2, TSIZE size=-1)
static CharType * FindString(CharType *str, const CharType *substr)
static const CharType * SkipSpaces(const CharType *str)
static void ToUpperCase(CharType *str)
static TBOOL IsUpperCase(const CharType *str)
typename TCharTraits::UCharType UCharType
static TINT StringToInt(const CharType *src)
static const CharType * FindChar(const CharType *str, CharType character)
static CharType * SkipSpaces(CharType *str)
TCharTraits CharTraits
static TSIZE Length(const CharType *str)
static TINT FormatV(CharType *a_pcString, TINT size, const CharType *a_pcFormat, va_list args)
static TFLOAT StringToFloat(const CharType *src)
static const CharType * FindString(const CharType *str, const CharType *substr)
static CharType * FindChar(CharType *str, CharType character)
static void IntToString(TINT value, CharType *dst, TINT unused, TINT radix)
static TBOOL IsLowerCase(const CharType *str)
static CharType * CopySafe(CharType *dst, const CharType *src, TSIZE size)
static void IntToString(TINT value, CharType *dst, TINT radix)
static CharType * Copy(CharType *dst, const CharType *src, TSIZE size=-1)
static TINT FormatV(CharType *a_pcString, const CharType *a_pcFormat, va_list args)