Provides utilities process strings.
More...
#include <TextUtilities.hpp>
|
static std::string | trim (const std::string &str, const std::string &del) |
|
static std::string | splitExtension (std::string &str) |
|
static std::string | extractFilename (const std::string &str) |
|
static void | replace (std::string &source, const std::string &fromString, const std::string &toString) |
|
static void | replace (std::string &source, const std::string &fromChars, const char toChar) |
|
static bool | hasPrefix (const std::string &source, const std::string &prefix) |
|
static bool | hasSuffix (const std::string &source, const std::string &suffix) |
|
static std::string | join (const std::vector< std::string > &tokens, const std::string &delimiter) |
|
static std::vector< std::string > | split (const std::string &str, const std::string &delimiter, bool skipEmpty) |
|
static std::vector< std::string > | splitLines (const std::string &str, bool skipEmpty) |
|
static std::string | padInt (uint number, uint padding) |
|
static std::string | lowercase (const std::string &src) |
|
static std::string | uppercase (const std::string &src) |
|
Provides utilities process strings.
◆ extractFilename()
std::string TextUtilities::extractFilename |
( |
const std::string & |
str | ) |
|
|
static |
Extract the filename from the end of a string (extension will be included).
- Parameters
-
str | the string to extract the filename from |
- Returns
- the filename string
◆ hasPrefix()
bool TextUtilities::hasPrefix |
( |
const std::string & |
source, |
|
|
const std::string & |
prefix |
|
) |
| |
|
static |
Test if a string is a prefix of another string.
- Parameters
-
source | the string to examine |
prefix | the prefix string to test |
- Returns
- true if the prefix is here
◆ hasSuffix()
bool TextUtilities::hasSuffix |
( |
const std::string & |
source, |
|
|
const std::string & |
suffix |
|
) |
| |
|
static |
Test if a string is a suffix of another string.
- Parameters
-
source | the string to examine |
suffix | the suffix string to test |
- Returns
- true if the suffix is here
◆ join()
std::string TextUtilities::join |
( |
const std::vector< std::string > & |
tokens, |
|
|
const std::string & |
delimiter |
|
) |
| |
|
static |
Join a list of strings together using a custom delimiter.
- Parameters
-
tokens | the list of strings to join |
delimiter | the string that will be inserted between each pair of strings |
- Returns
- the result of the join
◆ lowercase()
std::string TextUtilities::lowercase |
( |
const std::string & |
src | ) |
|
|
static |
Convert all upper case characters in a string to lower case.
- Parameters
-
- Returns
- the converted string
◆ padInt()
std::string TextUtilities::padInt |
( |
uint |
number, |
|
|
uint |
padding |
|
) |
| |
|
static |
Generate a zero-padded string representation of an unsigned integer.
- Parameters
-
number | the number to represent as a string |
padding | the length to pad the number string to |
- Returns
- the number string padded representation
◆ replace() [1/2]
void TextUtilities::replace |
( |
std::string & |
source, |
|
|
const std::string & |
fromChars, |
|
|
const char |
toChar |
|
) |
| |
|
static |
Replace all listed characters by another character in a string.
- Parameters
-
source | the string in which substitutions should happen |
fromChars | list of characters |
toChar | new character to insert |
◆ replace() [2/2]
void TextUtilities::replace |
( |
std::string & |
source, |
|
|
const std::string & |
fromString, |
|
|
const std::string & |
toString |
|
) |
| |
|
static |
Replace all occurences of a substring in a string by another string.
- Parameters
-
source | the string in which substitutions should happen |
fromString | substring to replace |
toString | new substring to insert |
◆ split()
std::vector< std::string > TextUtilities::split |
( |
const std::string & |
str, |
|
|
const std::string & |
delimiter, |
|
|
bool |
skipEmpty |
|
) |
| |
|
static |
Split a string into a list of tokens based on a given delimiter.
- Parameters
-
str | the string to split |
delimiter | the string that will be used as a splitting point |
skipEmpty | should empty tokens be ignored |
- Returns
- a list of tokens
◆ splitExtension()
std::string TextUtilities::splitExtension |
( |
std::string & |
str | ) |
|
|
static |
Remove file extension from the end of a string and extract it.
- Parameters
-
str | the string to remove the extension from |
- Returns
- the extension string
◆ splitLines()
std::vector< std::string > TextUtilities::splitLines |
( |
const std::string & |
str, |
|
|
bool |
skipEmpty |
|
) |
| |
|
static |
Split a string into a list of lines. This function supports both '\n' and '\r\n'.
- Parameters
-
str | the string to split |
skipEmpty | should empty lines be ignored |
- Returns
- a list of lines
◆ trim()
std::string TextUtilities::trim |
( |
const std::string & |
str, |
|
|
const std::string & |
del |
|
) |
| |
|
static |
Trim characters from both ends of a string.
- Parameters
-
str | the string to trim from |
del | the characters to delete |
- Returns
- the trimmed string
◆ uppercase()
std::string TextUtilities::uppercase |
( |
const std::string & |
src | ) |
|
|
static |
Convert all lower case characters in a string to upper case.
- Parameters
-
- Returns
- the converted string
The documentation for this class was generated from the following files: