ReactOS 0.4.15-dev-7924-g5949c20
CHString Class Reference

#include <chstring.h>

Inheritance diagram for CHString:

Public Member Functions

 CHString ()
 
 CHString (CHSTRING_WCHAR ch, int nRepeat=1)
 
 CHString (CHSTRING_LPCWSTR lpsz)
 
 CHString (CHSTRING_LPCWSTR lpch, int nLength)
 
 CHString (LPCSTR lpsz)
 
 CHString (const CHString &stringSrc)
 
 CHString (const unsigned char *lpsz)
 
 ~CHString ()
 
CHSTRING_LPWSTR AllocSysString () const
 
int Collate (CHSTRING_LPCWSTR lpsz) const
 
int Collate (const wchar_t *lpsz) const
 
int Compare (CHSTRING_LPCWSTR lpsz) const
 
int Compare (const wchar_t *lpsz) const
 
int CompareNoCase (CHSTRING_LPCWSTR lpsz) const
 
int CompareNoCase (const wchar_t *lpsz) const
 
void Empty ()
 
int Find (CHSTRING_WCHAR ch) const
 
int Find (CHSTRING_LPCWSTR lpszSub) const
 
int Find (const wchar_t *lpszSub) const
 
int FindOneOf (CHSTRING_LPCWSTR lpszCharSet) const
 
int FindOneOf (const wchar_t *lpszCharSet) const
 
void Format (UINT nFormatID,...)
 
void Format (CHSTRING_LPCWSTR lpszFormat,...)
 
template<typename ... Params>
void Format (const wchar_t *lpszFormat, Params &&... params)
 
void FormatMessageW (UINT nFormatID,...)
 
void FormatMessageW (CHSTRING_LPCWSTR lpszFormat,...)
 
template<typename ... Params>
void FormatMessageW (const wchar_t *lpszFormat, Params &&... params)
 
void FormatV (CHSTRING_LPCWSTR lpszFormat, va_list argList)
 
void FormatV (const wchar_t *lpszFormat, va_list argList)
 
void FreeExtra ()
 
int GetAllocLength () const
 
CHSTRING_WCHAR GetAt (int nIndex) const
 
CHSTRING_LPWSTR GetBuffer (int nMinBufLength)
 
CHSTRING_LPWSTR GetBufferSetLength (int nNewLength)
 
int GetLength () const
 
BOOL IsEmpty () const
 
CHString Left (int nCount) const
 
int LoadStringW (UINT nID)
 
CHSTRING_LPWSTR LockBuffer ()
 
void MakeLower ()
 
void MakeReverse ()
 
void MakeUpper ()
 
CHString Mid (int nFirst) const
 
CHString Mid (int nFirst, int nCount) const
 
void ReleaseBuffer (int nNewLength=-1)
 
int ReverseFind (CHSTRING_WCHAR ch) const
 
CHString Right (int nCount) const
 
void SetAt (int nIndex, CHSTRING_WCHAR ch)
 
CHString SpanExcluding (CHSTRING_LPCWSTR lpszCharSet) const
 
CHString SpanExcluding (const wchar_t *lpszCharSet) const
 
CHString SpanIncluding (CHSTRING_LPCWSTR lpszCharSet) const
 
CHString SpanIncluding (const wchar_t *lpszCharSet) const
 
void TrimLeft ()
 
void TrimRight ()
 
void UnlockBuffer ()
 
const CHStringoperator= (char ch)
 
const CHStringoperator= (CHSTRING_WCHAR ch)
 
const CHStringoperator= (CHString *p)
 
const CHStringoperator= (LPCSTR lpsz)
 
const CHStringoperator= (CHSTRING_LPCWSTR lpsz)
 
const CHStringoperator= (const CHString &stringSrc)
 
const CHStringoperator= (const unsigned char *lpsz)
 
const CHStringoperator+= (char ch)
 
const CHStringoperator+= (CHSTRING_WCHAR ch)
 
const CHStringoperator+= (CHSTRING_LPCWSTR lpsz)
 
const CHStringoperator+= (const CHString &string)
 
CHSTRING_WCHAR operator[] (int nIndex) const
 
 operator CHSTRING_LPCWSTR () const
 

Protected Member Functions

void AllocBeforeWrite (int nLen)
 
void AllocBuffer (int nLen)
 
void AllocCopy (CHString &dest, int nCopyLen, int nCopyIndex, int nExtraLen) const
 
void AssignCopy (int nSrcLen, CHSTRING_LPCWSTR lpszSrcData)
 
void AssignCopy (int nSrcLen, const wchar_t *lpszSrcData)
 
void ConcatCopy (int nSrc1Len, CHSTRING_LPCWSTR lpszSrc1Data, int nSrc2Len, CHSTRING_LPCWSTR lpszSrc2Data)
 
void ConcatCopy (int nSrc1Len, const wchar_t *lpszSrc1Data, int nSrc2Len, const wchar_t *lpszSrc2Data)
 
void ConcatInPlace (int nSrcLen, CHSTRING_LPCWSTR lpszSrcData)
 
void ConcatInPlace (int nSrcLen, const wchar_t *lpszSrcData)
 
void CopyBeforeWrite ()
 
CHStringDataGetData () const
 
void Init ()
 
int LoadStringW (UINT nID, CHSTRING_LPWSTR lpszBuf, UINT nMaxBuf)
 
void Release ()
 

Static Protected Member Functions

static void WINAPI Release (CHStringData *pData)
 
static int WINAPI SafeStrlen (CHSTRING_LPCWSTR lpsz)
 
static int WINAPI SafeStrlen (const wchar_t *lpsz)
 

Protected Attributes

CHSTRING_LPWSTR m_pchData
 

Friends

CHString WINAPI operator+ (CHSTRING_WCHAR ch, const CHString &string)
 
CHString WINAPI operator+ (const CHString &string, CHSTRING_WCHAR ch)
 
CHString WINAPI operator+ (const CHString &string, CHSTRING_LPCWSTR lpsz)
 
CHString WINAPI operator+ (CHSTRING_LPCWSTR lpsz, const CHString &string)
 
CHString WINAPI operator+ (const CHString &string1, const CHString &string2)
 

Detailed Description

Definition at line 31 of file chstring.h.

Constructor & Destructor Documentation

◆ CHString() [1/7]

CHString::CHString ( )

Definition at line 103 of file chstring.cpp.

104{
105 // Set to empty string
107}
CHSTRING_WCHAR afxPchNil[1]
Definition: chstring.cpp:39
CHSTRING_LPWSTR m_pchData
Definition: chstring.h:147

◆ CHString() [2/7]

CHString::CHString ( CHSTRING_WCHAR  ch,
int  nRepeat = 1 
)

Definition at line 112 of file chstring.cpp.

113{
114 // Allow null initialize, in case something goes wrong
116
117 // If we have a char to insert
118 if (nRepeat >= 1)
119 {
120 // Allocate a buffer big enough
121 AllocBuffer(nRepeat);
122 // And if possible, repeat char
123 if (m_pchData)
124 {
125 for (int i = 0; i < nRepeat; ++i)
126 {
127 m_pchData[i] = ch;
128 }
129 }
130 }
131}
void AllocBuffer(int nLen)
Definition: chstring.cpp:275
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

