4#include <utilities-def.h>
5#include <interface/sstring-i.h>
6#include <string/sstringdata.h>
16 static size_t StrLen(
const wchar_t* psz);
22 static int Compare(
const wchar_t* psz1,
const wchar_t* psz2);
28 static int CompareNoCase(
const wchar_t* psz1,
const wchar_t* psz2);
34 static const wchar_t*
StrChr(
const wchar_t* psz,
wchar_t ch);
40 static const wchar_t*
StrRChr(
const wchar_t* psz,
wchar_t ch);
46 static const wchar_t*
StrStr(
const wchar_t* psz,
const wchar_t* psz2);
51 static wchar_t*
StrUpper(
wchar_t* psz);
56 static wchar_t*
StrLower(
wchar_t* psz);
76 static wchar_t*
CharNext(
wchar_t* psz);
83 static int Format(
wchar_t** ppszDst,
const wchar_t* pszFormat, va_list & args);
91 static int LoadString(HINSTANCE hInst, UINT uID,
wchar_t* lpBuffer,
int nBufferMax);
98 typedef const wchar_t * pctstr;
99 typedef wchar_t _tchar;
111 SStringW(
const IStringW* stringSrc);
116 SStringW(
wchar_t ch,
int nLength = 1);
121 SStringW(
const wchar_t* psz,
int nLength);
137 STDMETHOD_(BOOL,
IsEmpty)(THIS) SCONST;
140 STDMETHOD_(
void,
Empty)(THIS);
145 STDMETHOD_(
wchar_t,
GetAt)(THIS_
int nIndex) SCONST;
150 STDMETHOD_(
void,
SetAt)(THIS_
int nIndex,
wchar_t ch);
154 STDMETHOD_(
const wchar_t *,
c_str)(THIS) SCONST;
159 STDMETHOD_(
int,
Compare)(THIS_
const wchar_t* psz) SCONST;
164 STDMETHOD_(
int,
CompareNoCase)(THIS_
const wchar_t* psz) SCONST;
173 STDMETHOD_(
int,
InsertChar)(THIS_
int nIndex,
wchar_t ch);
179 STDMETHOD_(
int,
Insert)(THIS_
int nIndex,
const wchar_t* psz);
185 STDMETHOD_(
int,
Delete)(THIS_
int nIndex,
int nCount = 1);
191 STDMETHOD_(
int,
ReplaceChar)(THIS_
wchar_t chOld,
wchar_t chNew);
197 STDMETHOD_(
int,
Replace)(THIS_
const wchar_t* pszOld,
const wchar_t* pszNew);
202 STDMETHOD_(
int,
Remove)(THIS_
wchar_t chRemove);
208 STDMETHOD_(
int,
FindChar)(THIS_
wchar_t ch,
int nStart DEF_VAL(0)) SCONST;
213 STDMETHOD_(
int,
ReverseFind)(THIS_
wchar_t ch) SCONST;
219 STDMETHOD_(
int,
Find)(THIS_
const wchar_t* pszSub,
int nStart DEF_VAL(0)) SCONST;
224 STDMETHOD_(
wchar_t*,
GetBuffer)(THIS_
int nMinBufLength DEF_VAL(-1));
228 STDMETHOD_(
void,
ReleaseBuffer)(THIS_
int nNewLength DEF_VAL(-1));
237 STDMETHOD_(
void,
SetLength)(THIS_
int nLength);
241 STDMETHOD_(
void,
Copy)(THIS_
const IStringW* src);
245 STDMETHOD_(
void,
Assign)(THIS_ LPCWSTR src);
250 STDMETHOD_(
void,
Assign2)(THIS_ LPCWSTR src,
int nLen);
257 STDMETHOD_(
void,
ToUpper)(THIS) OVERRIDE;
260 STDMETHOD_(
void,
ToLower)(THIS) OVERRIDE;
264 STDMETHOD_(
void,
TrimRight)(THIS_
wchar_t chTarget DEF_VAL(VK_SPACE)) OVERRIDE;
268 STDMETHOD_(
void,
TrimLeft)(THIS_
wchar_t chTarget DEF_VAL(VK_SPACE)) OVERRIDE;
272 STDMETHOD_(
void,
Trim)(THIS_
wchar_t chTarget DEF_VAL(VK_SPACE)) OVERRIDE;
276 STDMETHOD_(
void,
AppendChar)(THIS_
wchar_t ch) OVERRIDE;
281 STDMETHOD_(
void,
AppendStr)(THIS_
const wchar_t* pszStr,
int nLen DEF_VAL(-1)) OVERRIDE;
284 STDMETHOD_(
void,
Release)(THIS) OVERRIDE;
288 STDMETHOD_(UINT,
ToUint)(CTHIS) SCONST OVERRIDE;
292 STDMETHOD_(
long,
ToLong)(CTHIS) SCONST OVERRIDE;
296 STDMETHOD_(
int,
ToInt)(CTHIS) SCONST OVERRIDE;
300 STDMETHOD_(
float,
ToFloat)(CTHIS) SCONST OVERRIDE;
304 STDMETHOD_(
double,
ToDouble)(CTHIS) SCONST OVERRIDE;
308 STDMETHOD_(BOOL,
ToBool)(CTHIS) SCONST OVERRIDE;
362 BOOL __cdecl
Format(HINSTANCE hInst, UINT nFormatID, ...);
368 void __cdecl
AppendFormat(HINSTANCE hInst, UINT nFormatID, ...);
384 operator const wchar_t*()
const;
610 SASSERT(psz != NULL);
622 SASSERT(psz != NULL);
654 int GetAllocLength()
const;
659 static int SafeStrlen(
const wchar_t* psz);
663 void Preallocate(
int nLength);
672 TStringData* GetData()
const;
679 void InitFromIString(
const IStringW *stringSrc);
685 BOOL _Format(
const wchar_t* pszFormat, va_list & args);
690 void _AppendFormat(
const wchar_t* pszFormat, va_list & args);
707 void AllocCopy(
SStringW& dest,
int nCopyLen,
int nCopyIndex,
int nExtraLen)
const;
712 void AssignCopy(
int nSrcLen,
const wchar_t* pszSrcData);
720 bool ConcatCopy(
int nSrc1Len,
const wchar_t* pszSrc1Data,
int nSrc2Len,
const wchar_t* pszSrc2Data);
725 void ConcatInPlace(
int nSrcLen,
const wchar_t* pszSrcData);
728 void CopyBeforeWrite();
733 bool AllocBeforeWrite(
int nLen);
738 bool AllocBuffer(
int nLength);
743 bool ReallocBuffer(
int nNewLength);
755 static TStringData* AllocData(
int nLength, TStringData* pOldData = NULL);
759 static void ReleaseData(TStringData* pData);
A class representing an ASCII string.
SStringW()
Default constructor.
void Empty()
Empties the string.
friend bool __stdcall operator==(const SStringW &s1, const wchar_t *s2)
Overloaded equality operator between an SStringW object and a character array.
void Assign2(LPCWSTR src, int nLen)
Assigns a substring of a character array to the string.
int CompareNoCase(const wchar_t *psz) SCONST
Compares the string with another string, ignoring case.
void ReleaseBuffer(int nNewLength=-1)
Releases the buffer and sets the new length of the string.
static bool IsBlankChar(const wchar_t &c)
Checks if a character is a blank character.
void SetLength(int nLength)
Sets the length of the string.
void TrimBlank()
Trims leading and trailing whitespace characters from the string.
friend SStringW __stdcall operator+(const SStringW &string1, wchar_t ch)
Overloaded addition operator between an SStringW object and a single character.
LPVOID GetPrivData() SCONST
Retrieves private data associated with the string.
long ToLong() SCONST OVERRIDE
Converts the string to a long integer.
int Remove(wchar_t chRemove)
Removes all occurrences of a character from the string.
friend bool __stdcall operator==(const SStringW &s1, const SStringW &s2)
Overloaded equality operator between two SStringW objects.
friend SStringW __stdcall operator+(wchar_t ch, const SStringW &string)
Overloaded addition operator between a single character and an SStringW object.
void AppendChar(wchar_t ch) OVERRIDE
Appends a character to the string.
friend SStringW __stdcall operator+(const SStringW &string, const wchar_t *psz)
Overloaded addition operator between an SStringW object and a character array.
SStringW & operator=(const SStringW &stringSrc)
Overloaded assignment operator from another SStringW object.
int Replace(const wchar_t *pszOld, const wchar_t *pszNew)
Replaces all occurrences of a substring with another substring.
friend bool __stdcall operator<=(const SStringW &s1, const SStringW &s2)
Overloaded less-than-or-equal-to operator between two SStringW objects.
const wchar_t * c_str() SCONST
Retrieves a C-style string representation of the string.
int ReplaceChar(wchar_t chOld, wchar_t chNew)
Replaces all occurrences of a character with another character.
BOOL IsEmpty() SCONST
Checks if the string is empty.
int Compare(const wchar_t *psz) SCONST
Compares the string with another string.
wchar_t * GetBufferSetLength(int nNewLength)
Retrieves a modifiable buffer for the string and sets the new length.
void TrimLeft(wchar_t chTarget=VK_SPACE) OVERRIDE
Trims leading whitespace characters from the string.
void Copy(const IStringW *src)
Copies the contents of another string into this string.
friend bool __stdcall operator>=(const SStringW &s1, const SStringW &s2)
Overloaded greater-than-or-equal-to operator between two SStringW objects.
friend bool __stdcall operator>=(const wchar_t *s1, const SStringW &s2)
Overloaded greater-than-or-equal-to operator between a character array and an SStringW object.
friend bool __stdcall operator<=(const SStringW &s1, const wchar_t *s2)
Overloaded less-than-or-equal-to operator between an SStringW object and a character array.
void Trim(wchar_t chTarget=VK_SPACE) OVERRIDE
Trims leading and trailing whitespace characters from the string.
friend bool __stdcall operator<=(const wchar_t *s1, const SStringW &s2)
Overloaded less-than-or-equal-to operator between a character array and an SStringW object.
int FindChar(wchar_t ch, int nStart=0) SCONST
Finds the first occurrence of a character in the string.
double ToDouble() SCONST OVERRIDE
Converts the string to a double.
friend bool __stdcall operator>(const SStringW &s1, const SStringW &s2)
Overloaded greater-than operator between two SStringW objects.
SStringW Mid(int nFirst) const
Extracts a substring from the string.
static int SafeStrlen(const wchar_t *psz)
Computes the length of a null-terminated string safely.
friend bool __stdcall operator>(const wchar_t *s1, const SStringW &s2)
Overloaded greater-than operator between a character array and an SStringW object.
BOOL __cdecl Format(HINSTANCE hInst, UINT nFormatID,...)
Formats a string using a format string and variable arguments.
friend bool __stdcall operator<(const wchar_t *s1, const SStringW &s2)
Overloaded less-than operator between a character array and an SStringW object.
SStringW & MakeLower()
Converts the string to lowercase.
friend SStringW __stdcall operator+(const wchar_t *psz, const SStringW &string)
Overloaded addition operator between a character array and an SStringW object.
bool EndsWith(const SStringW &suffix, bool IgnoreCase=false) const
Checks if the string ends with a specified suffix.
bool ConcatCopy(int nSrc1Len, const wchar_t *pszSrc1Data, int nSrc2Len, const wchar_t *pszSrc2Data)
Concatenates two substrings and copies the result to the string.
friend bool __stdcall operator>(const SStringW &s1, const wchar_t *s2)
Overloaded greater-than operator between an SStringW object and a character array.
SStringW & Append(const SStringW &src)
Appends another SStringW object to the string.
int InsertChar(int nIndex, wchar_t ch)
Inserts a character at a specified index.
void SetAt(int nIndex, wchar_t ch)
Sets the character at a specified index.
friend bool __stdcall operator<(const SStringW &s1, const wchar_t *s2)
Overloaded less-than operator between an SStringW object and a character array.
friend bool __stdcall operator<(const SStringW &s1, const SStringW &s2)
Overloaded less-than operator between two SStringW objects.
void TrimRight(wchar_t chTarget=VK_SPACE) OVERRIDE
Trims trailing whitespace characters from the string.
BOOL ToBool() SCONST OVERRIDE
Converts the string to a boolean.
friend bool __stdcall operator!=(const SStringW &s1, const SStringW &s2)
Overloaded inequality operator between two SStringW objects.
int Insert(int nIndex, const wchar_t *psz)
Inserts a substring at a specified index.
TStringData * GetData() const
Retrieves the data structure of the string.
float ToFloat() SCONST OVERRIDE
Converts the string to a float.
void Assign(LPCWSTR src)
Assigns a character array to the string.
SStringW Right(int nCount) const
Extracts the rightmost part of the string.
void Release() OVERRIDE
Releases the string and its resources.
SStringW & MakeUpper()
Converts the string to uppercase.
wchar_t * GetBuffer(int nMinBufLength=-1)
Retrieves a modifiable buffer for the string.
int Delete(int nIndex, int nCount=1)
Deletes a substring from the string.
int ToInt() SCONST OVERRIDE
Converts the string to an integer.
const SStringW & operator+=(const wchar_t *psz)
Overloaded concatenation operator with a character array.
friend bool __stdcall operator==(const wchar_t *s1, const SStringW &s2)
Overloaded equality operator between a character array and an SStringW object.
wchar_t * m_pszData
Pointer to the ref counted string data.
UINT ToUint() SCONST OVERRIDE
Converts the string to an unsigned integer.
void __cdecl AppendFormat(HINSTANCE hInst, UINT nFormatID,...)
Appends formatted data to the string using a format string and variable arguments.
int GetLength() SCONST
Retrieves the length of the string.
int Find(const wchar_t *pszSub, int nStart=0) SCONST
Finds the first occurrence of a substring in the string.
wchar_t GetAt(int nIndex) SCONST
Retrieves the character at a specified index.
SStringW Left(int nCount) const
Extracts the leftmost part of the string.
int ReverseFind(wchar_t ch) SCONST
Finds the last occurrence of a character in the string.
void ToUpper() OVERRIDE
Converts the string to uppercase.
wchar_t operator[](int nIndex) const
Retrieves the character at a specified index.
friend SStringW __stdcall operator+(const SStringW &string1, const SStringW &string2)
Overloaded addition operator between two SStringW objects.
void ToLower() OVERRIDE
Converts the string to lowercase.
friend bool __stdcall operator>=(const SStringW &s1, const wchar_t *s2)
Overloaded greater-than-or-equal-to operator between an SStringW object and a character array.
void AppendStr(const wchar_t *pszStr, int nLen=-1) OVERRIDE
Appends a substring to the string.
friend bool __stdcall operator!=(const wchar_t *s1, const SStringW &s2)
Overloaded inequality operator between a character array and an SStringW object.
friend bool __stdcall operator!=(const SStringW &s1, const wchar_t *s2)
Overloaded inequality operator between an SStringW object and a character array.
bool StartsWith(const SStringW &prefix, bool IgnoreCase=false) const
Checks if the string starts with a specified prefix.
BOOL LoadString(UINT nID, HINSTANCE hInst)
Loads a string resource from a module.
Character traits for ASCII strings.
static int Compare(const wchar_t *psz1, const wchar_t *psz2)
Compares two strings lexicographically.
static wchar_t * CharNext(wchar_t *psz)
Moves to the next character in a string.
static wchar_t CharLower(wchar_t ch)
Converts a character to lowercase.
static size_t StrLen(const wchar_t *psz)
Computes the length of a null-terminated string.
static int CompareNoCase(const wchar_t *psz1, const wchar_t *psz2)
Compares two strings lexicographically, ignoring case.
static int LoadString(HINSTANCE hInst, UINT uID, wchar_t *lpBuffer, int nBufferMax)
Loads a string resource from a module.
static wchar_t * StrLower(wchar_t *psz)
Converts a string to lowercase.
static const wchar_t * StrRChr(const wchar_t *psz, wchar_t ch)
Finds the last occurrence of a character in a string.
static wchar_t * StrUpper(wchar_t *psz)
Converts a string to uppercase.
static const wchar_t * StrChr(const wchar_t *psz, wchar_t ch)
Finds the first occurrence of a character in a string.
static int Format(wchar_t **ppszDst, const wchar_t *pszFormat, va_list &args)
Formats a string using a format string and variable arguments.
static wchar_t CharUpper(wchar_t ch)
Converts a character to uppercase.
static int IsSpace(wchar_t ch)
Checks if a character is a whitespace character.
static const wchar_t * StrStr(const wchar_t *psz, const wchar_t *psz2)
Finds the first occurrence of a substring in a string.