OpenBarnyard
 
Loading...
Searching...
No Matches
TString16.h
Go to the documentation of this file.
1#pragma once
2#include "TString.h"
3#include "T2Allocator.h"
4
6
8{
9public:
10 TString16();
11 TString16( T2Allocator* allocator );
12 TString16( TString16&& src ) noexcept;
13 TString16( const TString16& src, T2Allocator* allocator = TNULL );
14 TString16( const TWCHAR* src, T2Allocator* allocator = TNULL );
15 TString16( TINT size, T2Allocator* allocator = TNULL );
17
18 void Copy( const TString16& src, TINT size = -1 ) { Copy( src.m_pBuffer, size ); }
19 void Copy( const TWCHAR* src, TINT size = -1 );
20
21 void FreeBuffer();
22
23 // Returns TTRUE if allocated memory
24 TBOOL AllocBuffer( TINT size, TBOOL freeMemory = TTRUE );
25
26 static TString16 Format( const TWCHAR* a_pcFormat, ... );
27 TString16& VFormat( const TWCHAR* a_pcFormat, va_list a_vargs );
28
29 void ForceSetData( TWCHAR* a_cString, TINT a_ilength );
30 void UndoForceSetData() { Reset(); }
31
32 TINT FindReverse( TWCHAR a_findChar, TINT pos = -1 ) const;
33
34 void Truncate( TINT length );
35
36 // Returns position of specified character
37 TINT Find( TWCHAR character, TINT pos = 0 ) const;
38
39 // Returns position of specified substring
40 TINT Find( const TWCHAR* substr, TINT pos = 0 ) const;
41
42 // Returns string starting from specified index
43 const TWCHAR* GetString( TINT index = 0 ) const;
44
45 // Returns string starting from specified a_iIndex. Use only if you are sure about what you do!
46 TWCHAR* GetStringUnsafe( TINT a_iIndex = 0 );
47
48 TString16& Concat( const TString16& str, TINT size = -1 ) { return Concat( str.m_pBuffer, size ); };
49 TString16& Concat( const TWCHAR* src, TINT size = -1 );
50
51 TString16& Reserve( TINT size );
52
53 TINT Compare( const TWCHAR* a_wszString, TINT a_iLength = -1 ) const;
54 TINT CompareNoCase( const TWCHAR* a_wszString, TINT a_iLength = -1 ) const;
55
56 // Returns a substring contained in a [a_iFirst; a_iFirst + a_iCount] range
57 TString16 Mid( TINT a_iFirst, TINT a_iCount ) const;
58
59 // Returns a substring contained in a [a_iFrom; end of the string] range
60 TString16 Right( TINT a_iFrom ) const;
61
63 {
64 _wcsupr( m_pBuffer );
65 return *this;
66 }
68 {
69 _wcslwr( m_pBuffer );
70 return *this;
71 }
72
73 TINT Length() const { return m_iStrLen; }
74 TUINT16 ExcessLength() const { return m_iExcessLen; }
75
76 TBOOL IsAllLowerCase() const;
77 TBOOL IsAllUpperCase() const;
78 TBOOL IsIndexValid( TINT index ) const { return index >= 0 && index <= Length(); }
79 TBOOL IsEmpty() const { return m_iStrLen == 0; }
80 TBOOL IsUnicode() const { return TFALSE; } // Who would have known?
81
82public:
83 TString16 operator+( TWCHAR const* a_wszStr ) const
84 {
85 TString16 str = TString16( *this );
86 return std::move( str.Concat( a_wszStr ) );
87 }
88
89 TString16* operator+=( TWCHAR const* a_wszStr )
90 {
91 Concat( a_wszStr, -1 );
92 return this;
93 }
94
96 {
97 Concat( str, -1 );
98 return this;
99 }
100
101 TWCHAR& operator[]( TINT index ) { return m_pBuffer[ index ]; }
102 const TWCHAR& operator[]( TINT index ) const { return *GetString( index ); }
103 operator const TWCHAR*() const { return m_pBuffer; }
104
105 TBOOL operator!() { return m_iStrLen == 0; }
106 TBOOL operator==( const TWCHAR* a_wszStr ) const { return Compare( a_wszStr, -1 ) == 0; }
107 TBOOL operator==( const TString16& str ) const { return Compare( str.m_pBuffer, -1 ) == 0; }
108 TBOOL operator!=( const TWCHAR* a_wszStr ) const { return Compare( a_wszStr, -1 ) != 0; }
109 TBOOL operator!=( const TString16& str ) const { return Compare( str.m_pBuffer, -1 ) != 0; }
110 TBOOL operator<( const TWCHAR* a_wszStr ) const { return Compare( a_wszStr, -1 ) > -1; };
111 TBOOL operator<( const TString16& str ) const { return Compare( str.m_pBuffer, -1 ) > -1; };
112 TBOOL operator<=( const TWCHAR* a_wszStr ) const { return Compare( a_wszStr, -1 ) > 0; };
113 TBOOL operator<=( const TString16& str ) const { return Compare( str.m_pBuffer, -1 ) > 0; };
114
115 TString16& operator=( const TWCHAR* a_wszStr )
116 {
117 Copy( a_wszStr, -1 );
118 return *this;
119 }
120
122 {
123 Copy( str, -1 );
124 return *this;
125 }
126
128 {
129 FreeBuffer();
130 m_pBuffer = str.m_pBuffer;
131 m_iExcessLen = str.m_iExcessLen;
132 m_iStrLen = str.m_iStrLen;
133 m_pAllocator = str.m_pAllocator;
134
135 str.Reset();
136 return *this;
137 }
138
139private:
140 typedef T2Allocator* ( *func_DefaultAllocatorCB )();
141
142 void Reset()
143 {
144 m_pBuffer = NullWString;
145 m_iStrLen = 0;
146 m_iExcessLen = 0;
147 }
148
149 T2Allocator* GetAllocator()
150 {
151 return sm_pDefaultAllocatorCB();
152 }
153
154 static T2Allocator* GetDefaultAllocatorCB()
155 {
156 return GetGlobalAllocator();
157 }
158
159private:
160 static inline func_DefaultAllocatorCB sm_pDefaultAllocatorCB = &GetDefaultAllocatorCB;
161
162private:
163 TWCHAR* m_pBuffer; // 0x0
164 TUINT32 m_iExcessLen : 8; // 0x4
165 TINT32 m_iStrLen : 24; // 0x5
166 T2Allocator* m_pAllocator; // 0x8
167};
168
#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
#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
TWCHAR & operator[](TINT index)
Definition TString16.h:101
TString16 & Concat(const TString16 &str, TINT size=-1)
Definition TString16.h:48
TBOOL operator<(const TString16 &str) const
Definition TString16.h:111
void UndoForceSetData()
Definition TString16.h:30
void Copy(const TString16 &src, TINT size=-1)
Definition TString16.h:18
TString16 Mid(TINT a_iFirst, TINT a_iCount) const
TBOOL operator!()
Definition TString16.h:105
TBOOL IsEmpty() const
Definition TString16.h:79
TString16 & MakeLower()
Definition TString16.h:67
TBOOL AllocBuffer(TINT size, TBOOL freeMemory=true)
Definition TString16.cpp:95
TBOOL operator==(const TWCHAR *a_wszStr) const
Definition TString16.h:106
TString16 Right(TINT a_iFrom) const
TINT Find(TWCHAR character, TINT pos=0) const
Definition TString16.cpp:75
TString16 & Reserve(TINT size)
TBOOL IsAllLowerCase() const
TBOOL operator==(const TString16 &str) const
Definition TString16.h:107
TString16 operator+(TWCHAR const *a_wszStr) const
Definition TString16.h:83
TUINT16 ExcessLength() const
Definition TString16.h:74
TString16 & operator=(TString16 &&str)
Definition TString16.h:127
TBOOL IsUnicode() const
Definition TString16.h:80
const TWCHAR & operator[](TINT index) const
Definition TString16.h:102
TString16 & MakeUpper()
Definition TString16.h:62
TWCHAR * GetStringUnsafe(TINT a_iIndex=0)
TINT CompareNoCase(const TWCHAR *a_wszString, TINT a_iLength=-1) const
void ForceSetData(TWCHAR *a_cString, TINT a_ilength)
TString16 & VFormat(const TWCHAR *a_pcFormat, va_list a_vargs)
TBOOL operator<=(const TWCHAR *a_wszStr) const
Definition TString16.h:112
TINT Length() const
Definition TString16.h:73
TString16 & operator=(const TString16 &str)
Definition TString16.h:121
const TWCHAR * GetString(TINT index=0) const
TINT Compare(const TWCHAR *a_wszString, TINT a_iLength=-1) const
static TString16 Format(const TWCHAR *a_pcFormat,...)
TBOOL operator<=(const TString16 &str) const
Definition TString16.h:113
TString16 * operator+=(TString16 &str)
Definition TString16.h:95
void Truncate(TINT length)
TBOOL IsIndexValid(TINT index) const
Definition TString16.h:78
TString16 & operator=(const TWCHAR *a_wszStr)
Definition TString16.h:115
TString16 * operator+=(TWCHAR const *a_wszStr)
Definition TString16.h:89
TBOOL operator<(const TWCHAR *a_wszStr) const
Definition TString16.h:110
void FreeBuffer()
TBOOL operator!=(const TString16 &str) const
Definition TString16.h:109
TBOOL IsAllUpperCase() const
TBOOL operator!=(const TWCHAR *a_wszStr) const
Definition TString16.h:108
TINT FindReverse(TWCHAR a_findChar, TINT pos=-1) const