◆ CHString() [3/7]

CHString::CHString ( CHSTRING_LPCWSTR  lpsz)

Definition at line 136 of file chstring.cpp.

137{
138 // Allow null initialize, in case something goes wrong
140
141 // If we have an input string
142 if (lpsz != 0)
143 {
144 // Get its length
145 int Len = SafeStrlen(lpsz);
146 // Then, allocate a big enough buffer and copy string
147 // Note that here, we don't null terminate the string...
148 if (Len)
149 {
151 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData),
152 reinterpret_cast<LPCWSTR>(lpsz),
153 Len);
154 }
155 }
156}
static int WINAPI SafeStrlen(CHSTRING_LPCWSTR lpsz)
Definition: chstring.cpp:1042
#define Len
Definition: deflate.h:82
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

◆ CHString() [4/7]

CHString::CHString ( CHSTRING_LPCWSTR  lpch,
int  nLength 
)

Definition at line 161 of file chstring.cpp.

162{
163 // Allow null initialize, in case something goes wrong
165
166 // In case we have a string with a len
167 if (lpch != 0 && nLength != 0)
168 {
169 // Just copy the string
171 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData),
172 reinterpret_cast<LPCWSTR>(lpch),
173 nLength);
174 }
175}
_In_ DWORD nLength
Definition: wincon.h:473

◆ CHString() [5/7]

CHString::CHString ( LPCSTR  lpsz)

Definition at line 180 of file chstring.cpp.

181{
182 // Allow null initialize, in case something goes wrong
184
185 // If we have input string
186 if (lpsz != 0)
187 {
188 // Get its length
189 int Len = (int)strlen(lpsz);
190 if (Len)
191 {
192 // Allocate and convert the string
194 mbstowcsz(reinterpret_cast<LPWSTR>(m_pchData), lpsz, Len + 1);
195 // Releasing buffer here is to allow to
196 // update the buffer size. We notify we're
197 // done with changing the string: recompute its
198 // length, please
200 }
201 }
202}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int mbstowcsz(LPWSTR lpDest, LPCSTR lpSrc, int nLen)
Definition: chstring.cpp:77
void ReleaseBuffer(int nNewLength=-1)
Definition: chstring.cpp:980
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ CHString() [6/7]

CHString::CHString ( const CHString stringSrc)

Definition at line 218 of file chstring.cpp.

219{
220 // If we have currently no referenced string
221 if (stringSrc.GetData()->nRefs < 0)
222 {
223 // Ensure we have the null string
225 // And then call, the copy operator with input string
226 *this = stringSrc.m_pchData;
227 }
228 else
229 {
230 // Otherwise, just copy the input string
231 m_pchData = stringSrc.m_pchData;
232 // And increment the number of references
233 InterlockedIncrement(&GetData()->nRefs);
234 // The whole point here is: Am I forget to release the old
235 // data?! MS doesn't release it, but I guess we should...
236 }
237}
#define InterlockedIncrement
Definition: armddk.h:53
CHStringData * GetData() const
Definition: chstring.cpp:766
long nRefs
Definition: chstring.h:21

◆ CHString() [7/7]

CHString::CHString ( const unsigned char lpsz)

Definition at line 207 of file chstring.cpp.

208{
209 // Null init
210 Init();
211 // And call operator= with const char*, easier
212 *this = (LPCSTR)lpsz;
213}
void Init()
Definition: chstring.cpp:789
const char * LPCSTR
Definition: xmlstorage.h:183

◆ ~CHString()

CHString::~CHString ( )

Definition at line 242 of file chstring.cpp.

243{
244 // If we have a string
245 if (GetData() != &afxNullData)
246 {
247 // Check whether it's still in use after we release it
248 if (InterlockedDecrement(&GetData()->nRefs) == 0)
249 {
250 // If so, delete it
251 delete GetData();
252 }
253 }
254}
#define InterlockedDecrement
Definition: armddk.h:52
CHStringData afxNullData
Definition: chstring.cpp:41

Member Function Documentation

◆ AllocBeforeWrite()

void CHString::AllocBeforeWrite ( int  nLen)
protected

Definition at line 259 of file chstring.cpp.

260{
261 // In case we have several strings pointing to our memory zone
262 // Or we need bigger buffer than actual
263 if (GetData()->nRefs > 1 || nLen > GetData()->nAllocLength)
264 {
265 // Just drop current
266 // And allocate a new one which is big enough
267 Release();
268 AllocBuffer(nLen);
269 }
270}
void Release()
Definition: chstring.cpp:940

Referenced by AssignCopy(), operator=(), and CHString2::UseStuff().

◆ AllocBuffer()

void CHString::AllocBuffer ( int  nLen)
protected

Definition at line 275 of file chstring.cpp.

276{
277 // Here we have to allocate a buffer for the string
278 // It actually consists in: CHStringData structure
279 // with a buffer big enough at its end to store the
280 // string.
282
283 // Null size is easy allocation
284 if (nSize == 0)
285 {
287 return;
288 }
289
290 // We cannot allow negative sizes
291 if (nSize < 0)
292 {
294 }
295
296 // Nor too big
297 if (nSize > (INT_MAX - (int)sizeof(CHStringData)) / (int)sizeof(WCHAR))
298 {
300 }
301
302 // Just allocate big enough buffer, using our own operator new
303 Data = (CHStringData *)operator new(nSize * sizeof(WCHAR) + sizeof(CHStringData));
304 // In case Data is null, throw an exception
305 // Yes, this is stupid! Our operator new is already supposed to through an exception...
306 // Thanks MS
307 if (!Data)
308 {
309 throw HeapException;
310 }
311
312 Data->nRefs = 1;
313 Data->nDataLength = nSize;
314 Data->nAllocLength = nSize;
315 Data->data()[0] = 0;
316
317 // We only return the string
318 // We can find back data with some mathematics
319 m_pchData = Data->data();
320}
CHeap_Exception HeapException(CHeap_Exception::E_ALLOCATION_ERROR)
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
VOID WINAPI RaiseException(_In_ DWORD dwExceptionCode, _In_ DWORD dwExceptionFlags, _In_ DWORD nNumberOfArguments, _In_opt_ const ULONG_PTR *lpArguments)
Definition: except.c:700
#define INT_MAX
Definition: limits.h:40
#define STATUS_INTEGER_OVERFLOW
Definition: ntstatus.h:385
#define EXCEPTION_NONCONTINUABLE
Definition: stubs.h:23
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2084
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by AllocBeforeWrite(), CHString(), ConcatCopy(), CopyBeforeWrite(), FreeExtra(), GetBuffer(), and CHString2::UseStuff().

◆ AllocCopy()

void CHString::AllocCopy ( CHString dest,
int  nCopyLen,
int  nCopyIndex,
int  nExtraLen 
) const
protected

Definition at line 325 of file chstring.cpp.

