OpenBarnyard
 
Loading...
Searching...
No Matches
TString8 Class Reference

#include <TString8.h>

Public Member Functions

 TString8 ()
 
 TString8 (T2Allocator *allocator)
 
 TString8 (TString8 &&src) noexcept
 
 TString8 (const TString8 &src, T2Allocator *allocator=nullptr)
 
 TString8 (const TString16 &src, T2Allocator *allocator=nullptr)
 
 TString8 (const TCHAR *src, T2Allocator *allocator=nullptr)
 
 TString8 (TINT size, T2Allocator *allocator=nullptr)
 
 ~TString8 ()
 
void Copy (const TString8 &src, TINT size=-1)
 
void Copy (const TString16 &src, TINT size=-1)
 
void Copy (const TCHAR *src, TINT size=-1)
 
void Copy (const TWCHAR *src, TINT size=-1)
 
void FreeBuffer ()
 
TBOOL AllocBuffer (TINT a_iLength, TBOOL a_bFreeMemory=true)
 
TString8Format (const TCHAR *a_pcFormat,...)
 
TString8VFormat (const TCHAR *a_pcFormat, va_list a_vargs)
 
void UndoForceSetData ()
 
void ForceSetData (TCHAR *a_pchString, TINT a_iLength)
 
TINT FindReverse (TCHAR a_findChar, TINT pos=-1) const
 
void Truncate (TINT length)
 
TINT Find (TCHAR character, TINT pos=0) const
 
TINT Find (const TCHAR *substr, TINT pos=0) const
 
const TCHARGetString (TINT a_iIndex=0) const
 
TCHARGetStringUnsafe (TINT a_iIndex=0)
 
TString8Concat (const TString8 &str, TINT size=-1)
 
TString8Concat (const TString16 &src, TINT size=-1)
 
TString8Concat (const TCHAR *src, TINT size=-1)
 
TString8Reserve (TINT size)
 
TINT Compare (const TCHAR *a_szString, TINT a_iLength=-1) const
 
TINT CompareNoCase (const TCHAR *a_szString, TINT a_iLength=-1) const
 
TString8 Mid (TINT a_iFirst, TINT a_iCount) const
 
TString8 Right (TINT a_iFrom) const
 
TString8MakeUpper ()
 
TString8MakeLower ()
 
TINT Length () const
 
TUINT16 ExcessLength () const
 
TBOOL StartsWith (const TCHAR *a_szString, TINT a_iLength=-1) const
 
TBOOL EndsWith (const TCHAR *a_szString, TINT a_iLength=-1) const
 
TBOOL StartsWithNoCase (const TCHAR *a_szString, TINT a_iLength=-1) const
 
TBOOL EndsWithNoCase (const TCHAR *a_szString, TINT a_iLength=-1) const
 
TBOOL IsAllLowerCase () const
 
TBOOL IsAllUpperCase () const
 
TBOOL IsIndexValid (TINT a_iIndex) const
 
TBOOL IsEmpty () const
 
TBOOL IsUnicode () const
 
TString8 operator+ (const TCHAR *cstr) const
 
TString8operator+= (const TCHAR *cstr)
 
TString8operator+= (TString8 &str)
 
TCHARoperator[] (TINT a_iIndex)
 
const TCHARoperator[] (TINT a_iIndex) const
 
 operator const TCHAR * () const
 
 operator const TBOOL () const
 
TBOOL operator! ()
 
TBOOL operator== (const TCHAR *cstr) const
 
TBOOL operator== (const TString8 &str) const
 
TBOOL operator!= (const TCHAR *cstr) const
 
TBOOL operator!= (const TString8 &str) const
 
TBOOL operator< (const TCHAR *cstr) const
 
TBOOL operator< (const TString8 &str) const
 
TBOOL operator<= (const TCHAR *cstr) const
 
TBOOL operator<= (const TString8 &str) const
 
