C++ Utilities
Loading...
Searching...
No Matches
string.h

A collectionm of utility functions that work on strings. See the String Functions page for all the details. More...

Go to the source code of this file.

Namespaces

namespace  utilities
 The namespace for the utilities library.

Functions

constexpr char32_t utilities::to_upper (char32_t cp) noexcept
 Converts a wide character to its upper case equivalent if it is a lowercase letter.
constexpr char32_t utilities::to_lower (char32_t cp) noexcept
 Converts a wide character to its lower case equivalent if it is a uppercase letter.
void utilities::upper_case (std::string &str)
 Converts a string to upper case in-place.
void utilities::lower_case (std::string &str)
 Converts a string to lower case in place.
void utilities::trim_left (std::string &str)
 Removes any leading white-space from a string in-place.
void utilities::trim_right (std::string &str)
 Remove any trailing white-space from a string in-place.
void utilities::trim (std::string &str)
 Removes all leading & trailing white-space from a string in-place.
void utilities::replace_left (std::string &str, std::string_view target, std::string_view replacement)
 Replace the first occurrence of a target substring with some other string in-place.
void utilities::replace_right (std::string &str, std::string_view target, std::string_view replacement)
 Replace the final occurrence of a target substring with some other string in-place.
void utilities::replace (std::string &str, std::string_view target, std::string_view replacement)
 Replace all occurrences of a target substring with some other string in-place.
void utilities::replace_space (std::string &s, const std::string &with=" ", bool also_trim=true)
 Replace all contiguous white space sequences in a string in-place.
void utilities::condense (std::string &s, bool also_trim=true)
 Condense contiguous white space sequences in a string in-place.
void utilities::erase_left (std::string &str, std::string_view target)
 Erase the first occurrence of a target substring.
void utilities::erase_right (std::string &str, std::string_view target)
 Erase the last occurrence of a target substring.
void utilities::erase (std::string &str, std::string_view target)
 Erase all occurrences of a target substring.
void utilities::remove_surrounds (std::string &s)
 Removes "surrounds" from a string in-place so for example: (text) -> text.
void utilities::standardize (std::string &s)
 "Standardize" a string – turns "[ hallo world ] " or " Hallo World" into "HALLO WORLD"
std::string utilities::upper_cased (std::string_view input)
 Returns a new string that is a copy of the input converted to upper case.
std::string utilities::lower_cased (std::string_view input)
 Returns a new string that is a copy of the input converted to lower case.
std::string utilities::trimmed_left (std::string_view input)
 Returns a new string that is a copy of the input with leading white-space removed.
std::string utilities::trimmed_right (std::string_view input)
 Returns a new string that is a copy of the input with trailing white-space removed.
std::string utilities::trimmed (std::string_view input)
 Returns a new string that is a copy of the input with all leading and trailing white-space removed.
std::string utilities::replaced_left (std::string_view input, std::string_view target, std::string_view replacement)
 Returns a new string that is a copy of the input with the first occurrence of a target substring replaced.
std::string utilities::replaced_right (std::string_view input, std::string_view target, std::string_view replacement)
 Returns a new string that is a copy of the input with the final occurrence of a target substring replaced.
std::string utilities::replaced (std::string_view input, std::string_view target, std::string_view replacement)
 Returns a new string that is a copy of the input with all occurrences of a target substring replaced.
std::string utilities::replaced_space (std::string_view input, const std::string &with=" ", bool also_trim=true)
 Returns a new string that is a copy of the input with all contiguous white space sequences replaced.
std::string utilities::condensed (std::string_view input, bool also_trim=true)
 Returns a copy of the input with all contiguous white space sequences replaced with one space.
std::string utilities::erased_left (std::string_view input, std::string_view target)
 Returns a new string that is a copy of the input with the first occurrence of a target substring erased.
std::string utilities::erased_right (std::string_view input, std::string_view target)
 Returns a new string that is a copy of the input with the last occurrence of a target substring erased.
std::string utilities::erased (std::string_view input, std::string_view target)
 Returns a new string that is a copy of the input with the all occurrence of a target substring erased.
std::string utilities::removed_surrounds (std::string_view input)
 Returns a new string that is a copy of the input with "surrounds" stripped from it.
std::string utilities::standardized (std::string_view input)
 Returns a "standardized" string that is a copy of the input.
bool utilities::starts_with (std::string_view str, std::string_view prefix)
 Check if a string starts with a particular prefix string.
bool utilities::ends_with (std::string_view str, std::string_view suffix)
 Check if a string ends with a particular suffix string.
template<typename T>
constexpr std::optional< T > utilities::possible (std::string_view in, const char **next=nullptr)
 Try to read a value of a particular type from a string.
template<std::input_iterator InputIt, std::forward_iterator ForwardIt, typename BinaryFunc>
constexpr void utilities::for_each_token (InputIt ib, InputIt ie, ForwardIt db, ForwardIt de, BinaryFunc function)
 Given input text and delimiters, tokenize the text and then passes the tokens to a function you supply.
template<typename Container_t>
constexpr void utilities::tokenize (std::string_view input, Container_t &output, std::string_view delimiters="\t,;: ", bool skip=true)
 Tokenize a string and put the tokens into the supplied output container.
std::vector< std::string > utilities::split (std::string_view input, std::string_view delimiters="\t,;: ", bool skip=true)
 Tokenize a string and return the tokens as a vector of strings.
template<typename Iter, typename Traits, typename CharT, typename UnaryFunction>
std::basic_string< CharT > utilities::regex_replace (Iter ib, Iter ie, const std::basic_regex< CharT, Traits > &re, UnaryFunction f)
 A version of regex_replace(...) where each match in turn is is run through a function you supply.
template<typename Traits, typename CharT, typename UnaryFunction>
std::string utilities::regex_replace (const std::string &s, const std::basic_regex< CharT, Traits > &re, UnaryFunction f)
 A version of regex_replace(...) where each match in turn is is run through a function you supply.

Detailed Description

A collectionm of utility functions that work on strings. See the String Functions page for all the details.