326{
327 // Once again, we cannot deal with negative lens
328 if (nCopyLen < 0)
329 {
331 }
332
333 if (nCopyIndex < 0)
334 {
336 }
337
338 if (nExtraLen < 0)
339 {
341 }
342
343 // In case what we have to copy is null-sized, just set empty string
344 if (nCopyLen + nExtraLen == 0)
345 {
346 dest.m_pchData = afxPchNil;
347 return;
348 }
349
350 // Otherwise, allocate a buffer in new string which is big enough
351 // You can note that we absolutely don't check about any existing
352 // (referenced) buffer in dest. Actually, dest is to be EMPTY string.
353 // The whole point of this function is to initialize a virgin string by
354 // copying data from another. This is needed by Left/Mid/Right
355 dest.AllocBuffer(nCopyLen + nExtraLen);
356 // And copy our stuff in
357 wcsncpy(reinterpret_cast<LPWSTR>(dest.m_pchData),
358 reinterpret_cast<LPWSTR>(m_pchData + nCopyIndex),
359 nCopyLen);
360}
static char * dest
Definition: rtl.c:135

Referenced by Left(), Mid(), Right(), and CHString2::UseStuff().

◆ AllocSysString()

CHSTRING_LPWSTR CHString::AllocSysString ( ) const

Definition at line 365 of file chstring.cpp.

366{
367 BSTR SysString;
368
369 // Just allocate the string
370 SysString = SysAllocStringLen(reinterpret_cast<LPWSTR>(m_pchData), GetData()->nDataLength);
371 if (!SysString)
372 {
373 throw HeapException;
374 }
375
376 return reinterpret_cast<CHSTRING_LPWSTR>(SysString);
377}
CHSTRING_WCHAR * CHSTRING_LPWSTR
Definition: chstring.h:15
OLECHAR * BSTR
Definition: compat.h:2293
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339

Referenced by CHString2::UseStuff().

◆ AssignCopy() [1/2]

void CHString::AssignCopy ( int  nSrcLen,
CHSTRING_LPCWSTR  lpszSrcData 
)
protected

Definition at line 382 of file chstring.cpp.

383{
384 // Don't allow negative len
385 if (nSrcLen < 0)
386 {
388 }
389
390 // We will have to modify a string that might be shared, so duplicate it
391 // Ensuring it's big enough to contain our new stuff
392 AllocBeforeWrite(nSrcLen);
393 if (nSrcLen == 0)
394 {
395 Release();
396 return;
397 }
398
399 // Just copy, write down new size, and ensure it's null terminated
400 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData),
401 reinterpret_cast<LPCWSTR>(lpszSrcData), nSrcLen);
402 GetData()->nDataLength = nSrcLen;
403 m_pchData[nSrcLen] = 0;
404}
void AllocBeforeWrite(int nLen)
Definition: chstring.cpp:259
int nDataLength
Definition: chstring.h:22

Referenced by AssignCopy(), operator=(), and CHString2::UseStuff().

◆ AssignCopy() [2/2]

void CHString::AssignCopy ( int  nSrcLen,
const wchar_t lpszSrcData 
)
inlineprotected

Definition at line 153 of file chstring.h.

154 {
155 AssignCopy(nSrcLen, reinterpret_cast<CHSTRING_LPCWSTR>(lpszSrcData));
156 }
const CHSTRING_WCHAR * CHSTRING_LPCWSTR
Definition: chstring.h:14
void AssignCopy(int nSrcLen, CHSTRING_LPCWSTR lpszSrcData)
Definition: chstring.cpp:382

◆ Collate() [1/2]

int CHString::Collate ( CHSTRING_LPCWSTR  lpsz) const

Definition at line 409 of file chstring.cpp.

410{
411 // Just call the deprecated function here - no matter we are null terminated
412 // Did you read my statement about how safe is this implementation?
413 return wcscoll(reinterpret_cast<LPCWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(lpsz));
414}
_Check_return_ _CRTIMP int __cdecl wcscoll(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by Collate(), and CHString2::UseStuff().

◆ Collate() [2/2]

int CHString::Collate ( const wchar_t lpsz) const
inline

Definition at line 45 of file chstring.h.

46 {
47 return Collate(reinterpret_cast<CHSTRING_LPCWSTR>(lpsz));
48 }
int Collate(CHSTRING_LPCWSTR lpsz) const
Definition: chstring.cpp:409

◆ Compare() [1/2]

int CHString::Compare ( CHSTRING_LPCWSTR  lpsz) const

Definition at line 419 of file chstring.cpp.

420{
421 // Just call the deprecated function here - no matter we are null terminated
422 // Did you read my statement about how safe is this implementation?
423 return wcscmp(reinterpret_cast<LPCWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(lpsz));
424}
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by Compare(), and CHString2::UseStuff().

◆ Compare() [2/2]

int CHString::Compare ( const wchar_t lpsz) const
inline

Definition at line 50 of file chstring.h.

51 {
52 return Compare(reinterpret_cast<CHSTRING_LPCWSTR>(lpsz));
53 }
int Compare(CHSTRING_LPCWSTR lpsz) const
Definition: chstring.cpp:419

◆ CompareNoCase() [1/2]

int CHString::CompareNoCase ( CHSTRING_LPCWSTR  lpsz) const

Definition at line 429 of file chstring.cpp.

430{
431 // Just call the deprecated function here - no matter we are null terminated
432 // Did you read my statement about how safe is this implementation?
433 return wcsicmp(reinterpret_cast<LPCWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(lpsz));
434}
#define wcsicmp
Definition: compat.h:15

Referenced by CompareNoCase(), and CHString2::UseStuff().

◆ CompareNoCase() [2/2]

int CHString::CompareNoCase ( const wchar_t lpsz) const
inline

Definition at line 55 of file chstring.h.

56 {
57 return CompareNoCase(reinterpret_cast<CHSTRING_LPCWSTR>(lpsz));
58 }
int CompareNoCase(CHSTRING_LPCWSTR lpsz) const
Definition: chstring.cpp:429

◆ ConcatCopy() [1/2]

void CHString::ConcatCopy ( int  nSrc1Len,
CHSTRING_LPCWSTR  lpszSrc1Data,
int  nSrc2Len,
CHSTRING_LPCWSTR  lpszSrc2Data 
)
protected

Definition at line 490 of file chstring.cpp.

493{
494 int TotalLen;
495
496 if (nSrc1Len < 0 || nSrc2Len < 0)
497 {
499 }
500
501 // If both len are null, do nothing
502 TotalLen = nSrc1Len + nSrc2Len;
503 if (TotalLen == 0)
504 {
505 return;
506 }
507
508 // Otherwise, allocate a new buffer to hold everything (caller will release previous buffer)
509 AllocBuffer(TotalLen);
510 // And concat stuff
511 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData),
512 reinterpret_cast<LPCWSTR>(lpszSrc1Data),
513 nSrc1Len);
514 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData + nSrc1Len),
515 reinterpret_cast<LPCWSTR>(lpszSrc2Data),
516 nSrc2Len);
517}