TString8operator= (const TCHAR *cstr)
 
TString8operator= (const TWCHAR *wcstr)
 
TString8operator= (const TString8 &str)
 
TString8operator= (TString8 &&str)
 
TString8operator= (const TString16 &str)
 

Static Public Member Functions

static TString8 VarArgs (const TCHAR *a_pcFormat,...)
 

Detailed Description

Definition at line 20 of file TString8.h.

Constructor & Destructor Documentation

◆ TString8() [1/7]

TString8::TString8 ( )

Definition at line 15 of file TString8.cpp.

16{
17 Reset();
18 m_pAllocator = GetAllocator();
19}

◆ TString8() [2/7]

TString8::TString8 ( T2Allocator * allocator)

Definition at line 21 of file TString8.cpp.

22{
23 Reset();
24 m_pAllocator = allocator == TNULL ? GetAllocator() : allocator;
25}
#define TNULL
Definition Typedefs.h:23

◆ TString8() [3/7]

TString8::TString8 ( TString8 && src)
noexcept

Definition at line 55 of file TString8.cpp.

56{
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;
61 src.Reset();
62}

◆ TString8() [4/7]

TString8::TString8 ( const TString8 & src,
T2Allocator * allocator = nullptr )

Definition at line 27 of file TString8.cpp.

28{
29 Reset();
30 m_pAllocator = allocator == TNULL ? GetAllocator() : allocator;
31 Copy( src, -1 );
32}
void Copy(const TString8 &src, TINT size=-1)
Definition TString8.h:32

◆ TString8() [5/7]

TString8::TString8 ( const TString16 & src,
T2Allocator * allocator = nullptr )

Definition at line 41 of file TString8.cpp.

42{
43 Reset();
44 m_pAllocator = allocator == TNULL ? GetAllocator() : allocator;
45 Copy( src );
46}

◆ TString8() [6/7]

TString8::TString8 ( const TCHAR * src,
T2Allocator * allocator = nullptr )

Definition at line 48 of file TString8.cpp.

49{
50 Reset();
51 m_pAllocator = allocator == TNULL ? GetAllocator() : allocator;
52 Copy( src );
53}

◆ TString8() [7/7]

TString8::TString8 ( TINT size,
T2Allocator * allocator = nullptr )

Definition at line 34 of file TString8.cpp.

35{
36 Reset();
37 m_pAllocator = allocator == TNULL ? GetAllocator() : allocator;
38 AllocBuffer( size );
39}
TBOOL AllocBuffer(TINT a_iLength, TBOOL a_bFreeMemory=true)
Definition TString8.cpp:127

◆ ~TString8()

TString8::~TString8 ( )
inline

Definition at line 30 of file TString8.h.

30{ FreeBuffer(); }
void FreeBuffer()
Definition TString8.cpp:280

Member Function Documentation

◆ AllocBuffer()

TBOOL TString8::AllocBuffer ( TINT a_iLength,
TBOOL a_bFreeMemory = true )

Definition at line 127 of file TString8.cpp.

128{
129 TBOOL hasChanged = TFALSE;
130 TUINT32 currentLength = Length();
131
132 TASSERT( a_iLength >= 0, "Length can't be less than 0" );
133 TASSERT( a_iLength <= 0xFFFFFF, "Too big string" );
134
135 if ( a_iLength != currentLength )
136 {
137 if ( a_iLength == 0 )
138 {
139 if ( a_bFreeMemory ) m_pAllocator->Free( m_pBuffer );
140
141 m_pBuffer = NullString;
142 m_iExcessLen = 0;
143
144 hasChanged = TTRUE;
145 }
146 else
147 {
148 TINT newExcessLen = ( currentLength - a_iLength ) + m_iExcessLen;
149
150 if ( newExcessLen < 0 || newExcessLen > 0xFF )
151 {
152 if ( currentLength != 0 && a_bFreeMemory )
153 {
154 m_pAllocator->Free( m_pBuffer );
155 }
156
157 m_pBuffer = (TCHAR*)m_pAllocator->Malloc( a_iLength + 1 );
158 m_iExcessLen = 0;
159
160 hasChanged = TTRUE;
161 }
162 else
163 {
164 m_iExcessLen = newExcessLen;
165 hasChanged = TFALSE;
166 }
167 }
168
169 m_iStrLen = a_iLength;
170 }
171
172 if ( a_bFreeMemory ) m_pBuffer[ 0 ] = '\0';
173 return hasChanged;
174}
#define TASSERT(X,...)
Definition Defines.h:138
char TCHAR
Definition Typedefs.h:20
uint32_t TUINT32
Definition Typedefs.h:13
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TINT Length() const
Definition TString8.h:93

