Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::CStringImp Class Reference

Low-level string helper functions used by engine utilities. More...

#include <Utils/CStringImp.h>

Static Public Member Functions

template<class T>
static int length (T *pString)
 Count characters before the null terminator.
template<class T>
static int find (T *pString, T pCharSearch, int begin=0)
 Find a character in a null-terminated string.
template<class T>
static int find (T *pString, T *pKeySearch, int begin=0)
 Find a substring in a null-terminated string.
template<class T>
static void trimleft (T *pString)
 Remove leading whitespace characters from a mutable string.
template<class T>
static void trimright (T *pString)
 Remove trailing whitespace characters from a mutable string.
template<class T>
static void trimleft (T *pString, T delChar)
 Remove leading occurrences of a character.
template<class T>
static void trimright (T *pString, T delChar)
 Remove trailing occurrences of a character.
template<class T>
static void trim (T *pString)
 Remove leading and trailing whitespace characters.
template<class T>
static void trim (T *pString, T delChar)
 Remove leading and trailing occurrences of a character.
template<class T>
static int countEntry (T *pString, T entry, int begin=0)
 Count occurrences of a character.
template<class T1, class T2>
static int copy (T1 *pStringDst, T2 *pStringSrc)
 Copy a null-terminated string while converting character type.
template<class T1, class T2>
static int copyAt (T1 *pStringDst, T2 *pStringSrc, int at)
 Copy a source string into a destination string at an index.
template<class T1, class T2>
static int cat (T1 *pStringDst, T2 *pStringSrc)
 Append a source string to a destination string.
template<class T>
static int comp (T *pString1, T *pString2)
 Compare two null-terminated strings by raw character bytes.
template<class T>
static int comp (T *pString1, T *pString2, int len)
 Compare a fixed number of characters by raw character bytes.
template<class T1, class T2>
static int mid (T1 *pStringDst, T2 *pStringSrc, int begin, int end)
 Copy a substring range.
template<class T1, class T2>
static int getBlock (T1 *pStringDst, T2 *pStringSrc, T2 *pBlock, int begin=0)
 Extract text between two occurrences of the same delimiter.
template<class T1, class T2>
static int findBlock (T1 *pStringDst, T2 *pStringSrc, T2 *pBlock, int begin=0)
 Extract text from a balanced block such as {} or [].
template<class T1, class T2>
static int findBlockString (T1 *pStringDst, T2 *pStringSrc, T2 *pBlock1, T2 *pBlock2, int begin=0)
 Extract text from a balanced block with string begin/end markers.
template<class T>
static void inorgeLoopChar (T *pString, T charLoop)
 Collapse repeated occurrences of a character to a single occurrence.
template<class T>
static bool split (T *lpStrResult, const T *lpStringSearch, const T *lpStrSplit, int *pos)
 Split a string incrementally using any character from a delimiter set.
static int splitString (const char *stringSplit, const char *search, std::vector< std::string > &result)
 Split a narrow string into a vector.
static std::string replaceAll (std::string &string, const std::string &from, const std::string &to)
 Replace every occurrence of a substring.
static int splitString (const wchar_t *stringSplit, const wchar_t *search, std::vector< std::wstring > &result)
 Split a wide string into a vector.
static bool format (char *lpString, const char *lpStringFormat,...)
 Format text into a caller-provided buffer.
template<class T>
static bool parseToInt (T *lpString, int *result)
 Parse a signed integer from a string.
template<class T>
static bool parseToFloat (T *lpString, float *result)
 Parse a floating-point value from a string.
template<class T>
static bool parseToUInt (T *lpString, int *result)
 Parse an unsigned integer from a string.
template<class T>
static bool parseFromHex (T *lpString, int *result)
 Parse a hexadecimal integer from a string.
template<class T>
static void toLower (T *lpString)
 Convert a mutable string to lowercase in place.
template<class T>
static void toUpper (T *lpString)
 Convert a mutable string to uppercase in place.
template<class T1, class T2>
static void getFolderPath (T1 *dstString, T2 *lpString)
 Extract the folder path from a file path.
template<class T1, class T2>
static void getFileName (T1 *dstString, T2 *lpString)
 Extract the file name from a path.
template<class T1, class T2>
static void getFileNameExt (T1 *dstString, T2 *lpString)
 Extract the file extension from a path.
