group String utils

String utils

Classes

Name
structRivet::bad_lexical_cast
Exception class for throwing from lexical_cast when a parse goes wrong.

Functions

Name
template <typename T ,typename U >
T
lexical_cast(const U & in)
Convert between any types via stringstream.
template <typename T >
string
to_str(const T & x)
Convert any object to a string.
template <typename T >
string
toString(const T & x)
Convert any object to a string.
string &replace_first(string & str, const string & patt, const string & repl)
Replace the first instance of patt with repl.
string &replace_all(string & str, const string & patt, const string & repl)
Replace all instances of patt with repl.
intnocase_cmp(const string & s1, const string & s2)
Case-insensitive string comparison function.
boolnocase_equals(const string & s1, const string & s2)
Case-insensitive string equality function.
stringtoLower(const string & s)
Convert a string to lower-case.
stringtoUpper(const string & s)
Convert a string to upper-case.
boolstartsWith(const string & s, const string & start)
Check whether a string start is found at the start of s.
boolendsWith(const string & s, const string & end)
Check whether a string end is found at the end of s.
stringstrcat()
template <typename T ,typename… Ts>
string
strcat(T value, Ts… fargs)
Make a string containing the concatenated string representations of each item in the variadic list.
template <typename T >
string
join(const vector< T > & v, const string & sep =" “)
Make a string containing the string representations of each item in v, separated by sep.
stringjoin(const vector< string > & v, const string & sep)
Make a string containing the string representations of each item in v, separated by sep.
template <typename T >
string
join(const set< T > & s, const string & sep =” “)
Make a string containing the string representations of each item in s, separated by sep.
stringjoin(const set< string > & s, const string & sep)
Make a string containing the string representations of each item in s, separated by sep.
vector< string >split(const string & s, const string & sep)
Split a string on a specified separator string.
stringlpad(const string & s, size_t width, const string & padchar =” “)
Left-pad the given string s to width width.
stringrpad(const string & s, size_t width, const string & padchar =” “)
Right-pad the given string s to width width.

Functions Documentation

function lexical_cast

template <typename T ,
typename U >
T lexical_cast(
    const U & in
)

Convert between any types via stringstream.

function to_str

template <typename T >
inline string to_str(
    const T & x
)

Convert any object to a string.

Just a convenience wrapper for the more general Boost lexical_cast

function toString

template <typename T >
inline string toString(
    const T & x
)

Convert any object to a string.

An alias for to_str() with a more “Rivety” mixedCase name.

function replace_first

inline string & replace_first(
    string & str,
    const string & patt,
    const string & repl
)

Replace the first instance of patt with repl.

function replace_all

inline string & replace_all(
    string & str,
    const string & patt,
    const string & repl
)

Replace all instances of patt with repl.

Note: Finding is interleaved with replacement, so the second search happens after first replacement, etc. This could lead to infinite loops and other counterintuitive behaviours if not careful.

function nocase_cmp

inline int nocase_cmp(
    const string & s1,
    const string & s2
)

Case-insensitive string comparison function.

function nocase_equals

inline bool nocase_equals(
    const string & s1,
    const string & s2
)

Case-insensitive string equality function.

function toLower

inline string toLower(
    const string & s
)

Convert a string to lower-case.

function toUpper

inline string toUpper(
    const string & s
)

Convert a string to upper-case.

function startsWith

inline bool startsWith(
    const string & s,
    const string & start
)

Check whether a string start is found at the start of s.

function endsWith

inline bool endsWith(
    const string & s,
    const string & end
)

Check whether a string end is found at the end of s.

function strcat

inline string strcat()

function strcat

template <typename T ,
typename... Ts>
inline string strcat(
    T value,
    Ts... fargs
)

Make a string containing the concatenated string representations of each item in the variadic list.

function join

template <typename T >
inline string join(
    const vector< T > & v,
    const string & sep =" "
)

Make a string containing the string representations of each item in v, separated by sep.

function join

inline string join(
    const vector< string > & v,
    const string & sep
)

Make a string containing the string representations of each item in v, separated by sep.

function join

template <typename T >
inline string join(
    const set< T > & s,
    const string & sep =" "
)

Make a string containing the string representations of each item in s, separated by sep.

function join

inline string join(
    const set< string > & s,
    const string & sep
)

Make a string containing the string representations of each item in s, separated by sep.

function split

inline vector< string > split(
    const string & s,
    const string & sep
)

Split a string on a specified separator string.

function lpad

inline string lpad(
    const string & s,
    size_t width,
    const string & padchar =" "
)

Left-pad the given string s to width width.

function rpad

inline string rpad(
    const string & s,
    size_t width,
    const string & padchar =" "
)

Right-pad the given string s to width width.


Updated on 2022-08-07 at 20:17:17 +0100