Class utils::string_template#

Nested Relationships#

This class is a nested type of Class utils.

Nested Types#

Class Documentation#

class string_template

String template allowing substitution of variables enclosed in curly braces.

string_template("{greeting} {name}!")
  .substitute({ { "greeting", "hello" }, { "name", "World" } })
  .str() == "hello World!"

Public Functions

inline explicit string_template(const std::string &templateString)
template<typename F>
string_template &substitute(F lookup)

Substitute variables based on a std::string(const std::string&) function. Variables for which the function throws a string_template::lookup_error exception are left untouched.

inline string_template &substitute(const std::map<std::string, std::string> &lookup)

Substitute variables based on a map. Variables for which the map does not contain a key are left untouched.

inline std::string str() const
inline std::vector<std::string> variables() const

List the remaining un-substituted variables.

template<typename F>
utils::string_template &substitute(F lookup)
struct lookup_error : public std::out_of_range

Exception to be thrown by substitution functions to let untouched variables through.

Public Functions

inline explicit lookup_error(const std::string &what = "")