Referenced by ConcatCopy(), ConcatInPlace(), and CHString2::UseStuff().

◆ ConcatCopy() [2/2]

void CHString::ConcatCopy ( int  nSrc1Len,
const wchar_t lpszSrc1Data,
int  nSrc2Len,
const wchar_t lpszSrc2Data 
)
inlineprotected

Definition at line 158 of file chstring.h.

159 {
160 ConcatCopy(nSrc1Len, reinterpret_cast<CHSTRING_LPCWSTR>(lpszSrc1Data), nSrc2Len, reinterpret_cast<CHSTRING_LPCWSTR>(lpszSrc2Data));
161 }
void ConcatCopy(int nSrc1Len, CHSTRING_LPCWSTR lpszSrc1Data, int nSrc2Len, CHSTRING_LPCWSTR lpszSrc2Data)
Definition: chstring.cpp:490

◆ ConcatInPlace() [1/2]

void CHString::ConcatInPlace ( int  nSrcLen,
CHSTRING_LPCWSTR  lpszSrcData 
)
protected

Definition at line 439 of file chstring.cpp.

440{
441 // With null length, there's not that much to concat...
442 if (nSrcLen == 0)
443 {
444 return;
445 }
446
447 // Still no negative length
448 if (nSrcLen < 0)
449 {
451 }
452
453 // Ensure we wouldn't overflow with the concat
454 if (GetData()->nDataLength > INT_MAX - nSrcLen)
455 {
457 }
458
459 // In case we have to modify a shared string OR if it can't fit into current buffer...
460 if (GetData()->nRefs > 1 || GetData()->nDataLength + nSrcLen > GetData()->nAllocLength)
461 {
462 // Allocate a new buffer! (without forgetting to release old one)
463 CHStringData* OldData = GetData();
464
465 // You remember about "InPlace" in the function's name?
466 // The cake is a lie
467 ConcatCopy(GetData()->nDataLength, m_pchData, nSrcLen, lpszSrcData);
468 Release(OldData);
469 }
470 else
471 {
472 // Ensure we don't overflow
473 if (nSrcLen > INT_MAX - GetData()->nDataLength)
474 {
476 }
477
478 // Then, just copy and null terminate
479 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData + GetData()->nDataLength),
480 reinterpret_cast<LPCWSTR>(lpszSrcData),
481 nSrcLen);
482 GetData()->nDataLength += nSrcLen;
484 }
485}

Referenced by ConcatInPlace(), operator+=(), and CHString2::UseStuff().

◆ ConcatInPlace() [2/2]

void CHString::ConcatInPlace ( int  nSrcLen,
const wchar_t lpszSrcData 
)
inlineprotected

Definition at line 163 of file chstring.h.

164 {
165 ConcatInPlace(nSrcLen, reinterpret_cast<CHSTRING_LPCWSTR>(lpszSrcData));
166 }
void ConcatInPlace(int nSrcLen, CHSTRING_LPCWSTR lpszSrcData)
Definition: chstring.cpp:439

◆ CopyBeforeWrite()

void CHString::CopyBeforeWrite ( )
protected

Definition at line 522 of file chstring.cpp.

523{
525
526 // First, we need to get reference count
527 // And we also need to save Data for later copy
528 Data = GetData();
529
530 if (Data->nRefs <= 1)
531 {
532 // If its not used, don't waste time to realloc, it will do the job
533 return;
534 }
535
536 // Release current data - we are sure it won't be freed upon that point
537 // Thanks to the reference count check previously done
538 Release();
539 // Alloc new buffer and copy old data in it
540 AllocBuffer(Data->nDataLength);
541 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData),
542 reinterpret_cast<LPCWSTR>(Data->data()),
543 Data->nDataLength);
544}

Referenced by MakeLower(), MakeReverse(), MakeUpper(), ReleaseBuffer(), SetAt(), TrimLeft(), TrimRight(), and CHString2::UseStuff().

◆ Empty()

void CHString::Empty ( )

Definition at line 549 of file chstring.cpp.

550{
551 // Already empty
552 if (GetData()->nDataLength == 0)
553 {
554 return;
555 }
556
557 // Empty it easily given it's reference count
558 if (GetData()->nRefs < 0)
559 {
560 *this = afxPchNil;
561 }
562 else
563 {
564 // Otherwise, just release it
565 // It will set back this instance to afxPchNil
566 // while decreasing reference count
567 Release();
568 }
569}

Referenced by CHString2::UseStuff().

◆ Find() [1/3]

int CHString::Find ( CHSTRING_LPCWSTR  lpszSub) const

Definition at line 593 of file chstring.cpp.

594{
596
597 // Let's use appropriate helper
598 Found = reinterpret_cast<CHSTRING_LPCWSTR>(wcsstr(reinterpret_cast<LPCWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(lpszSub)));
599 // We have to return a position, so compute it
600 if (Found)
601 {
602 return (Found - m_pchData);
603 }
604
605 // Otherwise, return no position
606 return -1;
607}
return Found
Definition: dirsup.c:1270
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)

◆ Find() [2/3]

int CHString::Find ( CHSTRING_WCHAR  ch) const

Definition at line 574 of file chstring.cpp.

575{
577
578 // Let's use appropriate helper
579 Found = reinterpret_cast<CHSTRING_LPCWSTR>(wcschr(reinterpret_cast<LPCWSTR>(m_pchData), ch));
580 // We have to return a position, so compute it
581 if (Found)
582 {
583 return (Found - m_pchData);
584 }
585
586 // Otherwise, return no position
587 return -1;
588}
#define wcschr
Definition: compat.h:17

Referenced by CHString2::UseStuff().

◆ Find() [3/3]

int CHString::Find ( const wchar_t lpszSub) const
inline

Definition at line 62 of file chstring.h.

63 {
64 return FindOneOf(reinterpret_cast<CHSTRING_LPCWSTR>(lpszSub));
65 }
int FindOneOf(CHSTRING_LPCWSTR lpszCharSet) const
Definition: chstring.cpp:612

◆ FindOneOf() [1/2]

int CHString::FindOneOf ( CHSTRING_LPCWSTR  lpszCharSet) const

Definition at line 612 of file chstring.cpp.

613{
615
616 // Let's use appropriate helper
617 Found = reinterpret_cast<CHSTRING_LPCWSTR>(wcspbrk(reinterpret_cast<LPCWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(lpszCharSet)));
618 // We have to return a position, so compute it
619 if (Found)
620 {
621 return (Found - m_pchData);
622 }
623
624 // Otherwise, return no position
625 return -1;
626}
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcspbrk(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)

Referenced by Find(), FindOneOf(), and CHString2::UseStuff().

◆ FindOneOf() [2/2]

int CHString::FindOneOf ( const wchar_t lpszCharSet) const
inline

Definition at line 67 of file chstring.h.

68 {
69 return FindOneOf(reinterpret_cast<CHSTRING_LPCWSTR>(lpszCharSet));
70 }

◆ Format() [1/3]

void CHString::Format ( CHSTRING_LPCWSTR  lpszFormat,
  ... 
)

