Skip to main content
Version: 🚧 Nightly

Class f3d::utils::string_template

Definition: utils.h (line 139)

String template allowing substitution of variables enclosed in curly braces.

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

Inner classes

Members

Private attributes

Variable fragments

Definition: utils.h (line 141)

std::vector<std::pair<std::string, bool> > f3d::utils::string_template::fragments

Type: std::vector< std::pair< std::string, bool > >

Public functions

Function string_template

f3d::utils::string_template::string_template(const std::string &templateString)

Parameters:

  • const std::string & templateString

Return type:

Function substitute

string_template & f3d::utils::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.

Parameters:

  • F lookup

Return type: string_template &

Function substitute

utils::string_template & f3d::utils::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.

Parameters:

  • const std::map< std::string, std::string > & lookup

Return type: string_template &

Function str

std::string f3d::utils::string_template::str() const

Return a string representation of the string template

Return type: std::string

Function variables

std::vector< std::string > f3d::utils::string_template::variables() const

List the remaining un-substituted variables.

Return type: std::vector< std::string >

Function substitute

utils::string_template & f3d::utils::string_template::substitute(F lookup)

Parameters:

  • F lookup

Return type: utils::string_template &