◆ Compare()

TINT TString8::Compare ( const TCHAR * a_szString,
TINT a_iLength = -1 ) const

Definition at line 362 of file TString8.cpp.

363{
364 TASSERT( a_pcString != TNULL, "TCString::Compare - Passed string cannot be TNULL" );
365 TASSERT( IsIndexValid( 0 ), "TCString::Compare - Index 0 is not valid" );
366 TASSERT( GetString() != TNULL, "TCString::Compare - String cannot be TNULL" );
367
368 if ( a_iLength != -1 )
369 return strncmp( GetString(), a_pcString, a_iLength );
370
371 return strcmp( GetString(), a_pcString );
372}
TBOOL IsIndexValid(TINT a_iIndex) const
Definition TString8.h:103
const TCHAR * GetString(TINT a_iIndex=0) const
Definition TString8.cpp:286

◆ CompareNoCase()

TINT TString8::CompareNoCase ( const TCHAR * a_szString,
TINT a_iLength = -1 ) const

Definition at line 374 of file TString8.cpp.

375{
376 TASSERT( a_pcString != TNULL, "TCString::CompareNoCase - Passed string cannot be TNULL" );
377 TASSERT( IsIndexValid( 0 ), "TCString::CompareNoCase - Index 0 is not valid" );
378 TASSERT( GetString() != TNULL, "TCString::CompareNoCase - String cannot be TNULL" );
379
380 if ( a_iLength == -1 )
381 return _stricmp( GetString(), a_pcString );
382
383 return _strnicmp( GetString(), a_pcString, a_iLength );
384}

◆ Concat() [1/3]

TString8 & TString8::Concat ( const TCHAR * src,
TINT size = -1 )

Definition at line 300 of file TString8.cpp.

301{
303
304 if ( ( len < size ) || ( size == -1 ) )
305 {
306 size = len;
307 }
308
309 TINT oldLength = m_iStrLen;
310 TCHAR* oldString = m_pBuffer;
311
312 TBOOL allocated = AllocBuffer( m_iStrLen + size, TFALSE );
313
314 if ( allocated )
315 {
316 // since it has made a new buffer
317 // it needs to copy the old string
318 // to the new buffer
319
320 TStringManager::String8Copy( m_pBuffer, oldString, -1 );
321 }
322
323 TStringManager::String8Copy( m_pBuffer + oldLength, str, size );
324 m_pBuffer[ m_iStrLen ] = 0;
325
326 if ( allocated && oldLength != 0 )
327 {
328 m_pAllocator->Free( oldString );
329 }
330
331 return *this;
332}
static TSIZE String8Length(const TCHAR *str)
static TCHAR * String8Copy(TCHAR *dst, const TCHAR *src, TSIZE size=-1)

◆ Concat() [2/3]

TString8 & TString8::Concat ( const TString16 & src,
TINT size = -1 )

Definition at line 415 of file TString8.cpp.