Definition at line 640 of file chstring.cpp.

641{
642 // Forward to FormatV
643 va_list ArgsList;
644
645 va_start(ArgsList, lpszFormat);
646 FormatV(lpszFormat, ArgsList);
647 va_end(ArgsList);
648}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
void FormatV(CHSTRING_LPCWSTR lpszFormat, va_list argList)
Definition: chstring.cpp:670

◆ Format() [2/3]

template<typename ... Params>
void CHString::Format ( const wchar_t lpszFormat,
Params &&...  params 
)
inline

Definition at line 74 of file chstring.h.

75 {
76 Format(reinterpret_cast<CHSTRING_LPCWSTR>(lpszFormat), params...);
77 }
GLenum const GLfloat * params
Definition: glext.h:5645

◆ Format() [3/3]

void CHString::Format ( UINT  nFormatID,
  ... 
)

Definition at line 631 of file chstring.cpp.

632{
633 // Deprecated and not implemented any longer - well, this is its implementation
634 return;
635}

◆ FormatMessageW() [1/3]

void CHString::FormatMessageW ( CHSTRING_LPCWSTR  lpszFormat,
  ... 
)

Definition at line 662 of file chstring.cpp.

663{
665}
#define UNIMPLEMENTED
Definition: debug.h:115

◆ FormatMessageW() [2/3]

template<typename ... Params>
void CHString::FormatMessageW ( const wchar_t lpszFormat,
Params &&...  params 
)
inline

Definition at line 81 of file chstring.h.

82 {
83 FormatMessageW(reinterpret_cast<CHSTRING_LPCWSTR>(lpszFormat), params...);
84 }
void FormatMessageW(UINT nFormatID,...)
Definition: chstring.cpp:653

◆ FormatMessageW() [3/3]

void CHString::FormatMessageW ( UINT  nFormatID,
  ... 
)

Definition at line 653 of file chstring.cpp.

654{
655 // Deprecated and not implemented any longer - well, this is its implementation
656 return;
657}

Referenced by FormatMessageW(), and CHString2::UseStuff().

◆ FormatV() [1/2]

void CHString::FormatV ( CHSTRING_LPCWSTR  lpszFormat,
va_list  argList 
)

Definition at line 670 of file chstring.cpp.

671{
673}

Referenced by Format(), FormatV(), and CHString2::UseStuff().

◆ FormatV() [2/2]

void CHString::FormatV ( const wchar_t lpszFormat,
va_list  argList 
)
inline

Definition at line 86 of file chstring.h.

87 {
88 return FormatV(reinterpret_cast<CHSTRING_LPCWSTR>(lpszFormat), argList);
89 }

◆ FreeExtra()

void CHString::FreeExtra ( )

Definition at line 678 of file chstring.cpp.

679{
680 CHStringData* OldData;
681
682 // No extra? Do nothing
683 if (GetData()->nDataLength == GetData()->nAllocLength)
684 {
685 return;
686 }
687
688 // Get old buffer
689 OldData = GetData();
690 // Allocate a new one, at the right size (with no place for \0 :-))
691 AllocBuffer(GetData()->nDataLength);
692 // Copy old and release it
693 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(OldData->data()), OldData->nDataLength);
694 Release(OldData);
695}
CHSTRING_WCHAR * data()
Definition: chstring.h:25

Referenced by CHString2::UseStuff().

◆ GetAllocLength()

int CHString::GetAllocLength ( ) const

Definition at line 700 of file chstring.cpp.

701{
702 return GetData()->nAllocLength;
703}
int nAllocLength
Definition: chstring.h:23

Referenced by CHString2::UseStuff().

◆ GetAt()

CHSTRING_WCHAR CHString::GetAt ( int  nIndex) const

Definition at line 708 of file chstring.cpp.

709{
710 // It's up to you to check the index!
711 return m_pchData[nIndex];
712}

Referenced by CHString2::UseStuff().

◆ GetBuffer()

CHSTRING_LPWSTR CHString::GetBuffer ( int  nMinBufLength)

Definition at line 717 of file chstring.cpp.

718{
719 CHSTRING_LPWSTR OldBuffer = m_pchData;
720
721 // We'll have to allocate a new buffer if it's not big enough
722 // or if it's shared by several strings
723 if (GetData()->nRefs > 1 || GetData()->nAllocLength < nMinBufLength)
724 {
725 CHStringData* OldData = GetData();
726 int OldLen = GetData()->nDataLength;
727
728 // Ensure we can hold enough
729 if (OldLen > nMinBufLength)
730 {
731 nMinBufLength = OldLen;
732 }
733
734 // Allocate new buffer
735 AllocBuffer(nMinBufLength);
736 // Copy contents
737 wcsncpy(reinterpret_cast<LPWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(OldBuffer), OldLen);
738 GetData()->nDataLength = OldLen;
739
740 // Release old
741 Release(OldData);
742 }
743
744 // Weirdly, here Windows always returns the old buffer
745 // Which basically exposes a wrong buffer
746 return OldBuffer;
747}

◆ GetBufferSetLength()

CHSTRING_LPWSTR CHString::GetBufferSetLength ( int  nNewLength)

Definition at line 752 of file chstring.cpp.

753{
754 // Get a buffer big enough
755 // We don't care about the return, it will be set in the string
756 (void)GetBuffer(nNewLength);
757 // Set length, null-terminate and return
758 GetData()->nDataLength = nNewLength;
759 m_pchData[nNewLength] = 0;
760 return m_pchData;
761}
return pMemory GetBuffer()

Referenced by CHString2::UseStuff().

◆ GetData()

CHStringData * CHString::GetData ( ) const
protected

Definition at line 766 of file chstring.cpp.

767{
768 // In case of empty string, return empty data
769 if (m_pchData == afxPchNil)
770 {
771 return &afxNullData;
772 }
773
774 // Otherwise, do maths
775 return (CHStringData*)((ULONG_PTR)m_pchData - sizeof(CHStringData));
776}
#define ULONG_PTR
Definition: config.h:101

Referenced by AllocBeforeWrite(), AllocSysString(), AssignCopy(), CHString(), ConcatInPlace(), CopyBeforeWrite(), Empty(), FreeExtra(), GetAllocLength(), GetBuffer(), GetBufferSetLength(), GetLength(), IsEmpty(), Left(), LockBuffer(), Mid(), operator+=(), operator=(), Release(), ReleaseBuffer(), Right(), TrimLeft(), TrimRight(), UnlockBuffer(), CHString2::UseStuff(), and ~CHString().

◆ GetLength()

int CHString::GetLength ( ) const

Definition at line 781 of file chstring.cpp.

782{
783 return GetData()->nDataLength;
784}

Referenced by CHString2::UseStuff().

◆ Init()

void CHString::Init ( )
protected

Definition at line 789 of file chstring.cpp.

790{
792}

Referenced by CHString(), and CHString2::UseStuff().

◆ IsEmpty()

BOOL CHString::IsEmpty ( ) const

Definition at line 797 of file chstring.cpp.

