ReactOS  0.4.14-dev-1332-g6db3d88
CHString Class Reference

#include <chstring.h>

Inheritance diagram for CHString:

Public Member Functions

 CHString ()
 
 CHString (WCHAR ch, int nRepeat=1)
 
 CHString (LPCWSTR lpsz)
 
 CHString (LPCWSTR lpch, int nLength)
 
 CHString (LPCSTR lpsz)
 
 CHString (const CHString &stringSrc)
 
 CHString (const unsigned char *lpsz)
 
 ~CHString ()
 
BSTR AllocSysString () const
 
int Collate (LPCWSTR lpsz) const
 
int Compare (LPCWSTR lpsz) const
 
int CompareNoCase (LPCWSTR lpsz) const
 
void Empty ()
 
int Find (WCHAR ch) const
 
int Find (LPCWSTR lpszSub) const
 
int FindOneOf (LPCWSTR lpszCharSet) const
 
void Format (UINT nFormatID,...)
 
void Format (LPCWSTR lpszFormat,...)
 
void FormatMessageW (UINT nFormatID,...)
 
void FormatMessageW (LPCWSTR lpszFormat,...)
 
void FormatV (LPCWSTR lpszFormat, va_list argList)
 
void FreeExtra ()
 
int GetAllocLength () const
 
WCHAR GetAt (int nIndex) const
 
LPWSTR GetBuffer (int nMinBufLength)
 
LPWSTR GetBufferSetLength (int nNewLength)
 
int GetLength () const
 
BOOL IsEmpty () const
 
CHString Left (int nCount) const
 
int LoadStringW (UINT nID)
 
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 (WCHAR ch) const
 
CHString Right (int nCount) const
 
void SetAt (int nIndex, WCHAR ch)
 
CHString SpanExcluding (LPCWSTR lpszCharSet) const
 
CHString SpanIncluding (LPCWSTR lpszCharSet) const
 
void TrimLeft ()
 
void TrimRight ()
 
void UnlockBuffer ()
 
const CHStringoperator= (char ch)
 
const CHStringoperator= (WCHAR ch)
 
const CHStringoperator= (CHString *p)
 
const CHStringoperator= (LPCSTR lpsz)
 
const CHStringoperator= (LPCWSTR lpsz)
 
const CHStringoperator= (const CHString &stringSrc)
 
const CHStringoperator= (const unsigned char *lpsz)
 
const CHStringoperator+= (char ch)
 
const CHStringoperator+= (WCHAR ch)
 
const CHStringoperator+= (LPCWSTR lpsz)
 
const CHStringoperator+= (const CHString &string)
 
WCHAR operator[] (int nIndex) const
 
 operator 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, LPCWSTR lpszSrcData)
 
void ConcatCopy (int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data)
 
void ConcatInPlace (int nSrcLen, LPCWSTR lpszSrcData)
 
void CopyBeforeWrite ()
 
CHStringDataGetData () const
 
void Init ()
 
int LoadStringW (UINT nID, LPWSTR lpszBuf, UINT nMaxBuf)
 
void Release ()
 

Static Protected Member Functions

static void WINAPI Release (CHStringData *pData)
 
static int WINAPI SafeStrlen (LPCWSTR lpsz)
 

Protected Attributes

LPWSTR m_pchData
 

Friends

CHString WINAPI operator+ (WCHAR ch, const CHString &string)
 
CHString WINAPI operator+ (const CHString &string, WCHAR ch)
 
CHString WINAPI operator+ (const CHString &string, LPCWSTR lpsz)
 
CHString WINAPI operator+ (LPCWSTR lpsz, const CHString &string)
 
CHString WINAPI operator+ (const CHString &string1, const CHString &string2)
 

Detailed Description

Definition at line 21 of file chstring.h.

Constructor & Destructor Documentation

◆ CHString() [1/7]

CHString::CHString ( )

Definition at line 101 of file chstring.cpp.

102 {
103  // Set to empty string
105 }
LPWSTR afxPchNil
Definition: chstring.cpp:37
LPWSTR m_pchData
Definition: chstring.h:95

◆ CHString() [2/7]

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

Definition at line 110 of file chstring.cpp.

111 {
112  // Allow null initialize, in case something goes wrong
114 
115  // If we have a char to insert
116  if (nRepeat >= 1)
117  {
118  // Allocate a buffer big enough
119  AllocBuffer(nRepeat);
120  // And if possible, repeat char
121  if (m_pchData)
122  {
123  for (int i = 0; i < nRepeat; ++i)
124  {
125  m_pchData[i] = ch;
126  }
127  }
128  }
129 }
LPWSTR afxPchNil
Definition: chstring.cpp:37
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
LPWSTR m_pchData
Definition: chstring.h:95
void AllocBuffer(int nLen)
Definition: chstring.cpp:269

◆ CHString() [3/7]

CHString::CHString ( LPCWSTR  lpsz)

Definition at line 134 of file chstring.cpp.

135 {
136  // Allow null initialize, in case something goes wrong
138 
139  // If we have an input string
140  if (lpsz != 0)
141  {
142  // Get its length
143  int Len = SafeStrlen(lpsz);
144  // Then, allocate a big enough buffer and copy string
145  // Note that here, we don't null terminate the string...
146  if (Len)
147  {
148  AllocBuffer(Len);
149  wcsncpy(m_pchData, lpsz, Len);
150  }
151  }
152 }
LPWSTR afxPchNil
Definition: chstring.cpp:37
LPWSTR m_pchData
Definition: chstring.h:95
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
#define Len
Definition: deflate.h:82
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
static int WINAPI SafeStrlen(LPCWSTR lpsz)
Definition: chstring.cpp:1023

◆ CHString() [4/7]

CHString::CHString ( LPCWSTR  lpch,
int  nLength 
)

Definition at line 157 of file chstring.cpp.

158 {
159  // Allow null initialize, in case something goes wrong
161 
162  // In case we have a string with a len
163  if (lpch != 0 && nLength != 0)
164  {
165  // Just copy the string
167  wcsncpy(m_pchData, lpch, nLength);
168  }
169 }
_In_ DWORD nLength
Definition: wincon.h:476
LPWSTR afxPchNil
Definition: chstring.cpp:37
LPWSTR m_pchData
Definition: chstring.h:95
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)

