Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
steppable::__internals::stringUtils Namespace Reference

Utilities to operate strings. More...

Classes

class  GraphemeIterator

Functions

bool isZeroWidthCharacter (uint32_t codepoint)
 Checks if a Unicode code point represents a zero-width character.
bool isEmojiBase (uint32_t cp)
bool utf8Decode (const std::string &s, size_t &i, uint32_t &cp)
bool isClusterExtender (uint32_t cp)
uint32_t getCodepoint (const std::string &str, size_t &i)
 Decodes a UTF-8 encoded string into a Unicode code point.
size_t getUnicodeDisplayWidth (const std::string &utf8Str)
 Calculates the display width of a UTF-8 encoded string.
std::string makeWider (const std::string &orig)
 Makes the given string wider by adding 2 spaces between each character.
int utf8ToUnicode (const std::string &utf8_code)
 Converts a UTF-8 encoded string to a Unicode string.
std::string unicodeToUtf8 (int unicode)
 Converts a Unicode character to UTF-8 encoding.
template<typename CharT>
auto split (std::basic_string< CharT > s, const CharT separator)
 Splits a string into substrings based on a separator.
template<typename CharT>
auto split (std::basic_string_view< CharT > s, const CharT separator)
 Splits a string view into substrings based on a separator.
template<typename CharT>
auto rReplace (const std::basic_string< CharT > s, const CharT t, const CharT replacement='\0')
 Replaces the trailing occurrences of a character in a string with another character.
template<typename CharT>
auto lReplace (const std::basic_string< CharT > s, const CharT t, const CharT replacement='\0')
 Replaces the leading occurrences of a character in a string with a replacement character.
template<typename CharT>
auto bothEndsReplace (const std::basic_string< CharT > s, const CharT t, const CharT replacement='\0')
 Replaces the leading and trailing occurrences of a character in a string with a replacement character.
template<typename T>
auto join (const std::vector< T > &vector, const std::string &delimiter)
 Joins a vector of elements into a single string using a delimiter.
std::vector< std::string > duplicates (const std::vector< std::string > &vector)
 Gets the duplicates in a vector of strings.
template<typename ValueType>
std::string vectorToString (const std::vector< ValueType > &vector)
template<concepts::Numeric T>
toNumeric (const std::string &s)

Detailed Description

Utilities to operate strings.

Function Documentation

◆ bothEndsReplace()

template<typename CharT>
auto steppable::__internals::stringUtils::bothEndsReplace ( const std::basic_string< CharT > s,
const CharT t,
const CharT replacement = '\0' )

Replaces the leading and trailing occurrences of a character in a string with a replacement character.

Template Parameters
CharTThe character type of the string.
Parameters
[in]sThe input string.
[in]tThe character to be replaced.
[in]replacementThe replacement character (default is '\0').
Returns
The modified string with leading and trailing occurrences replaced.
Note
This function is equivalent to calling lReplace(rReplace(s, t, replacement), t, replacement).
See also
lReplace
rReplace
Here is the call graph for this function:

◆ duplicates()

std::vector< std::string > steppable::__internals::stringUtils::duplicates ( const std::vector< std::string > & vector)

Gets the duplicates in a vector of strings.

Parameters
[in]vectorThe vector of strings to check for duplicates.
Returns
A vector of strings containing the duplicates.

◆ getCodepoint()

uint32_t steppable::__internals::stringUtils::getCodepoint ( const std::string & str,
size_t & i )

Decodes a UTF-8 encoded string into a Unicode code point.

This function reads one UTF-8 encoded character from the string, starting at index i, and advances the index to the next character.

Parameters
strThe UTF-8 encoded string.
iThe current position in the string (updated after decoding).
Returns
The Unicode code point of the character at the given position.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUnicodeDisplayWidth()

size_t steppable::__internals::stringUtils::getUnicodeDisplayWidth ( const std::string & utf8Str)

Calculates the display width of a UTF-8 encoded string.

This function computes the total display width of a string, correctly handling wide, narrow, zero-width, and CJK characters. CJK characters are counted as one character.

Parameters
utf8StrThe UTF-8 encoded string.
Returns
The total display width of the string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isClusterExtender()

