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...

Functions

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)
 

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.

◆ 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.

◆ 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:

◆ 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