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