template<class T1, class T2>
static void getFileNameNoExt (T1 *dstString, T2 *lpString)
 Extract the file name without extension from a path.
template<class T>
static void shortName (T *dest, const T *name, int maxchar)
 Shorten a name to a maximum character count.
template<class T>
static void replaceText (T *result, const T *string, const T *search, const T *replace)
 Replace all occurrences of text in a source buffer.
static wchar_t utf8Char2Unicode (const char *&str)
 Decode one UTF-8 character and advance the source pointer.
static unsigned short * getUnicodeString (const wchar_t *src)
 Convert a wide string to an unsigned 16-bit Unicode buffer.
static void convertUTF8ToUnicode (const char *src, wchar_t *dst)
 Convert UTF-8 text to a wide-character buffer.
static int getUnicodeStringSize (const char *src)
 Calculate the wide-character length required for a UTF-8 string.
static void convertUnicodeToUTF8 (const wchar_t *src, char *dst)
 Convert wide-character text to UTF-8.
static int getUTF8StringSize (const wchar_t *src)
 Calculate the UTF-8 byte length required for a wide string.
static void replaceExt (char *lpPath, const char *lpExt)
 Replace the extension portion of a file name in place.
static void replacePathExt (char *lpPath, const char *lpExt)
 Replace the extension portion of a full path in place.
static int findStringInList (std::vector< std::string > &listString, const char *find)
 Find a string in a vector.
static void replaceString (std::string &subject, const std::string &search, const std::string &replace)
 Replace all occurrences of a substring in a std::string.
static const std::string & convertUnicodeToUTF8 (const wchar_t *src)
 Convert wide-character text to UTF-8 using shared temporary storage.
static const std::wstring & convertUTF8ToUnicode (const char *src)
 Convert UTF-8 text to wide-character text using shared temporary storage.
static const std::string & toLower (const std::string &s)
 Return a lowercase copy of a narrow string.
static const std::wstring & toLower (const std::wstring &s)
 Return a lowercase copy of a wide string.
static const std::string & toUpper (const std::string &s)
 Return an uppercase copy of a narrow string.
static const std::wstring & toUpper (const std::wstring &s)
 Return an uppercase copy of a wide string.
static const std::string & formatThousand (int n, bool useK, bool useM)
 Format a number with thousand separators or compact suffixes.

Detailed Description

Low-level string helper functions used by engine utilities.

Most template functions operate on null-terminated mutable buffers and assume the destination buffer is large enough for the result. Functions returning const std::string& or const std::wstring& use shared temporary storage and should be copied before the next call that may reuse that storage.

Member Function Documentation

◆ cat()

template<class T1, class T2>
int Skylicht::CStringImp::cat ( T1 * pStringDst,
T2 * pStringSrc )
inlinestatic

Append a source string to a destination string.

Returns
Number of appended characters.

◆ comp() [1/2]

template<class T>
int Skylicht::CStringImp::comp ( T * pString1,
T * pString2 )
inlinestatic

Compare two null-terminated strings by raw character bytes.

Returns
0 if equal, a positive value if the first string is greater, otherwise negative.

◆ comp() [2/2]

template<class T>
int Skylicht::CStringImp::comp ( T * pString1,
T * pString2,
int len )
inlinestatic

Compare a fixed number of characters by raw character bytes.

Returns
Result of memcmp.

◆ convertUnicodeToUTF8() [1/2]

const std::string & Skylicht::CStringImp::convertUnicodeToUTF8 ( const wchar_t * src)
static

Convert wide-character text to UTF-8 using shared temporary storage.

Parameters
srcSource wide string.
Returns
UTF-8 string in shared temporary storage.

◆ convertUnicodeToUTF8() [2/2]

void Skylicht::CStringImp::convertUnicodeToUTF8 ( const wchar_t * src,
char * dst )
static

Convert wide-character text to UTF-8.

Parameters
srcWide-character source string.
dstDestination UTF-8 buffer.

◆ convertUTF8ToUnicode() [1/2]

const std::wstring & Skylicht::CStringImp::convertUTF8ToUnicode ( const char * src)
static

Convert UTF-8 text to wide-character text using shared temporary storage.

Parameters
srcSource UTF-8 string.
Returns
Wide string in shared temporary storage.

◆ convertUTF8ToUnicode() [2/2]

void Skylicht::CStringImp::convertUTF8ToUnicode ( const char * src,
wchar_t * dst )
static

