18 m_pAllocator = GetAllocator();
24 m_pAllocator = allocator ==
TNULL ? GetAllocator() : allocator;
30 m_pAllocator = allocator ==
TNULL ? GetAllocator() : allocator;
37 m_pAllocator = allocator ==
TNULL ? GetAllocator() : allocator;
44 m_pAllocator = allocator ==
TNULL ? GetAllocator() : allocator;
51 m_pAllocator = allocator ==
TNULL ? GetAllocator() : allocator;
57 TString8::m_pAllocator = src.m_pAllocator;
58 TString8::m_iExcessLen = src.m_iExcessLen;
59 TString8::m_iStrLen = src.m_iStrLen;
60 TString8::m_pBuffer = src.m_pBuffer;
67 TASSERT( srcLen <= 0xFFFFFF,
"Too big string" );
69 if ( srcLen < size || size == -1 ) { size = srcLen; }
73 m_pBuffer[ size ] = 0;
78 if ( src != m_pBuffer )
81 TASSERT( srcLen <= 0xFFFFFF,
"Too big string" );
83 if ( srcLen < size || size == -1 )
91 m_pBuffer[ size ] = 0;
98 TASSERT( srcLen <= 0xFFFFFF,
"Too big string" );
100 if ( srcLen < size || size == -1 ) { size = srcLen; }
104 m_pBuffer[ size ] = 0;
111 const TCHAR* foundAt = strchr( &m_pBuffer[ pos ], character );
112 if ( foundAt ==
TNULL )
return -1;
114 return (
TINT)( foundAt - m_pBuffer );
122 if ( foundAt ==
TNULL )
return -1;
124 return (
TINT)( foundAt - m_pBuffer );
132 TASSERT( a_iLength >= 0,
"Length can't be less than 0" );
133 TASSERT( a_iLength <= 0xFFFFFF,
"Too big string" );
135 if ( a_iLength != currentLength )
137 if ( a_iLength == 0 )
139 if ( a_bFreeMemory ) m_pAllocator->Free( m_pBuffer );
141 m_pBuffer = NullString;
148 TINT newExcessLen = ( currentLength - a_iLength ) + m_iExcessLen;
150 if ( newExcessLen < 0 || newExcessLen > 0xFF )
152 if ( currentLength != 0 && a_bFreeMemory )
154 m_pAllocator->Free( m_pBuffer );
157 m_pBuffer = (
TCHAR*)m_pAllocator->Malloc( a_iLength + 1 );
164 m_iExcessLen = newExcessLen;
169 m_iStrLen = a_iLength;
172 if ( a_bFreeMemory ) m_pBuffer[ 0 ] =
'\0';
179 va_start( args, a_pcFormat );
182 TCHAR buffer[ 1024 ];
183 TINT iResult = _vsnprintf( buffer,
sizeof( buffer ), a_pcFormat, args );
184 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" );
192 TCHAR buffer[ 0x400 ];
195 TINT iResult = _vsnprintf( buffer,
sizeof( buffer ), a_pcFormat, a_vargs );
196 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" );
204 TCHAR buffer[ 0x400 ];
208 va_start( args, a_pcFormat );
211 TINT iResult = _vsnprintf( buffer,
sizeof( buffer ), a_pcFormat, args );
212 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" );
213 buffer2.
Copy( buffer, -1 );
220 m_pBuffer = a_cString;
228 m_iStrLen = a_iLength;
246 for ( ; pos > -1; pos-- )
248 if ( a_findChar == m_pBuffer[ pos ] )
264 TCHAR* oldBuffer = m_pBuffer;
272 m_pBuffer[ length ] = 0;
274 if ( allocated &&
Length() != 0 )
276 m_pAllocator->Free( oldBuffer );
282 if (
Length() != 0 ) m_pAllocator->Free( m_pBuffer );
288 TASSERT( a_iIndex >= 0 && a_iIndex <= (
TINT)m_iStrLen );
289 if (
IsIndexValid( a_iIndex ) ) {
return &m_pBuffer[ a_iIndex ]; }
295 TASSERT( a_iIndex >= 0 && a_iIndex <= (
TINT)m_iStrLen );
296 if (
IsIndexValid( a_iIndex ) ) {
return &m_pBuffer[ a_iIndex ]; }
304 if ( ( len < size ) || ( size == -1 ) )
309 TINT oldLength = m_iStrLen;
310 TCHAR* oldString = m_pBuffer;
324 m_pBuffer[ m_iStrLen ] = 0;
326 if ( allocated && oldLength != 0 )
328 m_pAllocator->Free( oldString );
338 TINT iOldLength = m_iStrLen;
339 TCHAR* pOldString = m_pBuffer;
352 m_pBuffer[ iCopySize ] = 0;
355 if ( bAllocated && iOldLength != 0 )
356 m_pAllocator->Free( pOldString );
364 TASSERT( a_pcString !=
TNULL,
"TCString::Compare - Passed string cannot be TNULL" );
368 if ( a_iLength != -1 )
369 return strncmp(
GetString(), a_pcString, a_iLength );
371 return strcmp(
GetString(), a_pcString );
376 TASSERT( a_pcString !=
TNULL,
"TCString::CompareNoCase - Passed string cannot be TNULL" );
380 if ( a_iLength == -1 )
381 return _stricmp(
GetString(), a_pcString );
383 return _strnicmp(
GetString(), a_pcString, a_iLength );
392 else if (
Length() <= a_iFirst )
398 if ( a_iCount < 0 ||
Length() < a_iFirst + a_iCount )
400 a_iCount =
Length() - a_iFirst;
405 strResult[ a_iCount ] =
'\0';
412 return Mid( a_iFrom,
Length() - a_iFrom );
419 if ( ( len < size ) || ( size == -1 ) )
425 TCHAR* oldString = m_pBuffer;
439 m_pBuffer[ m_iStrLen ] = 0;
441 if ( allocated && m_iStrLen != 0 )
443 m_pAllocator->Free( oldString );
451 TCHAR* pChar = m_pBuffer;
453 while ( pChar < m_pBuffer + m_iStrLen )
455 TCHAR cChar = *pChar++;
456 if ( cChar >=
'A' && cChar <=
'Z' )
return TFALSE;
464 TCHAR* pChar = m_pBuffer;
466 while ( pChar < m_pBuffer + m_iStrLen )
468 TCHAR cChar = *pChar++;
469 if ( cChar >=
'a' && cChar <=
'z' )
return TFALSE;
479 if (
Length() < iStringLength )
482 return Compare( a_szString, iStringLength ) == 0;
489 if (
Length() < iStringLength )
492 return strncmp(
GetString(
Length() - iStringLength ), a_szString, iStringLength ) == 0;
499 if (
Length() < iStringLength )
509 if (
Length() < iStringLength )
512 return strnicmp(
GetString(
Length() - iStringLength ), a_szString, iStringLength ) == 0;
#define TOSHI_NAMESPACE_START
#define TOSHI_NAMESPACE_END
Char string implementation for the Toshi engine.
TFORCEINLINE const T & Min(const T &a, const T &b)
static TSIZE Length(const TCHAR *str)
const TWCHAR * GetString(TINT index=0) const
TString8 Mid(TINT a_iFirst, TINT a_iCount) const
TBOOL EndsWithNoCase(const TCHAR *a_szString, TINT a_iLength=-1) const
TString8 & Format(const TCHAR *a_pcFormat,...)
TBOOL EndsWith(const TCHAR *a_szString, TINT a_iLength=-1) const
TString8 & Concat(const TString8 &str, TINT size=-1)
TINT Compare(const TCHAR *a_szString, TINT a_iLength=-1) const
TCHAR * GetStringUnsafe(TINT a_iIndex=0)
TINT Find(TCHAR character, TINT pos=0) const
TBOOL IsAllLowerCase() const
TBOOL AllocBuffer(TINT a_iLength, TBOOL a_bFreeMemory=true)
TBOOL IsAllUpperCase() const
TINT CompareNoCase(const TCHAR *a_szString, TINT a_iLength=-1) const
TINT FindReverse(TCHAR a_findChar, TINT pos=-1) const
static TString8 VarArgs(const TCHAR *a_pcFormat,...)
TBOOL IsIndexValid(TINT a_iIndex) const
TBOOL StartsWith(const TCHAR *a_szString, TINT a_iLength=-1) const
TBOOL StartsWithNoCase(const TCHAR *a_szString, TINT a_iLength=-1) const
TString8 & VFormat(const TCHAR *a_pcFormat, va_list a_vargs)
void ForceSetData(TCHAR *a_pchString, TINT a_iLength)
void Truncate(TINT length)
void Copy(const TString8 &src, TINT size=-1)
TUINT16 ExcessLength() const
TString8 & Reserve(TINT size)
const TCHAR * GetString(TINT a_iIndex=0) const
TString8 Right(TINT a_iFrom) const
static TSIZE String8Length(const TCHAR *str)
static TSIZE String16Length(const TWCHAR *str)
static TCHAR * String8Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)
static TCHAR * StringUnicodeToChar(TCHAR *a_CharString, const TWCHAR *const &a_UnicodeString, TUINT32 a_iLength)
static void * MemCopy(void *dst, const void *src, TSIZE size)