OpenBarnyard
 
Loading...
Searching...
No Matches
TString8.h
Go to the documentation of this file.
1
11
12#pragma once
13#include "TString.h"
14#include "T2Allocator.h"
15
17
18class TString16;
19
21{
22public:
23 TString8();
24 TString8( T2Allocator* allocator );
25 TString8( TString8&& src ) noexcept;
26 TString8( const TString8& src, T2Allocator* allocator = TNULL );
27 TString8( const TString16& src, T2Allocator* allocator = TNULL );
28 TString8( const TCHAR* src, T2Allocator* allocator = TNULL );
29 TString8( TINT size, T2Allocator* allocator = TNULL );
31
32 void Copy( const TString8& src, TINT size = -1 ) { Copy( src.m_pBuffer, size ); }
33 void Copy( const TString16& src, TINT size = -1 );
34 void Copy( const TCHAR* src, TINT size = -1 );
35 void Copy( const TWCHAR* src, TINT size = -1 );
36
37 void FreeBuffer();
38
39 // Returns TTRUE if allocated memory
40 TBOOL AllocBuffer( TINT a_iLength, TBOOL a_bFreeMemory = TTRUE );
41
42 TString8& Format( const TCHAR* a_pcFormat, ... );
43 TString8& VFormat( const TCHAR* a_pcFormat, va_list a_vargs );
44
45 static TString8 VarArgs( const TCHAR* a_pcFormat, ... );
46
47 void UndoForceSetData() { Reset(); }
48 void ForceSetData( TCHAR* a_pchString, TINT a_iLength );
49
50 TINT FindReverse( TCHAR a_findChar, TINT pos = -1 ) const;
51
52 void Truncate( TINT length );
53
54 // Returns position of specified character
55 TINT Find( TCHAR character, TINT pos = 0 ) const;
56
57 // Returns position of specified substring
58 TINT Find( const TCHAR* substr, TINT pos = 0 ) const;
59
60 // Returns const string starting from specified a_iIndex
61 const TCHAR* GetString( TINT a_iIndex = 0 ) const;
62
63 // Returns string starting from specified a_iIndex. Use only if you are sure about what you do!
64 TCHAR* GetStringUnsafe( TINT a_iIndex = 0 );
65
66 TString8& Concat( const TString8& str, TINT size = -1 ) { return Concat( str.m_pBuffer, size ); };
67 TString8& Concat( const TString16& src, TINT size = -1 );
68 TString8& Concat( const TCHAR* src, TINT size = -1 );
69
70 TString8& Reserve( TINT size );
71
72 TINT Compare( const TCHAR* a_szString, TINT a_iLength = -1 ) const;
73 TINT CompareNoCase( const TCHAR* a_szString, TINT a_iLength = -1 ) const;
74
75 // Returns a substring contained in a [a_iFirst; a_iFirst + a_iCount] range
76 TString8 Mid( TINT a_iFirst, TINT a_iCount ) const;
77
78 // Returns a substring contained in a [a_iFrom; end of the string] range
79 TString8 Right( TINT a_iFrom ) const;
80
82 {
83 _strupr( m_pBuffer );
84 return *this;
85 }
86
88 {
89 _strlwr( m_pBuffer );
90 return *this;
91 }
92
93 TINT Length() const { return m_iStrLen; }
94 TUINT16 ExcessLength() const { return m_iExcessLen; }
95
96 TBOOL StartsWith( const TCHAR* a_szString, TINT a_iLength = -1 ) const;
97 TBOOL EndsWith( const TCHAR* a_szString, TINT a_iLength = -1 ) const;
98 TBOOL StartsWithNoCase( const TCHAR* a_szString, TINT a_iLength = -1 ) const;
99 TBOOL EndsWithNoCase( const TCHAR* a_szString, TINT a_iLength = -1 ) const;
100
101 TBOOL IsAllLowerCase() const;
102 TBOOL IsAllUpperCase() const;
103 TBOOL IsIndexValid( TINT a_iIndex ) const { return a_iIndex >= 0 && a_iIndex <= Length(); }
104 TBOOL IsEmpty() const { return m_iStrLen == 0; }
105 TBOOL IsUnicode() const { return TFALSE; } // Who would have known?
106
107public:
108 TString8 operator+( const TCHAR* cstr ) const
109 {
110 TString8 str = TString8( *this );
111 return std::move( str.Concat( cstr ) );
112 }
113
114 TString8* operator+=( const TCHAR* cstr )
115 {
116 Concat( cstr, -1 );
117 return this;
118 }
119
121 {
122 Concat( str, -1 );
123 return this;
124 }
125
126 TCHAR& operator[]( TINT a_iIndex ) { return m_pBuffer[ a_iIndex ]; }
127 const TCHAR& operator[]( TINT a_iIndex ) const { return *GetString( a_iIndex ); }
128
129 operator const TCHAR*() const { return m_pBuffer; }
130 operator const TBOOL() const { return !IsEmpty(); }
131
132 TBOOL operator!() { return m_iStrLen == 0; }
133 TBOOL operator==( const TCHAR* cstr ) const { return Compare( cstr, -1 ) == 0; }
134 TBOOL operator==( const TString8& str ) const { return Compare( str.m_pBuffer, -1 ) == 0; }
135 TBOOL operator!=( const TCHAR* cstr ) const { return Compare( cstr, -1 ) != 0; }
136 TBOOL operator!=( const TString8& str ) const { return Compare( str.m_pBuffer, -1 ) != 0; }
137 TBOOL operator<( const TCHAR* cstr ) const { return Compare( cstr, -1 ) > -1; }
138 TBOOL operator<( const TString8& str ) const { return Compare( str.m_pBuffer, -1 ) > -1; }
139 TBOOL operator<=( const TCHAR* cstr ) const { return Compare( cstr, -1 ) > 0; }
140 TBOOL operator<=( const TString8& str ) const { return Compare( str.m_pBuffer, -1 ) > 0; }
141
142 TString8& operator=( const TCHAR* cstr )
143 {
144 Copy( cstr, -1 );
145 return *this;
146 }
147
148 TString8& operator=( const TWCHAR* wcstr )
149 {
150 Copy( wcstr, -1 );
151 return *this;
152 }
153
155 {
156 Copy( str, -1 );
157 return *this;
158 }
159
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 }
171
173 {
174 Copy( str, -1 );
175 return *this;
176 }
177
178private:
179 typedef T2Allocator* ( *func_DefaultAllocatorCB )();
180
181 void Reset()
182 {
183 m_pBuffer = NullString;
184 m_iStrLen = 0;
185 m_iExcessLen = 0;
186 }
187
188 T2Allocator* GetAllocator()
189 {
190 return sm_pDefaultAllocatorCB();
191 }
192
193 static T2Allocator* GetDefaultAllocatorCB()
194 {
195 return GetGlobalAllocator();
196 }
197
198private:
199 static inline func_DefaultAllocatorCB sm_pDefaultAllocatorCB = &GetDefaultAllocatorCB;
200
201private:
202 TCHAR* m_pBuffer; // 0x0
203 TUINT32 m_iExcessLen : 8; // 0x4
204 TINT32 m_iStrLen : 24; // 0x5
205 T2Allocator* m_pAllocator; // 0x8
206};
207
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
TFORCEINLINE T2Allocator * GetGlobalAllocator()
Definition T2Allocator.h:49
uint16_t TUINT16
Definition Typedefs.h:15
int32_t TINT32
Definition Typedefs.h:12
wchar_t TWCHAR
Definition Typedefs.h:21
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
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
TString8 Mid(TINT a_iFirst, TINT a_iCount) const
Definition TString8.cpp:386
TCHAR & operator[](TINT a_iIndex)
Definition TString8.h:126
TBOOL EndsWithNoCase(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:505
TBOOL operator<(const TCHAR *cstr) const
Definition TString8.h:137
TString8 & MakeLower()
Definition TString8.h:87
TString8 & Format(const TCHAR *a_pcFormat,...)
Definition TString8.cpp:176
TString8 * operator+=(TString8 &str)
Definition TString8.h:120
TBOOL EndsWith(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:485
TString8 & Concat(const TString8 &str, TINT size=-1)
Definition TString8.h:66
TString8 & operator=(const TWCHAR *wcstr)
Definition TString8.h:148
TINT Compare(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:362
TBOOL operator==(const TString8 &str) const
Definition TString8.h:134
TCHAR * GetStringUnsafe(TINT a_iIndex=0)
Definition TString8.cpp:293
const TCHAR & operator[](TINT a_iIndex) const
Definition TString8.h:127
TINT Find(TCHAR character, TINT pos=0) const
Definition TString8.cpp:107
TBOOL operator!=(const TString8 &str) const
Definition TString8.h:136
TString8 & operator=(const TCHAR *cstr)
Definition TString8.h:142
TBOOL operator!=(const TCHAR *cstr) const
Definition TString8.h:135
TBOOL IsAllLowerCase() const
Definition TString8.cpp:449
TBOOL AllocBuffer(TINT a_iLength, TBOOL a_bFreeMemory=true)
Definition TString8.cpp:127
TBOOL operator==(const TCHAR *cstr) const
Definition TString8.h:133
TBOOL operator!()
Definition TString8.h:132
TBOOL IsAllUpperCase() const
Definition TString8.cpp:462
TString8 * operator+=(const TCHAR *cstr)
Definition TString8.h:114
TBOOL IsEmpty() const
Definition TString8.h:104
~TString8()
Definition TString8.h:30
TINT CompareNoCase(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:374
TString8 & operator=(const TString8 &str)
Definition TString8.h:154
TINT FindReverse(TCHAR a_findChar, TINT pos=-1) const
Definition TString8.cpp:234
static TString8 VarArgs(const TCHAR *a_pcFormat,...)
Definition TString8.cpp:202
TBOOL IsIndexValid(TINT a_iIndex) const
Definition TString8.h:103
TBOOL StartsWith(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:475
TBOOL StartsWithNoCase(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:495
TBOOL operator<=(const TCHAR *cstr) const
Definition TString8.h:139
void UndoForceSetData()
Definition TString8.h:47
TString8 & MakeUpper()
Definition TString8.h:81
TString8 & VFormat(const TCHAR *a_pcFormat, va_list a_vargs)
Definition TString8.cpp:190
void ForceSetData(TCHAR *a_pchString, TINT a_iLength)
Definition TString8.cpp:218
void Truncate(TINT length)
Definition TString8.cpp:257
void FreeBuffer()
Definition TString8.cpp:280
TINT Length() const
Definition TString8.h:93
void Copy(const TString8 &src, TINT size=-1)
Definition TString8.h:32
TUINT16 ExcessLength() const
Definition TString8.h:94
TString8 & Reserve(TINT size)
Definition TString8.cpp:334
const TCHAR * GetString(TINT a_iIndex=0) const
Definition TString8.cpp:286
TString8 Right(TINT a_iFrom) const
Definition TString8.cpp:410
TString8 & operator=(const TString16 &str)
Definition TString8.h:172
TBOOL operator<(const TString8 &str) const
Definition TString8.h:138
TString8 & operator=(TString8 &&str)
Definition TString8.h:160
TString8 operator+(const TCHAR *cstr) const
Definition TString8.h:108
TBOOL IsUnicode() const
Definition TString8.h:105
TBOOL operator<=(const TString8 &str) const
Definition TString8.h:140