bool steppable::__internals::stringUtils::isClusterExtender ( uint32_t cp)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEmojiBase()

bool steppable::__internals::stringUtils::isEmojiBase ( uint32_t cp)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isZeroWidthCharacter()

bool steppable::__internals::stringUtils::isZeroWidthCharacter ( uint32_t codepoint)

Checks if a Unicode code point represents a zero-width character.

Zero-width characters do not consume display space (e.g., combining marks, zero-width spaces).

Parameters
codepointThe Unicode code point to check.
Returns
true if the code point is a zero-width character, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ join()

template<typename T>
auto steppable::__internals::stringUtils::join ( const std::vector< T > & vector,
const std::string & delimiter )

Joins a vector of elements into a single string using a delimiter.

Template Parameters
TThe type of the vector elements.
Parameters
[in]vectorThe vector of strings to join.
[in]delimiterThe delimiter to join the strings with.
Returns
The joined string.

◆ lReplace()

template<typename CharT>
auto steppable::__internals::stringUtils::lReplace ( const std::basic_string< CharT > s,
const CharT t,
const CharT replacement = '\0' )

Replaces the leading occurrences of a character in a string with a replacement character.

Template Parameters
CharTThe character type of the string.
Parameters
[in]sThe input string.
[in]tThe character to be replaced.
[in]replacementThe replacement character (default is '\0').
Returns
The modified string with leading occurrences replaced.
See also
rReplace
Here is the caller graph for this function:

◆ makeWider()

std::string steppable::__internals::stringUtils::makeWider ( const std::string & orig)

Makes the given string wider by adding 2 spaces between each character.

Parameters
[in]origThe original string.
Returns
The widened string.
Here is the caller graph for this function:

◆ rReplace()

template<typename CharT>
auto steppable::__internals::stringUtils::rReplace ( const std::basic_string< CharT > s,
const CharT t,
const CharT replacement = '\0' )

Replaces the trailing occurrences of a character in a string with another character.

This function takes a string s and replaces all trailing occurrences of the character t with the character replacement. If replacement is not provided, the trailing occurrences of t are simply removed.

Template Parameters
CharTThe character type of the string.
Parameters
[in]sThe input string.
[in]tThe character to be replaced.
[in]replacementThe character to replace t with. Default is '\0' (null character).
Returns
The modified string with trailing occurrences of t replaced by replacement.
See also
lReplace
Here is the caller graph for this function:

◆ split() [1/2]

template<typename CharT>
auto steppable::__internals::stringUtils::split ( std::basic_string< CharT > s,
const CharT separator )

Splits a string into substrings based on a separator.

Parameters
[in]sThe string to be split.
[in]separatorThe separator to split the string by.
Returns
A vector of substrings.
Here is the caller graph for this function:

◆ split() [2/2]

template<typename CharT>
auto steppable::__internals::stringUtils::split ( std::basic_string_view< CharT > s,
const CharT separator )

Splits a string view into substrings based on a separator.

Parameters
[in]sThe string view to be split.
[in]separatorThe separator to split the string view by.
Returns
A vector of substrings.

◆ toNumeric()

template<concepts::Numeric T>
T steppable::__internals::stringUtils::toNumeric ( const std::string & s)
Here is the call graph for this function:

◆ unicodeToUtf8()

std::string steppable::__internals::stringUtils::unicodeToUtf8 ( int unicode)

Converts a Unicode character to UTF-8 encoding.

Parameters
[in]unicodeThe Unicode character to be converted.
Returns
The UTF-8 encoded string representation of the Unicode character.
Note
When output goes wrong, make sure to call this function when printing!
See also
Utf8CodePage
Here is the caller graph for this function:

◆ utf8Decode()

bool steppable::__internals::stringUtils::utf8Decode ( const std::string & s,
size_t & i,
uint32_t & cp )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf8ToUnicode()

int steppable::__internals::stringUtils::utf8ToUnicode ( const std::string & utf8_code)

Converts a UTF-8 encoded string to a Unicode string.

Parameters
[in]utf8_codeThe UTF-8 encoded string to convert.
Returns
The converted Unicode string.

◆ vectorToString()

template<typename ValueType>
std::string steppable::__internals::stringUtils::vectorToString ( const std::vector< ValueType > & vector)
Untitled