798{
799 return (GetData()->nDataLength == 0);
800}

Referenced by CHString2::UseStuff().

◆ Left()

CHString CHString::Left ( int  nCount) const

Definition at line 805 of file chstring.cpp.

806{
807 CHString NewString;
808
809 // Validate input (we can't get more than what we have ;-))
810 if (nCount)
811 {
812 if (nCount > GetData()->nDataLength)
813 {
814 nCount = GetData()->nDataLength;
815 }
816 }
817
818 AllocCopy(NewString, nCount, 0, 0);
819
820 return NewString;
821}
void AllocCopy(CHString &dest, int nCopyLen, int nCopyIndex, int nExtraLen) const
Definition: chstring.cpp:325

Referenced by SpanExcluding(), SpanIncluding(), and CHString2::UseStuff().

◆ LoadStringW() [1/2]

int CHString::LoadStringW ( UINT  nID)

Definition at line 826 of file chstring.cpp.

827{
828 // Deprecated and not implemented any longer - well, this is its implementation
829 return 0;
830}

Referenced by CHString2::UseStuff().

◆ LoadStringW() [2/2]

int CHString::LoadStringW ( UINT  nID,
CHSTRING_LPWSTR  lpszBuf,
UINT  nMaxBuf 
)
protected

Definition at line 835 of file chstring.cpp.

836{
837 // Deprecated and not implemented any longer - well, this is its implementation
838 return 0;
839}

◆ LockBuffer()

CHSTRING_LPWSTR CHString::LockBuffer ( )

Definition at line 844 of file chstring.cpp.

845{
846 CHSTRING_LPWSTR LockedBuffer;
847
848 // The purpose here is basically to set the nRefs to max int
849 LockedBuffer = GetBuffer(0);
850 GetData()->nRefs = INT_MAX;
851
852 return LockedBuffer;
853}

Referenced by CHString2::UseStuff().

◆ MakeLower()

void CHString::MakeLower ( )

Definition at line 858 of file chstring.cpp.

859{
860 // We'll modify string, duplicate it first if needed
862
863 // Let's use appropriate helper
864 _wcslwr(reinterpret_cast<LPWSTR>(m_pchData));
865}
void CopyBeforeWrite()
Definition: chstring.cpp:522
_CRTIMP wchar_t *__cdecl _wcslwr(_Inout_z_ wchar_t *_String)

Referenced by CHString2::UseStuff().

◆ MakeReverse()

void CHString::MakeReverse ( )

Definition at line 870 of file chstring.cpp.

871{
872 // We'll modify string, duplicate it first if needed
874
875 // Let's use appropriate helper
876 _wcsrev(reinterpret_cast<LPWSTR>(m_pchData));
877}
_CRTIMP wchar_t *__cdecl _wcsrev(_Inout_z_ wchar_t *_Str)

Referenced by CHString2::UseStuff().

◆ MakeUpper()

void CHString::MakeUpper ( )

Definition at line 882 of file chstring.cpp.

883{
884 // We'll modify string, duplicate it first if needed
886
887 // Let's use appropriate helper
888 _wcsupr(reinterpret_cast<LPWSTR>(m_pchData));
889}
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)

Referenced by CHString2::UseStuff().

◆ Mid() [1/2]

CHString CHString::Mid ( int  nFirst) const

Definition at line 894 of file chstring.cpp.

895{
896 // Take string from nFirst up to the end
897 return Mid(nFirst, GetData()->nDataLength - nFirst);
898}
CHString Mid(int nFirst) const
Definition: chstring.cpp:894

Referenced by Mid(), and CHString2::UseStuff().

◆ Mid() [2/2]

CHString CHString::Mid ( int  nFirst,
int  nCount 
) const

Definition at line 903 of file chstring.cpp.

904{
905 CHString NewString;
906
907 // Validate sizes first
908 if (nFirst < 0)
909 {
910 nFirst = 0;
911 }
912
913 if (nCount < 0)
914 {
915 nCount = 0;
916 }
917
918 // Ensure we don't go beyond the string
919 if (nFirst + nCount > GetData()->nDataLength)
920 {
921 nCount = GetData()->nDataLength - nFirst;
922 }
923
924 // Also ensure we don't read beyond
925 // Yes, this should have been done before previous check
926 // MS does it that way
927 if (nFirst > GetData()->nDataLength)
928 {
929 nCount = 0;
930 }
931
932 AllocCopy(NewString, nCount, nFirst, 0);
933
934 return NewString;
935}

◆ operator CHSTRING_LPCWSTR()

CHString::operator CHSTRING_LPCWSTR ( ) const

Definition at line 1348 of file chstring.cpp.

1349{
1350 return m_pchData;
1351}

◆ operator+=() [1/4]

const CHString & CHString::operator+= ( char  ch)

Definition at line 1299 of file chstring.cpp.

1300{
1301 *this += (CHSTRING_WCHAR)ch;
1302 return *this;
1303}
unsigned short CHSTRING_WCHAR
Definition: chstring.h:13

◆ operator+=() [2/4]

const CHString & CHString::operator+= ( CHSTRING_LPCWSTR  lpsz)

Definition at line 1317 of file chstring.cpp.

1318{
1319 int Len;
1320
1321 Len = SafeStrlen(lpsz);
1322 ConcatInPlace(Len, lpsz);
1323
1324 return *this;
1325}

◆ operator+=() [3/4]

const CHString & CHString::operator+= ( CHSTRING_WCHAR  ch)

Definition at line 1308 of file chstring.cpp.

1309{
1310 ConcatInPlace(1, &ch);
1311 return *this;
1312}

◆ operator+=() [4/4]

const CHString & CHString::operator+= ( const CHString string)

Definition at line 1330 of file chstring.cpp.

1331{
1332 ConcatInPlace(string.GetData()->nDataLength, string.m_pchData);
1333
1334 return *this;
1335}

◆ operator=() [1/7]

const CHString & CHString::operator= ( char  ch)

Definition at line 1187 of file chstring.cpp.

1188{
1189 *this = (CHSTRING_WCHAR)ch;
1190 return *this;
1191}

◆ operator=() [2/7]

const CHString & CHString::operator= ( CHString p)

Definition at line 1205 of file chstring.cpp.

1206{
1207 *this = *p;
1208 return *this;
1209}
GLfloat GLfloat p
Definition: glext.h:8902

◆ operator=() [3/7]

const CHString & CHString::operator= ( CHSTRING_LPCWSTR  lpsz)

Definition at line 1247 of file chstring.cpp.

1248{
1249 int Len;
1250
1251 Len = SafeStrlen(lpsz);
1252 AssignCopy(Len, lpsz);
1253
1254 return *this;
1255}

◆ operator=() [4/7]

const CHString & CHString::operator= ( CHSTRING_WCHAR  ch)

Definition at line 1196 of file chstring.cpp.

1197{
1198 AssignCopy(1, &ch);
1199 return *this;
1200}

◆ operator=() [5/7]

const CHString & CHString::operator= ( const CHString stringSrc)

Definition at line 1260 of file chstring.cpp.

