OpenBarnyard
 
Loading...
Searching...
No Matches
T2String16.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "T2CharTraits.h"
3#include "T2String16.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
14
15TINT T2String16::FormatV( TWCHAR* a_pcString, TINT size, const TWCHAR* a_pcFormat, va_list args )
16{
17 TINT iResult = _vsnwprintf( a_pcString, size, a_pcFormat, args );
18 TASSERT( iResult != -1, "PS2/GC/X360 do not correctly support _vsnprintf, this code will cause memory to be clobbered on those platforms! Increase the size of the destination string to avoid this problem" );
19 a_pcString[ size - 1 ] = '\0';
20 return iResult;
21}
22
23TINT T2String16::FormatV( TWCHAR* a_pcString, const TWCHAR* a_pcFormat, va_list args )
24{
25 TINT iResult = _vswprintf( a_pcString, a_pcFormat, args );
26 TASSERT( iResult != -1, "PS2/GC/X360 do not correctly support _vsnprintf, this code will cause memory to be clobbered on those platforms! Increase the size of the destination string to avoid this problem" );
27 return iResult;
28}
29
30TINT T2String16::Format( TWCHAR* a_pcString, const TWCHAR* a_pcFormat, ... )
31{
32 va_list args;
33
34 va_start( args, a_pcFormat );
35 TINT iResult = FormatV( a_pcString, a_pcFormat, args );
36 va_end( args );
37
38 return iResult;
39}
40
41TINT T2String16::Format( TWCHAR* a_pcString, TINT size, const TWCHAR* a_pcFormat, ... )
42{
43 va_list args;
44
45 va_start( args, a_pcFormat );
46 TINT iResult = FormatV( a_pcString, size, a_pcFormat, args );
47 va_end( args );
48
49 return iResult;
50}
51
52TINT T2String16::Compare( const TWCHAR* str1, const TWCHAR* str2, TSIZE size )
53{
54 if ( size != -1 )
55 return wcsncmp( str1, str2, size );
56
57 return wcscmp( str1, str2 );
58}
59
60TINT T2String16::CompareNoCase( const TWCHAR* str1, const TWCHAR* str2, TSIZE size )
61{
62 if ( size != -1 )
63 {
64 return _wcsnicmp( str1, str2, size );
65 }
66
67 return _wcsicmp( str1, str2 );
68}
69
70TWCHAR* T2String16::Copy( TWCHAR* dst, const TWCHAR* src, TSIZE size )
71{
72 if ( size != -1 )
73 return wcsncpy( dst, src, size );
74
75 return wcscpy( dst, src );
76}
77
78TWCHAR* T2String16::CopySafe( TWCHAR* dst, const TWCHAR* src, TSIZE size )
79{
80 TSIZE srcLen = Length( src );
81 size = TMath::Min( size - 1, srcLen );
82 wcsncpy( dst, src, size );
83 dst[ size ] = L'\0';
84 return dst;
85}
86
87TWCHAR* T2String16::Concat( TWCHAR* dst, const TWCHAR* src, TSIZE size /*= -1 */ )
88{
89 if ( size != -1 )
90 return wcsncat( dst, src, size );
91
92 return wcscat( dst, src );
93}
94
95const TWCHAR* T2String16::FindChar( const TWCHAR* str, TWCHAR character )
96{
97 while ( TTRUE )
98 {
99 if ( *str == L'\0' ) return TNULL;
100 if ( *str == character ) return str;
101 str++;
102 }
103
104 return TNULL;
105}
106
108{
109 while ( TTRUE )
110 {
111 if ( *str == L'\0' ) return TNULL;
112 if ( *str == character ) return str;
113 str++;
114 }
115
116 return TNULL;
117}
118
119const TWCHAR* T2String16::FindString( const TWCHAR* str, const TWCHAR* substr )
120{
121 return wcsstr( str, substr );
122}
123
125{
126 return wcsstr( str, substr );
127}
128
130{
131 if ( str != TNULL ) return wcslen( str );
132 return -1;
133}
134
136{
137 while ( *str != L'\0' && T2Char16::IsLowerCase( *str ) )
138 str++;
139
140 return ( *str == L'\0' );
141}
142
144{
145 while ( *str != L'\0' && T2Char16::IsUpperCase( *str ) )
146 str++;
147
148 return ( *str == L'\0' );
149}
150
152{
153 while ( *str )
154 {
155 *str = T2Char16::ToLowerCase( *str );
156 str++;
157 }
158}
159
161{
162 while ( *str )
163 {
164 *str = T2Char16::ToUpperCase( *str );
165 str++;
166 }
167}
168
169void T2String16::IntToString( TINT value, TWCHAR* dst, TINT unused, TINT radix )
170{
171 _itow( value, dst, radix );
172}
173
174void T2String16::IntToString( TINT value, TWCHAR* dst, TINT radix )
175{
176 _itow( value, dst, radix );
177}
178
180{
181 return _wtoi( src );
182}
183
185{
186 return (TFLOAT)_wtof( src );
187}
188
190{
191 TWCHAR* pszCursor = str;
192 while ( T2Char16::IsSpace( *pszCursor ) ) pszCursor++;
193
194 return pszCursor;
195}
196
198{
199 const TWCHAR* pszCursor = str;
200 while ( T2Char16::IsSpace( *pszCursor ) ) pszCursor++;
201
202 return pszCursor;
203}
204
205TWCHAR* T2String16::CreateCopy( const TWCHAR* a_wszString, TSIZE a_uiSize )
206{
207 TSIZE uiSize = ( a_uiSize == -1 ) ? T2String16::Length( a_wszString ) : a_uiSize;
208
209 TWCHAR* wszBuffer = new TWCHAR[ uiSize + 1 ];
210 TUtil::MemCopy( wszBuffer, a_wszString, uiSize * sizeof( TWCHAR ) );
211 wszBuffer[ uiSize ] = L'\0';
212
213 return wszBuffer;
214}
215
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
wchar_t TWCHAR
Definition Typedefs.h:21
size_t TSIZE
Definition Typedefs.h:9
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TFORCEINLINE const T & Min(const T &a, const T &b)
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 TWCHAR * FindString(TWCHAR *str, const TWCHAR *substr)
static void ToUpperCase(TWCHAR *str)
static TWCHAR * Copy(TWCHAR *dst, const TWCHAR *src, TSIZE size=-1)
static TWCHAR ms_aScratchMem[SCRATCH_MEM_SIZE]
Definition T2String16.h:61
static TINT FormatV(TWCHAR *a_pcString, TINT size, const TWCHAR *a_pcFormat, va_list args)
static constexpr TSIZE SCRATCH_MEM_SIZE
Definition T2String16.h:12
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 TINT Format(TWCHAR *a_pcString, TINT size, const TWCHAR *a_pcFormat,...)
static TWCHAR * CreateCopy(const TWCHAR *a_wszString, TSIZE a_uiSize=-1)
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90