Convert UTF-8 text to a wide-character buffer.

Parameters
srcUTF-8 source string.
dstDestination wide-character buffer.

◆ copy()

template<class T1, class T2>
int Skylicht::CStringImp::copy ( T1 * pStringDst,
T2 * pStringSrc )
inlinestatic

Copy a null-terminated string while converting character type.

Template Parameters
T1Destination character type.
T2Source character type.
Parameters
pStringDstDestination buffer.
pStringSrcSource string, or null.
Returns
Number of characters copied, excluding the terminator.

◆ copyAt()

template<class T1, class T2>
int Skylicht::CStringImp::copyAt ( T1 * pStringDst,
T2 * pStringSrc,
int at )
inlinestatic

Copy a source string into a destination string at an index.

Returns
New end index, or 0 when the input is invalid.

◆ countEntry()

template<class T>
int Skylicht::CStringImp::countEntry ( T * pString,
T entry,
int begin = 0 )
inlinestatic

Count occurrences of a character.

Template Parameters
TCharacter type.
Parameters
pStringString to scan.
entryCharacter to count.
beginStart index.
Returns
Number of occurrences.

◆ find() [1/2]

template<class T>
int Skylicht::CStringImp::find ( T * pString,
T * pKeySearch,
int begin = 0 )
inlinestatic

Find a substring in a null-terminated string.

Template Parameters
TCharacter type.
Parameters
pStringString to search.
pKeySearchNull-terminated substring to find.
beginStart index.
Returns
First matching index, or -1 when not found.

◆ find() [2/2]

template<class T>
int Skylicht::CStringImp::find ( T * pString,
T pCharSearch,
int begin = 0 )
inlinestatic

Find a character in a null-terminated string.

Template Parameters
TCharacter type.
Parameters
pStringString to search.
pCharSearchCharacter to find.
beginStart index.
Returns
Character index, or -1 when not found.

◆ findBlock()

template<class T1, class T2>
int Skylicht::CStringImp::findBlock ( T1 * pStringDst,
T2 * pStringSrc,
T2 * pBlock,
int begin = 0 )
inlinestatic

Extract text from a balanced block such as {} or [].

Returns
Index after the closing delimiter, or -1 when no balanced block exists.

◆ findBlockString()

template<class T1, class T2>
int Skylicht::CStringImp::findBlockString ( T1 * pStringDst,
T2 * pStringSrc,
T2 * pBlock1,
T2 * pBlock2,
int begin = 0 )
inlinestatic

Extract text from a balanced block with string begin/end markers.

Returns
Index after the closing marker, or -1 when no balanced block exists.

◆ findStringInList()

int Skylicht::CStringImp::findStringInList ( std::vector< std::string > & listString,
const char * find )
static

Find a string in a vector.

Parameters
listStringVector to search.
findText to find.
Returns
Index of the match, or -1 when not found.

◆ format()

bool Skylicht::CStringImp::format ( char * lpString,
const char * lpStringFormat,
... )
static

Format text into a caller-provided buffer.

Parameters
lpStringDestination buffer.
lpStringFormatPrintf-style format string.
Returns
True when formatting succeeds.

◆ formatThousand()

const std::string & Skylicht::CStringImp::formatThousand ( int n,
bool useK,
bool useM )
static

Format a number with thousand separators or compact suffixes.

Parameters
nNumber to format.
useKAllow compact K suffix.
useMAllow compact M suffix.
Returns
Formatted number in shared temporary storage.

◆ getBlock()

template<class T1, class T2>
int Skylicht::CStringImp::getBlock ( T1 * pStringDst,
T2 * pStringSrc,
T2 * pBlock,
int begin = 0 )
inlinestatic

Extract text between two occurrences of the same delimiter.

Returns
Index after the closing delimiter, or -1 when not found.

◆ getFileName()

template<class T1, class T2>
void Skylicht::CStringImp::getFileName ( T1 * dstString,
T2 * lpString )
inlinestatic

Extract the file name from a path.

Parameters
dstStringDestination buffer.
lpStringSource path.

◆ getFileNameExt()

template<class T1, class T2>
void Skylicht::CStringImp::getFileNameExt ( T1 * dstString,
T2 * lpString )
inlinestatic

Extract the file extension from a path.

Parameters
dstStringDestination buffer.
lpStringSource path.

◆ getFileNameNoExt()