1261{
1262 // Don't copy string on itself
1263 if (&stringSrc == this)
1264 {
1265 return *this;
1266 }
1267
1268 // In case we don't have a referenced string here,
1269 // or if the other is not referenced, just copy here
1270 if ((GetData()->nRefs < 0 && GetData() != &afxNullData) ||
1271 stringSrc.GetData()->nRefs < 0)
1272 {
1273 AssignCopy(stringSrc.GetData()->nDataLength, stringSrc.m_pchData);
1274 return *this;
1275 }
1276
1277 // Otherwise, release current buffer
1278 Release();
1279 // And set buffer as stringSrc buffer
1280 // And increase its reference count
1281 m_pchData = stringSrc.m_pchData;
1282 InterlockedIncrement(&GetData()->nRefs);
1283
1284 return *this;
1285}

◆ operator=() [6/7]

const CHString & CHString::operator= ( const unsigned char lpsz)

Definition at line 1290 of file chstring.cpp.

1291{
1292 *this = (LPCSTR)lpsz;
1293 return *this;
1294}

◆ operator=() [7/7]

const CHString & CHString::operator= ( LPCSTR  lpsz)

Definition at line 1214 of file chstring.cpp.

1215{
1216 int Len;
1217
1218 // If we have string, get its len
1219 if (lpsz != 0)
1220 {
1221 Len = (int)strlen(lpsz);
1222 }
1223 else
1224 {
1225 Len = 0;
1226 }
1227
1228 // Do this call, even with null len, just to get empty string
1230 if (Len == 0)
1231 {
1232 Release();
1233 return *this;
1234 }
1235
1236 // Convert and copy
1237 mbstowcsz(reinterpret_cast<LPWSTR>(m_pchData), lpsz, Len + 1);
1238 // Get new size and so on
1239 ReleaseBuffer();
1240
1241 return *this;
1242}

◆ operator[]()

CHSTRING_WCHAR CHString::operator[] ( int  nIndex) const

Definition at line 1340 of file chstring.cpp.

1341{
1342 return m_pchData[nIndex];
1343}

◆ Release() [1/2]

void CHString::Release ( )
protected

Definition at line 940 of file chstring.cpp.

941{
942 // If null string, nothing to do
943 if (GetData() == &afxNullData)
944 {
945 return;
946 }
947
948 // Otherwise, decrement ref count and release if required
949 if (InterlockedDecrement(&GetData()->nRefs) == 0)
950 {
951 delete GetData();
952 }
953
954 // In all cases, caller doesn't want string anymore
955 // So, switch back to empty string
957}

Referenced by AllocBeforeWrite(), AssignCopy(), ConcatInPlace(), CopyBeforeWrite(), Empty(), FreeExtra(), GetBuffer(), operator=(), and CHString2::UseStuff().

◆ Release() [2/2]

void WINAPI CHString::Release ( CHStringData pData)
staticprotected

Definition at line 962 of file chstring.cpp.

963{
964 // If empty string, ignore
965 if (pData == &afxNullData)
966 {
967 return;
968 }
969
970 // Otherwise, simply and free if needed
971 if (InterlockedDecrement(&pData->nRefs) == 0)
972 {
973 delete pData;
974 }
975}
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830

◆ ReleaseBuffer()

void CHString::ReleaseBuffer ( int  nNewLength = -1)

Definition at line 980 of file chstring.cpp.

981{
983
984 // We'll modify buffer, so duplicate
986
987 // If no len provided, get one
988 if (nNewLength == -1)
989 {
990 nNewLength = (int)wcslen(reinterpret_cast<LPCWSTR>(m_pchData));
991 }
992
993 // Set appropriate size and null-terminate
994 Data = GetData();
995 Data->nDataLength = nNewLength;
996 Data->data()[nNewLength] = 0;
997}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by CHString(), operator=(), and CHString2::UseStuff().

◆ ReverseFind()

int CHString::ReverseFind ( CHSTRING_WCHAR  ch) const

Definition at line 1002 of file chstring.cpp.

1003{
1004 CHSTRING_WCHAR *Last;
1005
1006 // Let's use appropriate helper
1007 Last = reinterpret_cast<CHSTRING_WCHAR*>(wcsrchr(reinterpret_cast<LPCWSTR>(m_pchData), ch));
1008 // We have to return a position, so compute it
1009 if (Last)
1010 {
1011 return (Last - m_pchData);
1012 }
1013
1014 // Otherwise, return no position
1015 return -1;
1016}
#define wcsrchr
Definition: compat.h:16

Referenced by CHString2::UseStuff().

◆ Right()

CHString CHString::Right ( int  nCount) const

Definition at line 1021 of file chstring.cpp.

1022{
1023 CHString NewString;
1024
1025 // Validate input (we can't get more than what we have ;-))
1026 if (nCount >= 0)
1027 {
1028 if (nCount > GetData()->nDataLength)
1029 {
1030 nCount = GetData()->nDataLength;
1031 }
1032 }
1033
1034 AllocCopy(NewString, nCount, GetData()->nDataLength - nCount, 0);
1035
1036 return NewString;
1037}

Referenced by CHString2::UseStuff().

◆ SafeStrlen() [1/2]

int CHString::SafeStrlen ( CHSTRING_LPCWSTR  lpsz)
staticprotected

Definition at line 1042 of file chstring.cpp.

1043{
1044 // Check we have a string and then get its length
1045 if (lpsz == 0)
1046 {
1047 return 0;
1048 }
1049
1050 // Of course, it's not safe at all in case string is not null-terminated.
1051 // Things that may happen given strings are not to be null-terminated
1052 // in this class...
1053 return (int)wcslen(reinterpret_cast<LPCWSTR>(lpsz));
1054}

Referenced by CHString(), operator+=(), operator=(), SafeStrlen(), and CHString2::UseStuff().

◆ SafeStrlen() [2/2]

static int WINAPI CHString::SafeStrlen ( const wchar_t lpsz)
inlinestaticprotected

Definition at line 174 of file chstring.h.

175 {
176 return SafeStrlen(reinterpret_cast<CHSTRING_LPCWSTR>(lpsz));
177 }

◆ SetAt()

void CHString::SetAt ( int  nIndex,
CHSTRING_WCHAR  ch 
)

Definition at line 1059 of file chstring.cpp.

1060{
1062
1063 m_pchData[nIndex] = ch;
1064}

Referenced by CHString2::UseStuff().

◆ SpanExcluding() [1/2]

CHString CHString::SpanExcluding ( CHSTRING_LPCWSTR  lpszCharSet) const

Definition at line 1069 of file chstring.cpp.

1070{
1071 int Count;
1072
1073 // Get position and then, extract
1074 Count = (int)wcscspn(reinterpret_cast<LPCWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(lpszCharSet));
1075 return Left(Count);
1076}
CHString Left(int nCount) const
Definition: chstring.cpp:805
int Count
Definition: noreturn.cpp:7
_Check_return_ _CRTIMP size_t __cdecl wcscspn(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)

Referenced by SpanExcluding(), and CHString2::UseStuff().