416{
417 TINT len = str.Length();
418
419 if ( ( len < size ) || ( size == -1 ) )
420 {
421 size = len;
422 }
423
424 TUINT32 oldLength = m_iStrLen;
425 TCHAR* oldString = m_pBuffer;
426
427 TBOOL allocated = AllocBuffer( m_iStrLen + size, TFALSE );
428
429 if ( allocated )
430 {
431 // since it has made a new buffer
432 // it needs to copy the old string
433 // to the new buffer
434
435 TStringManager::String8Copy( m_pBuffer, oldString, -1 );
436 }
437
438 TStringManager::StringUnicodeToChar( m_pBuffer + oldLength, str.GetString(), size );
439 m_pBuffer[ m_iStrLen ] = 0;
440
441 if ( allocated && m_iStrLen != 0 )
442 {
443 m_pAllocator->Free( oldString );
444 }
445
446 return *this;
447}
static TCHAR * StringUnicodeToChar(TCHAR *a_CharString, const TWCHAR *const &a_UnicodeString, TUINT32 a_iLength)

◆ Concat() [3/3]

TString8 & TString8::Concat ( const TString8 & str,
TINT size = -1 )
inline

Definition at line 66 of file TString8.h.

66{ return Concat( str.m_pBuffer, size ); };
TString8 & Concat(const TString8 &str, TINT size=-1)
Definition TString8.h:66

◆ Copy() [1/4]

void TString8::Copy ( const TCHAR * src,
TINT size = -1 )

Definition at line 76 of file TString8.cpp.

77{
78 if ( src != m_pBuffer )
79 {
80 TINT srcLen = src ? TINT( TStringManager::String8Length( src ) ) : 0;
81 TASSERT( srcLen <= 0xFFFFFF, "Too big string" );
82
83 if ( srcLen < size || size == -1 )
84 {
85 size = srcLen;
86 }
87
88 AllocBuffer( size, TTRUE );
89 TUtil::MemCopy( m_pBuffer, src, size );
90
91 m_pBuffer[ size ] = 0;
92 }
93}
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90

◆ Copy() [2/4]

void TString8::Copy ( const TString16 & src,
TINT size = -1 )

Definition at line 64 of file TString8.cpp.

65{
66 TINT srcLen = src.Length();
67 TASSERT( srcLen <= 0xFFFFFF, "Too big string" );
68
69 if ( srcLen < size || size == -1 ) { size = srcLen; }
70
71 AllocBuffer( size, TTRUE );
72 TStringManager::StringUnicodeToChar( m_pBuffer, src, size );
73 m_pBuffer[ size ] = 0;
74}
TINT Length() const
Definition TString16.h:73

◆ Copy() [3/4]

void TString8::Copy ( const TString8 & src,
TINT size = -1 )
inline

Definition at line 32 of file TString8.h.

32{ Copy( src.m_pBuffer, size ); }

◆ Copy() [4/4]

void TString8::Copy ( const TWCHAR * src,
TINT size = -1 )

Definition at line 95 of file TString8.cpp.

96{
97 TINT srcLen = TINT( TStringManager::String16Length( src ) );
98 TASSERT( srcLen <= 0xFFFFFF, "Too big string" );
99
100 if ( srcLen < size || size == -1 ) { size = srcLen; }
101
102 AllocBuffer( size, TTRUE );
103 TStringManager::StringUnicodeToChar( m_pBuffer, src, size );
104 m_pBuffer[ size ] = 0;
105}
static TSIZE String16Length(const TWCHAR *str)

◆ EndsWith()

TBOOL TString8::EndsWith ( const TCHAR * a_szString,
TINT a_iLength = -1 ) const

Definition at line 485 of file TString8.cpp.

486{
487 TINT iStringLength = ( a_iLength != -1 ) ? a_iLength : T2String8::Length( a_szString );
488
489 if ( Length() < iStringLength )
490 return TFALSE;
491
492 return strncmp( GetString( Length() - iStringLength ), a_szString, iStringLength ) == 0;
493}

◆ EndsWithNoCase()