template<class T1, class T2>
void Skylicht::CStringImp::getFileNameNoExt ( T1 * dstString,
T2 * lpString )
inlinestatic

Extract the file name without extension from a path.

Parameters
dstStringDestination buffer.
lpStringSource path.

◆ getFolderPath()

template<class T1, class T2>
void Skylicht::CStringImp::getFolderPath ( T1 * dstString,
T2 * lpString )
inlinestatic

Extract the folder path from a file path.

Parameters
dstStringDestination buffer.
lpStringSource path.

◆ getUnicodeString()

unsigned short * Skylicht::CStringImp::getUnicodeString ( const wchar_t * src)
static

Convert a wide string to an unsigned 16-bit Unicode buffer.

Parameters
srcSource wide string.
Returns
Newly allocated or internal Unicode buffer as implemented by the source file.

◆ getUnicodeStringSize()

int Skylicht::CStringImp::getUnicodeStringSize ( const char * src)
static

Calculate the wide-character length required for a UTF-8 string.

Parameters
srcUTF-8 source string.
Returns
Required wide-character count.

◆ getUTF8StringSize()

int Skylicht::CStringImp::getUTF8StringSize ( const wchar_t * src)
static

Calculate the UTF-8 byte length required for a wide string.

Parameters
srcWide-character source string.
Returns
Required byte count.

◆ inorgeLoopChar()

template<class T>
void Skylicht::CStringImp::inorgeLoopChar ( T * pString,
T charLoop )
inlinestatic

Collapse repeated occurrences of a character to a single occurrence.

Parameters
pStringString buffer to modify.
charLoopRepeated character to collapse.

◆ length()

template<class T>
int Skylicht::CStringImp::length ( T * pString)
inlinestatic

Count characters before the null terminator.

Template Parameters
TCharacter type.
Parameters
pStringNull-terminated string.
Returns
Character count, excluding the terminator.

◆ mid()

template<class T1, class T2>
int Skylicht::CStringImp::mid ( T1 * pStringDst,
T2 * pStringSrc,
int begin,
int end )
inlinestatic

Copy a substring range.

Parameters
pStringDstDestination buffer.
pStringSrcSource string.
beginFirst source index.
endOne-past-last source index.
Returns
Number of copied characters.

◆ parseFromHex()

template<class T>
bool Skylicht::CStringImp::parseFromHex ( T * lpString,
int * result )
inlinestatic

Parse a hexadecimal integer from a string.

Returns
True when parsing succeeds.

◆ parseToFloat()

template<class T>
bool Skylicht::CStringImp::parseToFloat ( T * lpString,
float * result )
inlinestatic

Parse a floating-point value from a string.

Returns
True when parsing succeeds.

◆ parseToInt()

template<class T>
bool Skylicht::CStringImp::parseToInt ( T * lpString,
int * result )
inlinestatic

Parse a signed integer from a string.

Returns
True when parsing succeeds.

◆ parseToUInt()

template<class T>
bool Skylicht::CStringImp::parseToUInt ( T * lpString,
int * result )
inlinestatic

Parse an unsigned integer from a string.

Returns
True when parsing succeeds.

◆ replaceAll()

std::string Skylicht::CStringImp::replaceAll ( std::string & string,
const std::string & from,
const std::string & to )
static

Replace every occurrence of a substring.

Parameters
stringSource string to process.
fromSubstring to replace.
toReplacement text.
Returns
Replaced string.

◆ replaceExt()

void Skylicht::CStringImp::replaceExt ( char * lpPath,
const char * lpExt )
static

Replace the extension portion of a file name in place.

Parameters
lpPathMutable path buffer.
lpExtNew extension.

◆ replacePathExt()

void Skylicht::CStringImp::replacePathExt ( char * lpPath,
const char * lpExt )
static

Replace the extension portion of a full path in place.

Parameters
lpPathMutable path buffer.
lpExtNew extension.

◆ replaceString()

void Skylicht::CStringImp::replaceString ( std::string & subject,
const std::string & search,
const std::string & replace )
static

Replace all occurrences of a substring in a std::string.

Parameters
subjectString to modify.
searchText to find.
replaceReplacement text.

◆ replaceText()

template<class T>
void Skylicht::CStringImp::replaceText ( T * result,
const T * string,
const T * search,
const T * replace )
inlinestatic