◆ SpanExcluding() [2/2]

CHString CHString::SpanExcluding ( const wchar_t lpszCharSet) const
inline

Definition at line 110 of file chstring.h.

111 {
112 return SpanExcluding(reinterpret_cast<CHSTRING_LPCWSTR>(lpszCharSet));
113 }
CHString SpanExcluding(CHSTRING_LPCWSTR lpszCharSet) const
Definition: chstring.cpp:1069

◆ SpanIncluding() [1/2]

CHString CHString::SpanIncluding ( CHSTRING_LPCWSTR  lpszCharSet) const

Definition at line 1081 of file chstring.cpp.

1082{
1083 int Count;
1084
1085 // Get position and then, extract
1086 Count = (int)wcsspn(reinterpret_cast<LPCWSTR>(m_pchData), reinterpret_cast<LPCWSTR>(lpszCharSet));
1087 return Left(Count);
1088}
_Check_return_ _CRTIMP size_t __cdecl wcsspn(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)

Referenced by SpanIncluding(), and CHString2::UseStuff().

◆ SpanIncluding() [2/2]

CHString CHString::SpanIncluding ( const wchar_t lpszCharSet) const
inline

Definition at line 115 of file chstring.h.

116 {
117 return SpanIncluding(reinterpret_cast<CHSTRING_LPCWSTR>(lpszCharSet));
118 }
CHString SpanIncluding(CHSTRING_LPCWSTR lpszCharSet) const
Definition: chstring.cpp:1081

◆ TrimLeft()

void CHString::TrimLeft ( )

Definition at line 1093 of file chstring.cpp.

1094{
1095 int NewBegin;
1096 int NewLength;
1097 CHSTRING_WCHAR *CurrentChar;
1098
1099 // We'll modify, so copy first
1101
1102 // Start at the begin of the string
1103 CurrentChar = m_pchData;
1104 while (*CurrentChar != 0)
1105 {
1106 // Browse string till we find something which is not a space
1107 if (!iswspace(*CurrentChar))
1108 {
1109 break;
1110 }
1111
1112 CurrentChar++;
1113 }
1114
1115 // Then, calculate new begin (easy) and new length
1116 // And move memory
1117 NewBegin = (CurrentChar - m_pchData);
1118 NewLength = GetData()->nDataLength - NewBegin;
1119 memmove(m_pchData, CurrentChar, NewLength * sizeof(CHSTRING_WCHAR));
1121}
static USHORT USHORT * NewLength
#define iswspace(_c)
Definition: ctype.h:669
#define memmove(s1, s2, n)
Definition: mkisofs.h:881

Referenced by CHString2::UseStuff().

◆ TrimRight()

void CHString::TrimRight ( )

Definition at line 1126 of file chstring.cpp.

1127{
1128 CHSTRING_WCHAR *CurrentChar;
1129 CHSTRING_WCHAR *CanBeEaten;
1130
1131 // We'll modify, so copy first
1133
1134 // Start at the begin of the string -- WHAT?!
1135 // Yes, this algorithm is the same that MS is
1136 // using for its TrimRight.
1137 // It is highly unefficient. It would have been
1138 // easier to start at nDataLength and to get back to
1139 // the begin. Note that it would have been safer as
1140 // well, in case the caller is using non-null-terminated
1141 // strings. But, well...
1142 CurrentChar = m_pchData;
1143 CanBeEaten = 0;
1144 while (*CurrentChar != 0)
1145 {
1146 // If not a space, reset what we can trim
1147 if (!iswspace(*CurrentChar))
1148 {
1149 CanBeEaten = 0;
1150 }
1151 // If it is one, and the first of the spaces serie
1152 // Keep its position
1153 else if (CanBeEaten == 0)
1154 {
1155 CanBeEaten = CurrentChar;
1156 }
1157
1158 CurrentChar++;
1159 }
1160
1161 // If nothing to trim, quit
1162 if (CanBeEaten == 0)
1163 {
1164 return;
1165 }
1166
1167 // Otherwise, shorten the string
1168 GetData()->nDataLength = (CanBeEaten - m_pchData);
1169}

Referenced by CHString2::UseStuff().

◆ UnlockBuffer()

void CHString::UnlockBuffer ( )

Definition at line 1174 of file chstring.cpp.

1175{
1176 // Unlock means just put ref back to 1
1177 // It was previously set to MAX_INT
1178 if (GetData() != &afxNullData)
1179 {
1180 GetData()->nRefs = 1;
1181 }
1182}

Referenced by CHString2::UseStuff().

Friends And Related Function Documentation

◆ operator+ [1/5]

CHString WINAPI operator+ ( CHSTRING_LPCWSTR  lpsz,
const CHString string 
)
friend

Definition at line 1398 of file chstring.cpp.

1399{
1400 int Len;
1401 CHString NewString;
1402
1403 // Get string length
1404 Len = CHString::SafeStrlen(lpsz);
1405 // And concat in new string
1406 NewString.ConcatCopy(Len, lpsz, string.GetData()->nDataLength, string.m_pchData);
1407
1408 return NewString;
1409}

◆ operator+ [2/5]

CHString WINAPI operator+ ( CHSTRING_WCHAR  ch,
const CHString string 
)
friend

Definition at line 1356 of file chstring.cpp.

1357{
1358 CHString NewString;
1359
1360 // Basically concat in a new string
1361 NewString.ConcatCopy(1, &ch, string.GetData()->nDataLength, string.m_pchData);
1362
1363 return NewString;
1364}

◆ operator+ [3/5]

CHString WINAPI operator+ ( const CHString string,
CHSTRING_LPCWSTR  lpsz 
)
friend

Definition at line 1382 of file chstring.cpp.

1383{
1384 int Len;
1385 CHString NewString;
1386
1387 // Get string length
1388 Len = CHString::SafeStrlen(lpsz);
1389 // And concat in new string
1390 NewString.ConcatCopy(string.GetData()->nDataLength, string.m_pchData, Len, lpsz);
1391
1392 return NewString;
1393}

◆ operator+ [4/5]

CHString WINAPI operator+ ( const CHString string,
CHSTRING_WCHAR  ch 
)
friend

Definition at line 1369 of file chstring.cpp.

1370{
1371 CHString NewString;
1372
1373 // Basically concat in a new string
1374 NewString.ConcatCopy(string.GetData()->nDataLength, string.m_pchData, 1, &ch);
1375
1376 return NewString;
1377}

◆ operator+ [5/5]

CHString WINAPI operator+ ( const CHString string1,
const CHString string2 
)
friend

Definition at line 1414 of file chstring.cpp.

1415{
1416 CHString NewString;
1417
1418 // Basically concat in a new string
1419 NewString.ConcatCopy(string1.GetData()->nDataLength, string1.m_pchData,
1420 string2.GetData()->nDataLength, string2.m_pchData);
1421
1422 return NewString;
1423}
static CHAR string1[MAX_PATH]
Definition: asmname.c:32
static CHAR string2[MAX_PATH]
Definition: automation.c:449

Member Data Documentation

◆ m_pchData


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