Utilities to operate strings.
More...
|
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) |
|
Utilities to operate strings.
◆ 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
-
CharT | The character type of the string. |
- Parameters
-
[in] | s | The input string. |
[in] | t | The character to be replaced. |
[in] | replacement | The 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
◆ 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] | vector | The 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
-
T | The type of the vector elements. |
- Parameters
-
[in] | vector | The vector of strings to join. |
[in] | delimiter | The 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
-
CharT | The character type of the string. |
- Parameters
-
[in] | s | The input string. |
[in] | t | The character to be replaced. |
[in] | replacement | The replacement character (default is '\0'). |
- Returns
- The modified string with leading occurrences replaced.
- See also
- rReplace
◆ 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] | orig | The original string. |
- Returns
- The widened string.
◆ 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
-
CharT | The character type of the string. |
- Parameters
-
[in] | s | The input string. |
[in] | t | The character to be replaced. |
[in] | replacement | The 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
◆ 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] | s | The string to be split. |
[in] | separator | The separator to split the string by. |
- Returns
- A vector of substrings.
◆ 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] | s | The string view to be split. |
[in] | separator | The 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] | unicode | The 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
◆ utf8ToUnicode()
int steppable::__internals::stringUtils::utf8ToUnicode |
( |
const std::string & | utf8_code | ) |
|
Converts a UTF-8 encoded string to a Unicode string.
- Parameters
-
[in] | utf8_code | The 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 | ) |
|