TBOOL TString8::EndsWithNoCase ( const TCHAR * a_szString,
TINT a_iLength = -1 ) const

Definition at line 505 of file TString8.cpp.

506{
507 TINT iStringLength = ( a_iLength != -1 ) ? a_iLength : T2String8::Length( a_szString );
508
509 if ( Length() < iStringLength )
510 return TFALSE;
511
512 return strnicmp( GetString( Length() - iStringLength ), a_szString, iStringLength ) == 0;
513}

◆ ExcessLength()

TUINT16 TString8::ExcessLength ( ) const
inline

Definition at line 94 of file TString8.h.

94{ return m_iExcessLen; }

◆ Find() [1/2]

TINT TString8::Find ( const TCHAR * substr,
TINT pos = 0 ) const

Definition at line 117 of file TString8.cpp.

118{
119 if ( !IsIndexValid( pos ) ) return -1;
120
121 const TCHAR* foundAt = strstr( GetString( pos ), substr );
122 if ( foundAt == TNULL ) return -1;
123
124 return (TINT)( foundAt - m_pBuffer );
125}

◆ Find() [2/2]

TINT TString8::Find ( TCHAR character,
TINT pos = 0 ) const

Definition at line 107 of file TString8.cpp.

108{
109 if ( !IsIndexValid( pos ) ) return -1;
110
111 const TCHAR* foundAt = strchr( &m_pBuffer[ pos ], character );
112 if ( foundAt == TNULL ) return -1;
113
114 return (TINT)( foundAt - m_pBuffer );
115}

◆ FindReverse()

TINT TString8::FindReverse ( TCHAR a_findChar,
TINT pos = -1 ) const

Definition at line 234 of file TString8.cpp.

235{
236 if ( pos == -1 )
237 {
238 pos = m_iStrLen;
239 }
240 else
241 {
242 if ( !IsIndexValid( pos ) ) return -1;
243 }
244
245
246 for ( ; pos > -1; pos-- )
247 {
248 if ( a_findChar == m_pBuffer[ pos ] )
249 {
250 return pos;
251 }
252 }
253
254 return -1;
255}

◆ ForceSetData()

void TString8::ForceSetData ( TCHAR * a_pchString,
TINT a_iLength )

Definition at line 218 of file TString8.cpp.

219{
220 m_pBuffer = a_cString;
221
222 if ( a_iLength < 0 )
223 {
224 m_iStrLen = TINT( TStringManager::String8Length( a_cString ) );
225 }
226 else
227 {
228 m_iStrLen = a_iLength;
229 }
230
231 m_iExcessLen = 0;
232}

◆ Format()

TString8 & TString8::Format ( const TCHAR * a_pcFormat,
... )

Definition at line 176 of file TString8.cpp.

177{
178 va_list args;
179 va_start( args, a_pcFormat );
180 // TASSERT is only in T2String8
181
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" );
185 Copy( buffer, -1 );
186
187 return *this;
188}

◆ FreeBuffer()

void TString8::FreeBuffer ( )

Definition at line 280 of file TString8.cpp.

281{
282 if ( Length() != 0 ) m_pAllocator->Free( m_pBuffer );
283 Reset();
284}

◆ GetString()

const TCHAR * TString8::GetString ( TINT a_iIndex = 0) const

Definition at line 286 of file TString8.cpp.

287{
288 TASSERT( a_iIndex >= 0 && a_iIndex <= (TINT)m_iStrLen );
289 if ( IsIndexValid( a_iIndex ) ) { return &m_pBuffer[ a_iIndex ]; }
290 return TNULL;
291}

◆ GetStringUnsafe()

TCHAR * TString8::GetStringUnsafe ( TINT a_iIndex = 0)

Definition at line 293 of file TString8.cpp.

294{
295 TASSERT( a_iIndex >= 0 && a_iIndex <= (TINT)m_iStrLen );
296 if ( IsIndexValid( a_iIndex ) ) { return &m_pBuffer[ a_iIndex ]; }
297 return TNULL;
298}

