SyTen

◆ replace()

template<typename T >
std::string syten::replace ( std::string const &  input,
std::string const &  start_delim,
std::string const &  end_delim,
func 
)

Replaces occurences of delimited substrings by function return values.

Given a string input and two delimiter strings start_delim and end_delim, searches for all pairwise occurences of the delimiters, extracts the characters between them and calls the function func with those characters as argument, then replaces the delimiters plus internal content by the return value of the function.

Potentially expensive, only use for small strings or if function evaluations dominate.

Parameters
inputinput string
start_delimdelimiter denoting the start of a replacee string
end_delimdelimiter denoting the end of a replacee string
funcfunction to call to get the replacer
Returns
a new string
Example\n replace("a {b} c {d e} f} {g", "{", "}", toupper),
with toupper a function taking a std::string and returning an all-uppercase version thereof results in a B c D E f} {g and a warning being thrown about a runaway argument.

References std::string::find(), logGE(), std::string::size(), std::stringstream::str(), std::string::substr(), and SYTEN_ASSERT_MSG.

+ Here is the call graph for this function: