AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::utilities::string Namespace Reference

Functions

bool endsWith (const std::string &str, const std::string &suffix)
 Tests whether a string ends with another string https://stackoverflow.com/questions/20446201/how-to-check-if-string-ends-with-txt/20446257. More...
 
bool endsWith (const std::string &str, const char suffix)
 Tests whether a string ends with a char. More...
 
bool startsWith (const std::string &str, const std::string &prefix)
 Tests whether a string starts with another string. More...
 
bool startsWith (const std::string &str, const char prefix)
 Tests whether a string starts with a char. More...
 
std::string removeSuffix (const std::string &str, const std::string &suffix)
 Removes suffix from the end of str, if present. More...
 
std::vector< std::string > split (const std::string &str, const char delimiter)
 Splits the given string based on the given delimiter. More...
 
void toLower (std::string &str)
 Converts a string to lowercase. More...
 
void toUpper (std::string &str)
 Converts a string to uppercase. More...
 
std::vector< std::string > rsplitN (const std::string &input, const std::size_t n, const char delim)
 Retrieves the last "n" tokens of a string split with the specified delimiter. More...
 
std::string appendPrefix (const std::string &prefix, const std::string &name, const char delim='/')
 This function appends the prefix name to the ending name. More...
 
std::string removePrefix (const std::string &prefix, const std::string &name, const char delim='/')
 This function returns the tail of a string following a given prefix plus a delimiter. More...
 
std::string removeBeforeDelimiter (const std::string &str, const char delim='/')
 This function extracts the substring following the last instance of the delimiting character. More...
 
std::string removeAllInstances (const std::string &target, const std::string &substr)
 This function removes all instances of the substring from the target string. More...
 
std::string replaceAllInstances (const std::string &target, const std::string &findstr, const std::string &replacestr)
 This function finds all instances of a substring and replaces it with another string for the target string. More...
 

Function Documentation

◆ endsWith() [1/2]

bool axom::utilities::string::endsWith ( const std::string &  str,
const std::string &  suffix 
)
inline

Tests whether a string ends with another string https://stackoverflow.com/questions/20446201/how-to-check-if-string-ends-with-txt/20446257.

Parameters
[in]strstring to be searched
[in]suffixstring to be checked for
Returns
boolean value whether suffix was found at the end of str

◆ endsWith() [2/2]

bool axom::utilities::string::endsWith ( const std::string &  str,
const char  suffix 
)
inline

Tests whether a string ends with a char.

Parameters
[in]strstring to be searched
[in]suffixchar to be checked for
Returns
boolean value whether suffix was found at the end of str

◆ startsWith() [1/2]

bool axom::utilities::string::startsWith ( const std::string &  str,
const std::string &  prefix 
)
inline

Tests whether a string starts with another string.

Parameters
[in]strstring to be searched
[in]prefixstring to be checked for
Returns
boolean value whether prefix was found at start of str

◆ startsWith() [2/2]

bool axom::utilities::string::startsWith ( const std::string &  str,
const char  prefix 
)
inline

Tests whether a string starts with a char.

Parameters
[in]strstring to be searched
[in]prefixchar to be checked for
Returns
boolean value whether prefix was found at start of str

◆ removeSuffix()

std::string axom::utilities::string::removeSuffix ( const std::string &  str,
const std::string &  suffix 
)
inline

Removes suffix from the end of str, if present.

Parameters
[in]strstring to be searched
[in]suffixstring to check for
Returns
String with (one copy of) suffix removed from end, if it was present

References endsWith().

◆ split()

std::vector<std::string> axom::utilities::string::split ( const std::string &  str,
const char  delimiter 
)

Splits the given string based on the given delimiter.

Parameters
[in]strstring to be tokenized
[in]delimiterchar to split string on
Returns
vector containing the found tokens

◆ toLower()

void axom::utilities::string::toLower ( std::string &  str)

Converts a string to lowercase.

Parameters
[in,out]strstring to be converted

◆ toUpper()

void axom::utilities::string::toUpper ( std::string &  str)

Converts a string to uppercase.

Parameters
[in,out]strstring to be converted

◆ rsplitN()

std::vector<std::string> axom::utilities::string::rsplitN ( const std::string &  input,
const std::size_t  n,
const char  delim 
)

Retrieves the last "n" tokens of a string split with the specified delimiter.

Parameters
[in]inputThe string to split
[in]nThe number of tokens to retrieve
[in]delimThe delimiter to split with
Returns
A list of tokens (of size n )
Note
If delim is not found in the input string, the full input string is returned

Splits a string starting from the end of the string into a maximum of n tokens

◆ appendPrefix()

std::string axom::utilities::string::appendPrefix ( const std::string &  prefix,
const std::string &  name,
const char  delim = '/' 
)

This function appends the prefix name to the ending name.

Parameters
[in]prefixThe prefix string name.
[in]nameThe ending string name.
[in]delimThe delimiting character inserted between the prefix and the name, if both are non-empty
Returns
The appended string. If prefix is empty, then just name is returned.

◆ removePrefix()

std::string axom::utilities::string::removePrefix ( const std::string &  prefix,
const std::string &  name,
const char  delim = '/' 
)

This function returns the tail of a string following a given prefix plus a delimiter.

Parameters
[in]prefixThe prefix of the name, to be removed.
[in]nameThe full name.
[in]delimThe delimiting character "expected" to separate the prefix and the return value
Returns
The extracted string.

For example, removePrefix("foo", "foo/bar") will return "bar". If the prefix is empty or not found the full name string is returned.

◆ removeBeforeDelimiter()

std::string axom::utilities::string::removeBeforeDelimiter ( const std::string &  str,
const char  delim = '/' 
)

This function extracts the substring following the last instance of the delimiting character.

Parameters
[in]strThe string to extract from
[in]delimThe delimiting character
Returns
The extracted string.

◆ removeAllInstances()

std::string axom::utilities::string::removeAllInstances ( const std::string &  target,
const std::string &  substr 
)

This function removes all instances of the substring from the target string.

Parameters
[in]targetThe string to operate on
[in]substrThe string to remove
Returns
The filtered string.

◆ replaceAllInstances()

std::string axom::utilities::string::replaceAllInstances ( const std::string &  target,
const std::string &  findstr,
const std::string &  replacestr 
)

This function finds all instances of a substring and replaces it with another string for the target string.

Parameters
[in]targetThe string to operate on
[in]findstrThe string to find
[in]replacestrThe string to replace with
Returns
The modified string. If findstr and replacestr are the same or if findstr is an empty string, target is returned.