◆ IsAllLowerCase()

TBOOL TString8::IsAllLowerCase ( ) const

Definition at line 449 of file TString8.cpp.

450{
451 TCHAR* pChar = m_pBuffer;
452
453 while ( pChar < m_pBuffer + m_iStrLen )
454 {
455 TCHAR cChar = *pChar++;
456 if ( cChar >= 'A' && cChar <= 'Z' ) return TFALSE;
457 }
458
459 return TTRUE;
460}

◆ IsAllUpperCase()

TBOOL TString8::IsAllUpperCase ( ) const

Definition at line 462 of file TString8.cpp.

463{
464 TCHAR* pChar = m_pBuffer;
465
466 while ( pChar < m_pBuffer + m_iStrLen )
467 {
468 TCHAR cChar = *pChar++;
469 if ( cChar >= 'a' && cChar <= 'z' ) return TFALSE;
470 }
471
472 return TTRUE;
473}

◆ IsEmpty()

TBOOL TString8::IsEmpty ( ) const
inline

Definition at line 104 of file TString8.h.

104{ return m_iStrLen == 0; }

◆ IsIndexValid()

TBOOL TString8::IsIndexValid ( TINT a_iIndex) const
inline

Definition at line 103 of file TString8.h.

103{ return a_iIndex >= 0 && a_iIndex <= Length(); }

◆ IsUnicode()

TBOOL TString8::IsUnicode ( ) const
inline

Definition at line 105 of file TString8.h.

105{ return TFALSE; } // Who would have known?

◆ Length()

TINT TString8::Length ( ) const
inline

Definition at line 93 of file TString8.h.

93{ return m_iStrLen; }

◆ MakeLower()

TString8 & TString8::MakeLower ( )
inline

Definition at line 87 of file TString8.h.

88 {
89 _strlwr( m_pBuffer );
90 return *this;
91 }

◆ MakeUpper()

TString8 & TString8::MakeUpper ( )
inline

Definition at line 81 of file TString8.h.

82 {
83 _strupr( m_pBuffer );
84 return *this;
85 }

◆ Mid()

TString8 TString8::Mid ( TINT a_iFirst,
TINT a_iCount ) const

Definition at line 386 of file TString8.cpp.

387{
388 if ( a_iFirst < 0 )
389 {
390 a_iFirst = 0;
391 }
392 else if ( Length() <= a_iFirst )
393 {
394 // Can't return string bigger that the original
395 return TString8();
396 }
397
398 if ( a_iCount < 0 || Length() < a_iFirst + a_iCount )
399 {
400 a_iCount = Length() - a_iFirst;
401 }
402
403 TString8 strResult( a_iCount, TNULL );
404 TUtil::MemCopy( strResult.GetStringUnsafe(), GetString( a_iFirst ), a_iCount );
405 strResult[ a_iCount ] = '\0';
406
407 return strResult;
408}

◆ operator const TBOOL()

TString8::operator const TBOOL ( ) const
inline

Definition at line 130 of file TString8.h.

130{ return !IsEmpty(); }
TBOOL IsEmpty() const
Definition TString8.h:104

◆ operator const TCHAR *()

TString8::operator const TCHAR * ( ) const
inline

Definition at line 129 of file TString8.h.

129{ return m_pBuffer; }

◆ operator!()

TBOOL TString8::operator! ( )
inline

Definition at line 132 of file TString8.h.

132{ return m_iStrLen == 0; }

◆ operator!=() [1/2]

TBOOL TString8::operator!= ( const TCHAR * cstr) const
inline

Definition at line 135 of file TString8.h.