Replace all occurrences of text in a source buffer.

Parameters
resultDestination buffer.
stringSource string.
searchText to find.
replaceReplacement text.

◆ shortName()

template<class T>
void Skylicht::CStringImp::shortName ( T * dest,
const T * name,
int maxchar )
inlinestatic

Shorten a name to a maximum character count.

When truncated, the last one or two characters are replaced with dots.

◆ split()

template<class T>
bool Skylicht::CStringImp::split ( T * lpStrResult,
const T * lpStringSearch,
const T * lpStrSplit,
int * pos )
inlinestatic

Split a string incrementally using any character from a delimiter set.

Parameters
lpStrResultDestination buffer for the current token.
lpStringSearchSource string.
lpStrSplitNull-terminated delimiter character set.
posIn/out current scan position.
Returns
True when a token was produced, false when no more tokens exist.

◆ splitString() [1/2]

int Skylicht::CStringImp::splitString ( const char * stringSplit,
const char * search,
std::vector< std::string > & result )
static

Split a narrow string into a vector.

Parameters
stringSplitDelimiter characters.
searchSource string.
resultReceives split tokens.
Returns
Number of tokens.

◆ splitString() [2/2]

int Skylicht::CStringImp::splitString ( const wchar_t * stringSplit,
const wchar_t * search,
std::vector< std::wstring > & result )
static

Split a wide string into a vector.

Parameters
stringSplitDelimiter characters.
searchSource string.
resultReceives split tokens.
Returns
Number of tokens.

◆ toLower() [1/2]

const std::string & Skylicht::CStringImp::toLower ( const std::string & s)
static

Return a lowercase copy of a narrow string.

Parameters
sSource string.
Returns
Lowercase text in shared temporary storage.

◆ toLower() [2/2]

const std::wstring & Skylicht::CStringImp::toLower ( const std::wstring & s)
static

Return a lowercase copy of a wide string.

Parameters
sSource string.
Returns
Lowercase text in shared temporary storage.

◆ toUpper() [1/2]

const std::string & Skylicht::CStringImp::toUpper ( const std::string & s)
static

Return an uppercase copy of a narrow string.

Parameters
sSource string.
Returns
Uppercase text in shared temporary storage.

◆ toUpper() [2/2]

const std::wstring & Skylicht::CStringImp::toUpper ( const std::wstring & s)
static

Return an uppercase copy of a wide string.

Parameters
sSource string.
Returns
Uppercase text in shared temporary storage.

◆ trim() [1/2]

template<class T>
void Skylicht::CStringImp::trim ( T * pString)
inlinestatic

Remove leading and trailing whitespace characters.

Template Parameters
TCharacter type.
Parameters
pStringString buffer to modify.

◆ trim() [2/2]

template<class T>
void Skylicht::CStringImp::trim ( T * pString,
T delChar )
inlinestatic

Remove leading and trailing occurrences of a character.

Template Parameters
TCharacter type.
Parameters
pStringString buffer to modify.
delCharCharacter to trim.

◆ trimleft() [1/2]

template<class T>
void Skylicht::CStringImp::trimleft ( T * pString)
inlinestatic

Remove leading whitespace characters from a mutable string.

Template Parameters
TCharacter type.
Parameters
pStringString buffer to modify.

◆ trimleft() [2/2]

template<class T>
void Skylicht::CStringImp::trimleft ( T * pString,
T delChar )
inlinestatic

Remove leading occurrences of a character.

Template Parameters
TCharacter type.
Parameters
pStringString buffer to modify.
delCharCharacter to trim.

◆ trimright() [1/2]

template<class T>
void Skylicht::CStringImp::trimright ( T * pString)
inlinestatic

Remove trailing whitespace characters from a mutable string.

Template Parameters
TCharacter type.
Parameters
pStringString buffer to modify.

◆ trimright() [2/2]

template<class T>
void Skylicht::CStringImp::trimright ( T * pString,
T delChar )
inlinestatic

Remove trailing occurrences of a character.

Template Parameters
TCharacter type.
Parameters
pStringString buffer to modify.
delCharCharacter to trim.

◆ utf8Char2Unicode()

wchar_t Skylicht::CStringImp::utf8Char2Unicode ( const char *& str)
static

Decode one UTF-8 character and advance the source pointer.

Parameters
strIn/out UTF-8 source pointer.
Returns
Decoded Unicode character.

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