◆ CHString() [5/7]

CHString::CHString ( LPCSTR  lpsz)

Definition at line 174 of file chstring.cpp.

175 {
176  // Allow null initialize, in case something goes wrong
178 
179  // If we have input string
180  if (lpsz != 0)
181  {
182  // Get its length
183  int Len = (int)strlen(lpsz);
184  if (Len)
185  {
186  // Allocate and convert the string
187  AllocBuffer(Len);
188  mbstowcsz(m_pchData, lpsz, Len + 1);
189  // Releasing buffer here is to allow to
190  // update the buffer size. We notify we're
191  // done with changing the string: recompute its
192  // length, please
193  ReleaseBuffer();
194  }
195  }
196 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void ReleaseBuffer(int nNewLength=-1)
Definition: chstring.cpp:961
LPWSTR afxPchNil
Definition: chstring.cpp:37
LPWSTR m_pchData
Definition: chstring.h:95
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
#define Len
Definition: deflate.h:82
int mbstowcsz(LPWSTR lpDest, LPCSTR lpSrc, int nLen)
Definition: chstring.cpp:75
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 212 of file chstring.cpp.

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

◆ CHString() [7/7]

CHString::CHString ( const unsigned char lpsz)

Definition at line 201 of file chstring.cpp.

202 {
203  // Null init
204  Init();
205  // And call operator= with const char*, easier
206  *this = (LPCSTR)lpsz;
207 }
void Init()
Definition: chstring.cpp:770
const char * LPCSTR
Definition: xmlstorage.h:183

◆ ~CHString()

CHString::~CHString ( )

Definition at line 236 of file chstring.cpp.

237 {
238  // If we have a string
239  if (GetData() != &afxNullData)
240  {
241  // Check whether it's still in use after we release it
242  if (InterlockedDecrement(&GetData()->nRefs) == 0)
243  {
244  // If so, delete it
245  delete GetData();
246  }
247  }
248 }
CHStringData * GetData() const
Definition: chstring.cpp:747
CHStringData afxNullData
Definition: chstring.cpp:39
#define InterlockedDecrement
Definition: armddk.h:52

Member Function Documentation

◆ AllocBeforeWrite()

void CHString::AllocBeforeWrite ( int  nLen)
protected

Definition at line 253 of file chstring.cpp.

254 {
255  // In case we have several strings pointing to our memory zone
256  // Or we need bigger buffer than actual
257  if (GetData()->nRefs > 1 || nLen > GetData()->nAllocLength)
258  {
259  // Just drop current
260  // And allocate a new one which is big enough
261  Release();
262  AllocBuffer(nLen);
263  }
264 }
CHStringData * GetData() const
Definition: chstring.cpp:747
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
void Release()
Definition: chstring.cpp:921

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

◆ AllocBuffer()

void CHString::AllocBuffer ( int  nLen)
protected

Definition at line 269 of file chstring.cpp.

270 {
271  // Here we have to allocate a buffer for the string
272  // It actually consists in: CHStringData structure
273  // with a buffer big enough at its end to store the
274  // string.
276 
277  // Null size is easy allocation
278  if (nSize == 0)
279  {
281  return;
282  }
283 
284  // We cannot allow negative sizes
285  if (nSize < 0)
286  {
288  }
289 
290  // Nor too big
291  if (nSize > (INT_MAX - (int)sizeof(CHStringData)) / (int)sizeof(WCHAR))
292  {
294  }
295 
296  // Just allocate big enough buffer, using our own operator new
297  Data = (CHStringData *)operator new(nSize * sizeof(WCHAR) + sizeof(CHStringData));
298  // In case Data is null, throw an exception
299  // Yes, this is stupid! Our operator new is already supposed to through an exception...
300  // Thanks MS
301  if (!Data)
302  {
303  throw HeapException;
304  }
305 
306  Data->nRefs = 1;
307  Data->nDataLength = nSize;
308  Data->nAllocLength = nSize;
309  Data->data()[0] = 0;
310 
311  // We only return the string
312  // We can find back data with some mathematics
313  m_pchData = Data->data();
314 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define INT_MAX
Definition: limits.h:40
CHeap_Exception HeapException(CHeap_Exception::E_ALLOCATION_ERROR)
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2037
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
LPWSTR afxPchNil
Definition: chstring.cpp:37
#define STATUS_INTEGER_OVERFLOW
Definition: ntstatus.h:371
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
LPWSTR m_pchData
Definition: chstring.h:95
__wchar_t WCHAR
Definition: xmlstorage.h:180
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:693

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 319 of file chstring.cpp.

320 {
321  // Once again, we cannot deal with negative lens
322  if (nCopyLen < 0)
323  {
325  }
326 
327  if (nCopyIndex < 0)
328  {
330  }
331 
332  if (nExtraLen < 0)
333  {
335  }
336 
337  // In case what we have to copy is null-sized, just set empty string
338  if (nCopyLen + nExtraLen == 0)
339  {
340  dest.m_pchData = afxPchNil;
341  return;
342  }
343 
344  // Otherwise, allocate a buffer in new string which is big enough
345  // You can note that we absolutely don't check about any existing
346  // (referenced) buffer in dest. Actually, dest is to be EMPTY string.
347  // The whole point of this function is to initialize a virgin string by
348  // copying data from another. This is needed by Left/Mid/Right
349  dest.AllocBuffer(nCopyLen + nExtraLen);
350  // And copy our stuff in
351  wcsncpy(dest.m_pchData, m_pchData + nCopyIndex, nCopyLen);
352 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
LPWSTR afxPchNil
Definition: chstring.cpp:37
LPWSTR m_pchData
Definition: chstring.h:95
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:693
static char * dest
Definition: rtl.c:135

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

◆ AllocSysString()

BSTR CHString::AllocSysString ( ) const

Definition at line 357 of file chstring.cpp.

358 {
359  BSTR SysString;
360 
361  // Just allocate the string
362  SysString = SysAllocStringLen(m_pchData, GetData()->nDataLength);
363  if (!SysString)
364  {
365  throw HeapException;
366  }
367 
368  return SysString;
369 }
CHStringData * GetData() const
Definition: chstring.cpp:747
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
CHeap_Exception HeapException(CHeap_Exception::E_ALLOCATION_ERROR)
OLECHAR * BSTR
Definition: compat.h:1942
LPWSTR m_pchData
Definition: chstring.h:95

Referenced by CHString2::UseStuff().

◆ AssignCopy()

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

Definition at line 374 of file chstring.cpp.

375 {
376  // Don't allow negative len
377  if (nSrcLen < 0)
378  {
380  }
381 
382  // We will have to modify a string that might be shared, so duplicate it
383  // Ensuring it's big enough to contain our new stuff
384  AllocBeforeWrite(nSrcLen);
385  if (nSrcLen == 0)
386  {
387  Release();
388  return;
389  }
390 
391  // Just copy, write down new size, and ensure it's null terminated
392  wcsncpy(m_pchData, lpszSrcData, nSrcLen);
393  GetData()->nDataLength = nSrcLen;
394  m_pchData[nSrcLen] = 0;
395 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
CHStringData * GetData() const
Definition: chstring.cpp:747
void AllocBeforeWrite(int nLen)
Definition: chstring.cpp:253
int nDataLength
Definition: chstring.h:12
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
LPWSTR m_pchData
Definition: chstring.h:95
void Release()
Definition: chstring.cpp:921
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:693

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

◆ Collate()

int CHString::Collate ( LPCWSTR  lpsz) const

Definition at line 400 of file chstring.cpp.

401 {
402  // Just call the deprecated function here - no matter we are null terminated
403  // Did you read my statement about how safe is this implementation?
404  return wcscoll(m_pchData, lpsz);
405 }
_Check_return_ _CRTIMP int __cdecl wcscoll(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
LPWSTR m_pchData
Definition: chstring.h:95

Referenced by CHString2::UseStuff().

◆ Compare()

int CHString::Compare ( LPCWSTR  lpsz) const

Definition at line 410 of file chstring.cpp.

411 {
412  // Just call the deprecated function here - no matter we are null terminated
413  // Did you read my statement about how safe is this implementation?
414  return wcscmp(m_pchData, lpsz);
415 }
LPWSTR m_pchData
Definition: chstring.h:95
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by CHString2::UseStuff().

◆ CompareNoCase()

int CHString::CompareNoCase ( LPCWSTR  lpsz) const

Definition at line 420 of file chstring.cpp.

421 {
422  // Just call the deprecated function here - no matter we are null terminated
423  // Did you read my statement about how safe is this implementation?
424  return wcsicmp(m_pchData, lpsz);
425 }
LPWSTR m_pchData
Definition: chstring.h:95
#define wcsicmp
Definition: string.h:1152

Referenced by CHString2::UseStuff().

◆ ConcatCopy()

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

Definition at line 479 of file chstring.cpp.

480 {
481  int TotalLen;
482 
483  if (nSrc1Len < 0 || nSrc2Len < 0)
484  {
486  }
487 
488  // If both len are null, do nothing
489  TotalLen = nSrc1Len + nSrc2Len;
490  if (TotalLen == 0)
491  {
492  return;
493  }
494 
495  // Otherwise, allocate a new buffer to hold everything (caller will release previous buffer)
496  AllocBuffer(TotalLen);
497  // And concat stuff
498  wcsncpy(m_pchData, lpszSrc1Data, nSrc1Len);
499  wcsncpy(m_pchData + nSrc1Len, lpszSrc2Data, nSrc2Len);
500 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
LPWSTR m_pchData
Definition: chstring.h:95
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:693

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

◆ ConcatInPlace()

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

Definition at line 430 of file chstring.cpp.

431 {
432  // With null length, there's not that much to concat...
433  if (nSrcLen == 0)
434  {
435  return;
436  }
437 
438  // Still no negative length
439  if (nSrcLen < 0)
440  {
442  }
443 
444  // Ensure we wouldn't overflow with the concat
445  if (GetData()->nDataLength > INT_MAX - nSrcLen)
446  {
448  }
449 
450  // In case we have to modify a shared string OR if it can't fit into current buffer...
451  if (GetData()->nRefs > 1 || GetData()->nDataLength + nSrcLen > GetData()->nAllocLength)
452  {
453  // Allocate a new buffer! (without forgetting to release old one)
454  CHStringData* OldData = GetData();
455 
456  // You remember about "InPlace" in the function's name?
457  // The cake is a lie
458  ConcatCopy(GetData()->nDataLength, m_pchData, nSrcLen, lpszSrcData);
459  Release(OldData);
460  }
461  else
462  {
463  // Ensure we don't overflow
464  if (nSrcLen > INT_MAX - GetData()->nDataLength)
465  {
467  }
468 
469  // Then, just copy and null terminate
470  wcsncpy(m_pchData + GetData()->nDataLength, lpszSrcData, nSrcLen);
471  GetData()->nDataLength += nSrcLen;
472  m_pchData[GetData()->nDataLength] = 0;
473  }
474 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
CHStringData * GetData() const
Definition: chstring.cpp:747
#define INT_MAX
Definition: limits.h:40
int nDataLength
Definition: chstring.h:12
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data)
Definition: chstring.cpp:479
#define STATUS_INTEGER_OVERFLOW
Definition: ntstatus.h:371
LPWSTR m_pchData
Definition: chstring.h:95
void Release()
Definition: chstring.cpp:921
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:693

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

◆ CopyBeforeWrite()

void CHString::CopyBeforeWrite ( )
protected

Definition at line 505 of file chstring.cpp.

506 {
508 
509  // First, we need to get reference count
510  // And we also need to save Data for later copy
511  Data = GetData();
512 
513  if (Data->nRefs <= 1)
514  {
515  // If its not used, don't waste time to realloc, it will do the job
516  return;
517  }
518 
519  // Release current data - we are sure it won't be freed upon that point
520  // Thanks to the reference count check previously done
521  Release();
522  // Alloc new buffer and copy old data in it
523  AllocBuffer(Data->nDataLength);
524  wcsncpy(m_pchData, Data->data(), Data->nDataLength);
525 }
CHStringData * GetData() const
Definition: chstring.cpp:747
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
LPWSTR m_pchData
Definition: chstring.h:95
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
void Release()
Definition: chstring.cpp:921
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)

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

◆ Empty()

void CHString::Empty ( )

Definition at line 530 of file chstring.cpp.

531 {
532  // Already empty
533  if (GetData()->nDataLength == 0)
534  {
535  return;
536  }
537 
538  // Empty it easily given it's reference count
539  if (GetData()->nRefs < 0)
540  {
541  *this = afxPchNil;
542  }
543  else
544  {
545  // Otherwise, just release it
546  // It will set back this instance to afxPchNil
547  // while decreasing reference count
548  Release();
549  }
550 }
CHStringData * GetData() const
Definition: chstring.cpp:747
LPWSTR afxPchNil
Definition: chstring.cpp:37
void Release()
Definition: chstring.cpp:921

Referenced by CHString2::UseStuff().

◆ Find() [1/2]

int CHString::Find ( WCHAR  ch) const

Definition at line 555 of file chstring.cpp.

556 {
557  WCHAR *Found;
558 
559  // Let's use appropriate helper
560  Found = wcschr(m_pchData, ch);
561  // We have to return a position, so compute it
562  if (Found)
563  {
564  return (Found - m_pchData);
565  }
566 
567  // Otherwise, return no position
568  return -1;
569 }
LPWSTR m_pchData
Definition: chstring.h:95
return Found
Definition: dirsup.c:1270
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CHString2::UseStuff().

◆ Find() [2/2]

int CHString::Find ( LPCWSTR  lpszSub) const

Definition at line 574 of file chstring.cpp.

575 {
576  WCHAR *Found;
577 
578  // Let's use appropriate helper
579  Found = wcsstr(m_pchData, lpszSub);
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 }
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
LPWSTR m_pchData
Definition: chstring.h:95
return Found
Definition: dirsup.c:1270
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ FindOneOf()

int CHString::FindOneOf ( LPCWSTR  lpszCharSet) const

Definition at line 593 of file chstring.cpp.

594 {
595  WCHAR *Found;
596 
597  // Let's use appropriate helper
598  Found = wcspbrk(m_pchData, lpszCharSet);
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 }
LPWSTR m_pchData
Definition: chstring.h:95
return Found
Definition: dirsup.c:1270
__wchar_t WCHAR
Definition: xmlstorage.h:180
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcspbrk(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)

Referenced by CHString2::UseStuff().

◆ Format() [1/2]

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

Definition at line 612 of file chstring.cpp.

613 {
614  // Deprecated and not implemented any longer - well, this is its implementation
615  return;
616 }

Referenced by CHString2::UseStuff().

◆ Format() [2/2]

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

Definition at line 621 of file chstring.cpp.

622 {
623  // Forward to FormatV
624  va_list ArgsList;
625 
626  va_start(ArgsList, lpszFormat);
627  FormatV(lpszFormat, ArgsList);
628  va_end(ArgsList);
629 }
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
void FormatV(LPCWSTR lpszFormat, va_list argList)
Definition: chstring.cpp:651
#define va_start(ap, A)
Definition: acmsvcex.h:91

◆ FormatMessageW() [1/2]

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

Definition at line 634 of file chstring.cpp.

635 {
636  // Deprecated and not implemented any longer - well, this is its implementation
637  return;
638 }

Referenced by CHString2::UseStuff().

◆ FormatMessageW() [2/2]

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

Definition at line 643 of file chstring.cpp.

644 {
646 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ FormatV()

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

Definition at line 651 of file chstring.cpp.

652 {
654 }
#define UNIMPLEMENTED
Definition: debug.h:114

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

◆ FreeExtra()

void CHString::FreeExtra ( )

Definition at line 659 of file chstring.cpp.

660 {
661  CHStringData* OldData;
662 
663  // No extra? Do nothing
664  if (GetData()->nDataLength == GetData()->nAllocLength)
665  {
666  return;
667  }
668 
669  // Get old buffer
670  OldData = GetData();
671  // Allocate a new one, at the right size (with no place for \0 :-))
672  AllocBuffer(GetData()->nDataLength);
673  // Copy old and release it
674  wcsncpy(m_pchData, OldData->data(), OldData->nDataLength);
675  Release(OldData);
676 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nDataLength
Definition: chstring.h:12
WCHAR * data()
Definition: chstring.h:15
LPWSTR m_pchData
Definition: chstring.h:95
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
void Release()
Definition: chstring.cpp:921
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)

Referenced by CHString2::UseStuff().

◆ GetAllocLength()

int CHString::GetAllocLength ( ) const

Definition at line 681 of file chstring.cpp.

682 {
683  return GetData()->nAllocLength;
684 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nAllocLength
Definition: chstring.h:13

Referenced by CHString2::UseStuff().

◆ GetAt()

WCHAR CHString::GetAt ( int  nIndex) const

Definition at line 689 of file chstring.cpp.

690 {
691  // It's up to you to check the index!
692  return m_pchData[nIndex];
693 }
LPWSTR m_pchData
Definition: chstring.h:95

Referenced by CHString2::UseStuff().

◆ GetBuffer()

LPWSTR CHString::GetBuffer ( int  nMinBufLength)

Definition at line 698 of file chstring.cpp.

699 {
700  LPWSTR OldBuffer = m_pchData;
701 
702  // We'll have to allocate a new buffer if it's not big enough
703  // or if it's shared by several strings
704  if (GetData()->nRefs > 1 || GetData()->nAllocLength < nMinBufLength)
705  {
706  CHStringData* OldData = GetData();
707  int OldLen = GetData()->nDataLength;
708 
709  // Ensure we can hold enough
710  if (OldLen > nMinBufLength)
711  {
712  nMinBufLength = OldLen;
713  }
714 
715  // Allocate new buffer
716  AllocBuffer(nMinBufLength);
717  // Copy contents
718  wcsncpy(m_pchData, OldBuffer, OldLen);
719  GetData()->nDataLength = OldLen;
720 
721  // Release old
722  Release(OldData);
723  }
724 
725  // Weirdly, here Windows always returns the old buffer
726  // Which basically exposes a wrong buffer
727  return OldBuffer;
728 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nDataLength
Definition: chstring.h:12
LPWSTR m_pchData
Definition: chstring.h:95
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
void Release()
Definition: chstring.cpp:921
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by GetBufferSetLength(), LockBuffer(), and CHString2::UseStuff().

◆ GetBufferSetLength()

LPWSTR CHString::GetBufferSetLength ( int  nNewLength)

Definition at line 733 of file chstring.cpp.

734 {
735  // Get a buffer big enough
736  // We don't care about the return, it will be set in the string
737  (void)GetBuffer(nNewLength);
738  // Set length, null-terminate and return
739  GetData()->nDataLength = nNewLength;
740  m_pchData[nNewLength] = 0;
741  return m_pchData;
742 }
CHStringData * GetData() const
Definition: chstring.cpp:747
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
int nDataLength
Definition: chstring.h:12
LPWSTR m_pchData
Definition: chstring.h:95
LPWSTR GetBuffer(int nMinBufLength)
Definition: chstring.cpp:698

Referenced by CHString2::UseStuff().

◆ GetData()

CHStringData * CHString::GetData ( ) const
protected

Definition at line 747 of file chstring.cpp.

748 {
749  // In case of empty string, return empty data
750  if (m_pchData == afxPchNil)
751  {
752  return &afxNullData;
753  }
754 
755  // Otherwise, do maths
756  return (CHStringData*)((ULONG_PTR)m_pchData - sizeof(CHStringData));
757 }
LPWSTR afxPchNil
Definition: chstring.cpp:37
LPWSTR m_pchData
Definition: chstring.h:95
CHStringData afxNullData
Definition: chstring.cpp:39
#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 762 of file chstring.cpp.

763 {
764  return GetData()->nDataLength;
765 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nDataLength
Definition: chstring.h:12

Referenced by CHString2::UseStuff().

◆ Init()

void CHString::Init ( )
protected

Definition at line 770 of file chstring.cpp.

771 {
773 }
LPWSTR afxPchNil
Definition: chstring.cpp:37
LPWSTR m_pchData
Definition: chstring.h:95

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

◆ IsEmpty()

BOOL CHString::IsEmpty ( ) const

Definition at line 778 of file chstring.cpp.

779 {
780  return (GetData()->nDataLength == 0);
781 }
CHStringData * GetData() const
Definition: chstring.cpp:747

Referenced by CHString2::UseStuff().

◆ Left()

CHString CHString::Left ( int  nCount) const

Definition at line 786 of file chstring.cpp.

787 {
788  CHString NewString;
789 
790  // Validate input (we can't get more than what we have ;-))
791  if (nCount)
792  {
793  if (nCount > GetData()->nDataLength)
794  {
795  nCount = GetData()->nDataLength;
796  }
797  }
798 
799  AllocCopy(NewString, nCount, 0, 0);
800 
801  return NewString;
802 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nDataLength
Definition: chstring.h:12
void AllocCopy(CHString &dest, int nCopyLen, int nCopyIndex, int nExtraLen) const
Definition: chstring.cpp:319

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

◆ LoadStringW() [1/2]

int CHString::LoadStringW ( UINT  nID)

Definition at line 807 of file chstring.cpp.

808 {
809  // Deprecated and not implemented any longer - well, this is its implementation
810  return 0;
811 }

Referenced by CHString2::UseStuff().

◆ LoadStringW() [2/2]

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

Definition at line 816 of file chstring.cpp.

817 {
818  // Deprecated and not implemented any longer - well, this is its implementation
819  return 0;
820 }

◆ LockBuffer()

LPWSTR CHString::LockBuffer ( )

Definition at line 825 of file chstring.cpp.

826 {
827  LPWSTR LockedBuffer;
828 
829  // The purpose here is basically to set the nRefs to max int
830  LockedBuffer = GetBuffer(0);
831  GetData()->nRefs = INT_MAX;
832 
833  return LockedBuffer;
834 }
CHStringData * GetData() const
Definition: chstring.cpp:747
#define INT_MAX
Definition: limits.h:40
long nRefs
Definition: chstring.h:11
LPWSTR GetBuffer(int nMinBufLength)
Definition: chstring.cpp:698
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by CHString2::UseStuff().

◆ MakeLower()

void CHString::MakeLower ( )

Definition at line 839 of file chstring.cpp.

840 {
841  // We'll modify string, duplicate it first if needed
842  CopyBeforeWrite();
843 
844  // Let's use appropriate helper
846 }
LPWSTR m_pchData
Definition: chstring.h:95
_CRTIMP wchar_t *__cdecl _wcslwr(_Inout_z_ wchar_t *_String)
void CopyBeforeWrite()
Definition: chstring.cpp:505

Referenced by CHString2::UseStuff().

◆ MakeReverse()

void CHString::MakeReverse ( )

Definition at line 851 of file chstring.cpp.

852 {
853  // We'll modify string, duplicate it first if needed
854  CopyBeforeWrite();
855 
856  // Let's use appropriate helper
858 }
_CRTIMP wchar_t *__cdecl _wcsrev(_Inout_z_ wchar_t *_Str)
LPWSTR m_pchData
Definition: chstring.h:95
void CopyBeforeWrite()
Definition: chstring.cpp:505

Referenced by CHString2::UseStuff().

◆ MakeUpper()

void CHString::MakeUpper ( )

Definition at line 863 of file chstring.cpp.

864 {
865  // We'll modify string, duplicate it first if needed
866  CopyBeforeWrite();
867 
868  // Let's use appropriate helper
870 }
LPWSTR m_pchData
Definition: chstring.h:95
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
void CopyBeforeWrite()
Definition: chstring.cpp:505

Referenced by CHString2::UseStuff().

◆ Mid() [1/2]

CHString CHString::Mid ( int  nFirst) const

Definition at line 875 of file chstring.cpp.

876 {
877  // Take string from nFirst up to the end
878  return Mid(nFirst, GetData()->nDataLength - nFirst);
879 }
CHStringData * GetData() const
Definition: chstring.cpp:747
CHString Mid(int nFirst) const
Definition: chstring.cpp:875

Referenced by CHString2::UseStuff().

◆ Mid() [2/2]

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

Definition at line 884 of file chstring.cpp.

885 {
886  CHString NewString;
887 
888  // Validate sizes first
889  if (nFirst < 0)
890  {
891  nFirst = 0;
892  }
893 
894  if (nCount < 0)
895  {
896  nCount = 0;
897  }
898 
899  // Ensure we don't go beyond the string
900  if (nFirst + nCount > GetData()->nDataLength)
901  {
902  nCount = GetData()->nDataLength - nFirst;
903  }
904 
905  // Also ensure we don't read beyond
906  // Yes, this should have been done before previous check
907  // MS does it that way
908  if (nFirst > GetData()->nDataLength)
909  {
910  nCount = 0;
911  }
912 
913  AllocCopy(NewString, nCount, nFirst, 0);
914 
915  return NewString;
916 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nDataLength
Definition: chstring.h:12
void AllocCopy(CHString &dest, int nCopyLen, int nCopyIndex, int nExtraLen) const
Definition: chstring.cpp:319

◆ operator LPCWSTR()

Definition at line 1329 of file chstring.cpp.

1330 {
1331  return m_pchData;
1332 }
LPWSTR m_pchData
Definition: chstring.h:95

◆ operator+=() [1/4]

Definition at line 1280 of file chstring.cpp.

1281 {
1282  *this += (WCHAR)ch;
1283  return *this;
1284 }
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ operator+=() [2/4]

Definition at line 1289 of file chstring.cpp.

1290 {
1291  ConcatInPlace(1, &ch);
1292  return *this;
1293 }
void ConcatInPlace(int nSrcLen, LPCWSTR lpszSrcData)
Definition: chstring.cpp:430

◆ operator+=() [3/4]

Definition at line 1298 of file chstring.cpp.

1299 {
1300  int Len;
1301 
1302  Len = SafeStrlen(lpsz);
1303  ConcatInPlace(Len, lpsz);
1304 
1305  return *this;
1306 }
void ConcatInPlace(int nSrcLen, LPCWSTR lpszSrcData)
Definition: chstring.cpp:430
#define Len
Definition: deflate.h:82
static int WINAPI SafeStrlen(LPCWSTR lpsz)
Definition: chstring.cpp:1023

◆ operator+=() [4/4]

Definition at line 1311 of file chstring.cpp.

1312 {
1313  ConcatInPlace(string.GetData()->nDataLength, string.m_pchData);
1314 
1315  return *this;
1316 }
CHStringData * GetData() const
Definition: chstring.cpp:747
void ConcatInPlace(int nSrcLen, LPCWSTR lpszSrcData)
Definition: chstring.cpp:430
LPWSTR m_pchData
Definition: chstring.h:95

◆ operator=() [1/7]

Definition at line 1168 of file chstring.cpp.

1169 {
1170  *this = (WCHAR)ch;
1171  return *this;
1172 }
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ operator=() [2/7]

Definition at line 1177 of file chstring.cpp.

1178 {
1179  AssignCopy(1, &ch);
1180  return *this;
1181 }
void AssignCopy(int nSrcLen, LPCWSTR lpszSrcData)
Definition: chstring.cpp:374

◆ operator=() [3/7]

Definition at line 1186 of file chstring.cpp.

1187 {
1188  *this = *p;
1189  return *this;
1190 }
GLfloat GLfloat p
Definition: glext.h:8902

◆ operator=() [4/7]

Definition at line 1195 of file chstring.cpp.

1196 {
1197  int Len;
1198 
1199  // If we have string, get its len
1200  if (lpsz != 0)
1201  {
1202  Len = (int)strlen(lpsz);
1203  }
1204  else
1205  {
1206  Len = 0;
1207  }
1208 
1209  // Do this call, even with null len, just to get empty string
1211  if (Len == 0)
1212  {
1213  Release();
1214  return *this;
1215  }
1216 
1217  // Convert and copy
1218  mbstowcsz(m_pchData, lpsz, Len + 1);
1219  // Get new size and so on
1220  ReleaseBuffer();
1221 
1222  return *this;
1223 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void AllocBeforeWrite(int nLen)
Definition: chstring.cpp:253
void ReleaseBuffer(int nNewLength=-1)
Definition: chstring.cpp:961
LPWSTR m_pchData
Definition: chstring.h:95
#define Len
Definition: deflate.h:82
int mbstowcsz(LPWSTR lpDest, LPCSTR lpSrc, int nLen)
Definition: chstring.cpp:75
void Release()
Definition: chstring.cpp:921
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ operator=() [5/7]

Definition at line 1228 of file chstring.cpp.

1229 {
1230  int Len;
1231 
1232  Len = SafeStrlen(lpsz);
1233  AssignCopy(Len, lpsz);
1234 
1235  return *this;
1236 }
void AssignCopy(int nSrcLen, LPCWSTR lpszSrcData)
Definition: chstring.cpp:374
#define Len
Definition: deflate.h:82
static int WINAPI SafeStrlen(LPCWSTR lpsz)
Definition: chstring.cpp:1023

◆ operator=() [6/7]

Definition at line 1241 of file chstring.cpp.

1242 {
1243  // Don't copy string on itself
1244  if (&stringSrc == this)
1245  {
1246  return *this;
1247  }
1248 
1249  // In case we don't have a referenced string here,
1250  // or if the other is not referenced, just copy here
1251  if ((GetData()->nRefs < 0 && GetData() != &afxNullData) ||
1252  stringSrc.GetData()->nRefs < 0)
1253  {
1254  AssignCopy(stringSrc.GetData()->nDataLength, stringSrc.m_pchData);
1255  return *this;
1256  }
1257 
1258  // Otherwise, release current buffer
1259  Release();
1260  // And set buffer as stringSrc buffer
1261  // And increase its reference count
1262  m_pchData = stringSrc.m_pchData;
1263  InterlockedIncrement(&GetData()->nRefs);
1264 
1265  return *this;
1266 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nDataLength
Definition: chstring.h:12
void AssignCopy(int nSrcLen, LPCWSTR lpszSrcData)
Definition: chstring.cpp:374
LPWSTR m_pchData
Definition: chstring.h:95
CHStringData afxNullData
Definition: chstring.cpp:39
long nRefs
Definition: chstring.h:11
void Release()
Definition: chstring.cpp:921
#define InterlockedIncrement
Definition: armddk.h:53

◆ operator=() [7/7]

Definition at line 1271 of file chstring.cpp.

1272 {
1273  *this = (LPCSTR)lpsz;
1274  return *this;
1275 }
const char * LPCSTR
Definition: xmlstorage.h:183

◆ operator[]()

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

Definition at line 1321 of file chstring.cpp.

1322 {
1323  return m_pchData[nIndex];
1324 }
LPWSTR m_pchData
Definition: chstring.h:95

◆ Release() [1/2]

void CHString::Release ( void  )
protected

Definition at line 921 of file chstring.cpp.

922 {
923  // If null string, nothing to do
924  if (GetData() == &afxNullData)
925  {
926  return;
927  }
928 
929  // Otherwise, decrement ref count and release if required
930  if (InterlockedDecrement(&GetData()->nRefs) == 0)
931  {
932  delete GetData();
933  }
934 
935  // In all cases, caller doesn't want string anymore
936  // So, switch back to empty string
938 }
CHStringData * GetData() const
Definition: chstring.cpp:747
LPWSTR afxPchNil
Definition: chstring.cpp:37
LPWSTR m_pchData
Definition: chstring.h:95
CHStringData afxNullData
Definition: chstring.cpp:39
#define InterlockedDecrement
Definition: armddk.h:52

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 943 of file chstring.cpp.

944 {
945  // If empty string, ignore
946  if (pData == &afxNullData)
947  {
948  return;
949  }
950 
951  // Otherwise, simply and free if needed
952  if (InterlockedDecrement(&pData->nRefs) == 0)
953  {
954  delete pData;
955  }
956 }
CHStringData afxNullData
Definition: chstring.cpp:39
#define InterlockedDecrement
Definition: armddk.h:52
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

◆ ReleaseBuffer()

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

Definition at line 961 of file chstring.cpp.

962 {
964 
965  // We'll modify buffer, so duplicate
966  CopyBeforeWrite();
967 
968  // If no len provided, get one
969  if (nNewLength == -1)
970  {
971  nNewLength = (int)wcslen(m_pchData);
972  }
973 
974  // Set appropriate size and null-terminate
975  Data = GetData();
976  Data->nDataLength = nNewLength;
977  Data->data()[nNewLength] = 0;
978 }
CHStringData * GetData() const
Definition: chstring.cpp:747
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
LPWSTR m_pchData
Definition: chstring.h:95
void CopyBeforeWrite()
Definition: chstring.cpp:505
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

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

◆ ReverseFind()

int CHString::ReverseFind ( WCHAR  ch) const

Definition at line 983 of file chstring.cpp.

984 {
985  WCHAR *Last;
986 
987  // Let's use appropriate helper
988  Last = wcsrchr(m_pchData, ch);
989  // We have to return a position, so compute it
990  if (Last)
991  {
992  return (Last - m_pchData);
993  }
994 
995  // Otherwise, return no position
996  return -1;
997 }
LPWSTR m_pchData
Definition: chstring.h:95
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CHString2::UseStuff().

◆ Right()

CHString CHString::Right ( int  nCount) const

Definition at line 1002 of file chstring.cpp.

1003 {
1004  CHString NewString;
1005 
1006  // Validate input (we can't get more than what we have ;-))
1007  if (nCount >= 0)
1008  {
1009  if (nCount > GetData()->nDataLength)
1010  {
1011  nCount = GetData()->nDataLength;
1012  }
1013  }
1014 
1015  AllocCopy(NewString, nCount, GetData()->nDataLength - nCount, 0);
1016 
1017  return NewString;
1018 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nDataLength
Definition: chstring.h:12
void AllocCopy(CHString &dest, int nCopyLen, int nCopyIndex, int nExtraLen) const
Definition: chstring.cpp:319

Referenced by CHString2::UseStuff().

◆ SafeStrlen()

int CHString::SafeStrlen ( LPCWSTR  lpsz)
staticprotected

Definition at line 1023 of file chstring.cpp.

1024 {
1025  // Check we have a string and then get its length
1026  if (lpsz == 0)
1027  {
1028  return 0;
1029  }
1030 
1031  // Of course, it's not safe at all in case string is not null-terminated.
1032  // Things that may happen given strings are not to be null-terminated
1033  // in this class...
1034  return (int)wcslen(lpsz);
1035 }
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

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

◆ SetAt()

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

Definition at line 1040 of file chstring.cpp.

1041 {
1042  CopyBeforeWrite();
1043 
1044  m_pchData[nIndex] = ch;
1045 }
LPWSTR m_pchData
Definition: chstring.h:95
void CopyBeforeWrite()
Definition: chstring.cpp:505

Referenced by CHString2::UseStuff().

◆ SpanExcluding()

CHString CHString::SpanExcluding ( LPCWSTR  lpszCharSet) const

Definition at line 1050 of file chstring.cpp.

1051 {
1052  int Count;
1053 
1054  // Get position and then, extract
1055  Count = (int)wcscspn(m_pchData, lpszCharSet);
1056  return Left(Count);
1057 }
_Check_return_ _CRTIMP size_t __cdecl wcscspn(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)
CHString Left(int nCount) const
Definition: chstring.cpp:786
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
LPWSTR m_pchData
Definition: chstring.h:95
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by CHString2::UseStuff().

◆ SpanIncluding()

CHString CHString::SpanIncluding ( LPCWSTR  lpszCharSet) const

Definition at line 1062 of file chstring.cpp.

1063 {
1064  int Count;
1065 
1066  // Get position and then, extract
1067  Count = (int)wcsspn(m_pchData, lpszCharSet);
1068  return Left(Count);
1069 }
CHString Left(int nCount) const
Definition: chstring.cpp:786
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
LPWSTR m_pchData
Definition: chstring.h:95
_Check_return_ _CRTIMP size_t __cdecl wcsspn(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by CHString2::UseStuff().

◆ TrimLeft()

void CHString::TrimLeft ( )

Definition at line 1074 of file chstring.cpp.

1075 {
1076  int NewBegin;
1077  int NewLength;
1078  WCHAR *CurrentChar;
1079 
1080  // We'll modify, so copy first
1081  CopyBeforeWrite();
1082 
1083  // Start at the begin of the string
1084  CurrentChar = m_pchData;
1085  while (*CurrentChar != 0)
1086  {
1087  // Browse string till we find something which is not a space
1088  if (!iswspace(*CurrentChar))
1089  {
1090  break;
1091  }
1092 
1093  CurrentChar++;
1094  }
1095 
1096  // Then, calculate new begin (easy) and new length
1097  // And move memory
1098  NewBegin = (CurrentChar - m_pchData);
1099  NewLength = GetData()->nDataLength - NewBegin;
1100  memmove(m_pchData, CurrentChar, NewLength * sizeof(WCHAR));
1102 }
CHStringData * GetData() const
Definition: chstring.cpp:747
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
int nDataLength
Definition: chstring.h:12
static USHORT USHORT * NewLength
LPWSTR m_pchData
Definition: chstring.h:95
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define iswspace(_c)
Definition: ctype.h:669
void CopyBeforeWrite()
Definition: chstring.cpp:505

Referenced by CHString2::UseStuff().

◆ TrimRight()

void CHString::TrimRight ( )

Definition at line 1107 of file chstring.cpp.

1108 {
1109  WCHAR *CurrentChar;
1110  WCHAR *CanBeEaten;
1111 
1112  // We'll modify, so copy first
1113  CopyBeforeWrite();
1114 
1115  // Start at the begin of the string -- WHAT?!
1116  // Yes, this algorithm is the same that MS is
1117  // using for its TrimRight.
1118  // It is highly unefficient. It would have been
1119  // easier to start at nDataLength and to get back to
1120  // the begin. Note that it would have been safer as
1121  // well, in case the caller is using non-null-terminated
1122  // strings. But, well...
1123  CurrentChar = m_pchData;
1124  CanBeEaten = 0;
1125  while (*CurrentChar != 0)
1126  {
1127  // If not a space, reset what we can trim
1128  if (!iswspace(*CurrentChar))
1129  {
1130  CanBeEaten = 0;
1131  }
1132  // If it is one, and the first of the spaces serie
1133  // Keep its position
1134  else if (CanBeEaten == 0)
1135  {
1136  CanBeEaten = CurrentChar;
1137  }
1138 
1139  CurrentChar++;
1140  }
1141 
1142  // If nothing to trim, quit
1143  if (CanBeEaten == 0)
1144  {
1145  return;
1146  }
1147 
1148  // Otherwise, shorten the string
1149  GetData()->nDataLength = (CanBeEaten - m_pchData);
1150 }
CHStringData * GetData() const
Definition: chstring.cpp:747
int nDataLength
Definition: chstring.h:12
LPWSTR m_pchData
Definition: chstring.h:95
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define iswspace(_c)
Definition: ctype.h:669
void CopyBeforeWrite()
Definition: chstring.cpp:505

Referenced by CHString2::UseStuff().

◆ UnlockBuffer()

void CHString::UnlockBuffer ( )

Definition at line 1155 of file chstring.cpp.

1156 {
1157  // Unlock means just put ref back to 1
1158  // It was previously set to MAX_INT
1159  if (GetData() != &afxNullData)
1160  {
1161  GetData()->nRefs = 1;
1162  }
1163 }
CHStringData * GetData() const
Definition: chstring.cpp:747
CHStringData afxNullData
Definition: chstring.cpp:39
long nRefs
Definition: chstring.h:11

Referenced by CHString2::UseStuff().

Friends And Related Function Documentation

◆ operator+ [1/5]

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

Definition at line 1337 of file chstring.cpp.

1338 {
1339  CHString NewString;
1340 
1341  // Basically concat in a new string
1342  NewString.ConcatCopy(1, &ch, string.GetData()->nDataLength, string.m_pchData);
1343 
1344  return NewString;
1345 }
CHStringData * GetData() const
Definition: chstring.cpp:747
void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data)
Definition: chstring.cpp:479
LPWSTR m_pchData
Definition: chstring.h:95

◆ operator+ [2/5]

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

Definition at line 1350 of file chstring.cpp.

1351 {
1352  CHString NewString;
1353 
1354  // Basically concat in a new string
1355  NewString.ConcatCopy(string.GetData()->nDataLength, string.m_pchData, 1, &ch);
1356 
1357  return NewString;
1358 }
CHStringData * GetData() const
Definition: chstring.cpp:747
void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data)
Definition: chstring.cpp:479
LPWSTR m_pchData
Definition: chstring.h:95

◆ operator+ [3/5]

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

Definition at line 1363 of file chstring.cpp.

1364 {
1365  int Len;
1366  CHString NewString;
1367 
1368  // Get string length
1369  Len = CHString::SafeStrlen(lpsz);
1370  // And concat in new string
1371  NewString.ConcatCopy(string.GetData()->nDataLength, string.m_pchData, Len, lpsz);
1372 
1373  return NewString;
1374 }
CHStringData * GetData() const
Definition: chstring.cpp:747
void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data)
Definition: chstring.cpp:479
LPWSTR m_pchData
Definition: chstring.h:95
#define Len
Definition: deflate.h:82
static int WINAPI SafeStrlen(LPCWSTR lpsz)
Definition: chstring.cpp:1023

◆ operator+ [4/5]

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

Definition at line 1379 of file chstring.cpp.

1380 {
1381  int Len;
1382  CHString NewString;
1383 
1384  // Get string length
1385  Len = CHString::SafeStrlen(lpsz);
1386  // And concat in new string
1387  NewString.ConcatCopy(Len, lpsz, string.GetData()->nDataLength, string.m_pchData);
1388 
1389  return NewString;
1390 }
CHStringData * GetData() const
Definition: chstring.cpp:747
void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data)
Definition: chstring.cpp:479
LPWSTR m_pchData
Definition: chstring.h:95
#define Len
Definition: deflate.h:82
static int WINAPI SafeStrlen(LPCWSTR lpsz)
Definition: chstring.cpp:1023

◆ operator+ [5/5]

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

Definition at line 1395 of file chstring.cpp.

1396 {
1397  CHString NewString;
1398 
1399  // Basically concat in a new string
1400  NewString.ConcatCopy(string1.GetData()->nDataLength, string1.m_pchData,
1401  string2.GetData()->nDataLength, string2.m_pchData);
1402 
1403  return NewString;
1404 }
static CHAR string2[MAX_PATH]
Definition: automation.c:468
static CHAR string1[MAX_PATH]
Definition: asmname.c:32
void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data)
Definition: chstring.cpp:479

Member Data Documentation

◆ m_pchData


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