135{ return Compare( cstr, -1 ) != 0; }
TINT Compare(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:362

◆ operator!=() [2/2]

TBOOL TString8::operator!= ( const TString8 & str) const
inline

Definition at line 136 of file TString8.h.

136{ return Compare( str.m_pBuffer, -1 ) != 0; }

◆ operator+()

TString8 TString8::operator+ ( const TCHAR * cstr) const
inline

Definition at line 108 of file TString8.h.

109 {
110 TString8 str = TString8( *this );
111 return std::move( str.Concat( cstr ) );
112 }

◆ operator+=() [1/2]

TString8 * TString8::operator+= ( const TCHAR * cstr)
inline

Definition at line 114 of file TString8.h.

115 {
116 Concat( cstr, -1 );
117 return this;
118 }

◆ operator+=() [2/2]

TString8 * TString8::operator+= ( TString8 & str)
inline

Definition at line 120 of file TString8.h.

121 {
122 Concat( str, -1 );
123 return this;
124 }

◆ operator<() [1/2]

TBOOL TString8::operator< ( const TCHAR * cstr) const
inline

Definition at line 137 of file TString8.h.

137{ return Compare( cstr, -1 ) > -1; }

◆ operator<() [2/2]

TBOOL TString8::operator< ( const TString8 & str) const
inline

Definition at line 138 of file TString8.h.

138{ return Compare( str.m_pBuffer, -1 ) > -1; }

◆ operator<=() [1/2]

TBOOL TString8::operator<= ( const TCHAR * cstr) const
inline

Definition at line 139 of file TString8.h.

139{ return Compare( cstr, -1 ) > 0; }

◆ operator<=() [2/2]

TBOOL TString8::operator<= ( const TString8 & str) const
inline

Definition at line 140 of file TString8.h.

140{ return Compare( str.m_pBuffer, -1 ) > 0; }

◆ operator=() [1/5]

TString8 & TString8::operator= ( const TCHAR * cstr)
inline

Definition at line 142 of file TString8.h.

143 {
144 Copy( cstr, -1 );
145 return *this;
146 }

◆ operator=() [2/5]

TString8 & TString8::operator= ( const TString16 & str)
inline

Definition at line 172 of file TString8.h.

173 {
174 Copy( str, -1 );
175 return *this;
176 }

◆ operator=() [3/5]

TString8 & TString8::operator= ( const TString8 & str)
inline

Definition at line 154 of file TString8.h.

155 {
156 Copy( str, -1 );
157 return *this;
158 }

◆ operator=() [4/5]

TString8 & TString8::operator= ( const TWCHAR * wcstr)
inline

Definition at line 148 of file TString8.h.

149 {
150 Copy( wcstr, -1 );
151 return *this;
152 }

◆ operator=() [5/5]

TString8 & TString8::operator= ( TString8 && str)
inline

Definition at line 160 of file TString8.h.

161 {
162 FreeBuffer();
163 m_pBuffer = str.m_pBuffer;
164 m_iExcessLen = str.m_iExcessLen;
165 m_iStrLen = str.m_iStrLen;
166 m_pAllocator = str.m_pAllocator;
167
168 str.Reset();
169 return *this;
170 }

◆ operator==() [1/2]

TBOOL TString8::operator== ( const TCHAR * cstr) const
inline

Definition at line 133 of file TString8.h.

133{ return Compare( cstr, -1 ) == 0; }

◆ operator==() [2/2]

TBOOL TString8::operator== ( const TString8 & str) const
inline

Definition at line 134 of file TString8.h.

134{ return Compare( str.m_pBuffer, -1 ) == 0; }

◆ operator[]() [1/2]

TCHAR & TString8::operator[] ( TINT a_iIndex)
inline

Definition at line 126 of file TString8.h.

126{ return m_pBuffer[ a_iIndex ]; }

◆ operator[]() [2/2]

const TCHAR & TString8::operator[] ( TINT a_iIndex) const
inline

Definition at line 127 of file TString8.h.

127{ return *GetString( a_iIndex ); }

◆ Reserve()

TString8 & TString8::Reserve ( TINT size)

Definition at line 334 of file TString8.cpp.

335{
336 if ( size > Length() + TINT( ExcessLength() ) )
337 {
338 TINT iOldLength = m_iStrLen;
339 TCHAR* pOldString = m_pBuffer;
340 TINT iCopySize = TMath::Min( iOldLength, size );
341
342 // Reallocate buffer if necessary
343 TBOOL bAllocated = AllocBuffer( size, TFALSE );
344
345 // Update excess length
346 TASSERT( iCopySize <= size );
347 AllocBuffer( iCopySize, TFALSE );
348
349 if ( bAllocated )
350 {
351 TStringManager::String8Copy( m_pBuffer, pOldString, iCopySize );
352 m_pBuffer[ iCopySize ] = 0;
353 }
354
355 if ( bAllocated && iOldLength != 0 )
356 m_pAllocator->Free( pOldString );
357 }
358
359 return *this;
360}
TFORCEINLINE const T & Min(const T &a, const T &b)
TUINT16 ExcessLength() const
Definition TString8.h:94

◆ Right()

TString8 TString8::Right ( TINT a_iFrom) const

Definition at line 410 of file TString8.cpp.

411{
412 return Mid( a_iFrom, Length() - a_iFrom );
413}
TString8 Mid(TINT a_iFirst, TINT a_iCount) const
Definition TString8.cpp:386

◆ StartsWith()

TBOOL TString8::StartsWith ( const TCHAR * a_szString,
TINT a_iLength = -1 ) const

Definition at line 475 of file TString8.cpp.

476{
477 TINT iStringLength = ( a_iLength != -1 ) ? a_iLength : T2String8::Length( a_szString );
478
479 if ( Length() < iStringLength )
480 return TFALSE;
481
482 return Compare( a_szString, iStringLength ) == 0;
483}

◆ StartsWithNoCase()

TBOOL TString8::StartsWithNoCase ( const TCHAR * a_szString,
TINT a_iLength = -1 ) const

Definition at line 495 of file TString8.cpp.

496{
497 TINT iStringLength = ( a_iLength != -1 ) ? a_iLength : T2String8::Length( a_szString );
498
499 if ( Length() < iStringLength )
500 return TFALSE;
501
502 return CompareNoCase( a_szString, iStringLength ) == 0;
503}
TINT CompareNoCase(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:374

◆ Truncate()

void TString8::Truncate ( TINT length)

Definition at line 257 of file TString8.cpp.

258{
259 if ( Length() < length )
260 {
261 length = Length();
262 }
263
264 TCHAR* oldBuffer = m_pBuffer;
265
266 TBOOL allocated = AllocBuffer( length, TFALSE );
267 if ( allocated )
268 {
269 TStringManager::String8Copy( m_pBuffer, oldBuffer, length );
270 }
271
272 m_pBuffer[ length ] = 0;
273
274 if ( allocated && Length() != 0 )
275 {
276 m_pAllocator->Free( oldBuffer );
277 }
278}

◆ UndoForceSetData()

void TString8::UndoForceSetData ( )
inline

Definition at line 47 of file TString8.h.

47{ Reset(); }

◆ VarArgs()

TString8 TString8::VarArgs ( const TCHAR * a_pcFormat,
... )
static

Definition at line 202 of file TString8.cpp.

203{
204 TCHAR buffer[ 0x400 ];
205 TString8 buffer2;
206 va_list args;
207
208 va_start( args, a_pcFormat );
209
210 // TASSERT is only in T2String8
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 );
214
215 return buffer2;
216}

◆ VFormat()

TString8 & TString8::VFormat ( const TCHAR * a_pcFormat,
va_list a_vargs )

Definition at line 190 of file TString8.cpp.

191{
192 TCHAR buffer[ 0x400 ];
193
194 // TASSERT is only in T2String8
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" );
197 Copy( buffer, -1 );
198
199 return *this;
200}

The documentation for this class was generated from the following files: