![]() |
|
TfTemplateString provides simple string substitutions based on named placeholders. More...
#include <templateString.h>
Public Types | |
typedef std::map< std::string, std::string > | Mapping |
Public Member Functions | |
TF_API | TfTemplateString () |
Constructs a new template string. | |
TF_API | TfTemplateString (const std::string &template_) |
Constructs a new template string. | |
const std::string & | GetTemplate () const |
Returns the template source string supplied to the constructor. | |
TF_API std::string | Substitute (const Mapping &) const |
Performs the template substitution, returning a new string. | |
TF_API std::string | SafeSubstitute (const Mapping &) const |
Like Substitute(), except that if placeholders are missing from the mapping, instead of raising a coding error, the original placeholder will appear in the resulting string intact. | |
TF_API Mapping | GetEmptyMapping () const |
Returns an empty mapping for the current template. | |
TF_API bool | IsValid () const |
Returns true if the current template is well formed. | |
TF_API std::vector< std::string > | GetParseErrors () const |
Returns any error messages generated during template parsing. | |
TfTemplateString provides simple string substitutions based on named placeholders.
Instead of the ''-based substitutions used by printf, template strings use '$'-based substitutions, using the following rules:
TfTemplateString is immutable: once one is created it may not be modified. TfTemplateString is fast to copy, since it shares state internally between copies. TfTemplateString is thread-safe. It may be read freely by multiple threads concurrently.
Definition at line 46 of file templateString.h.
typedef std::map<std::string, std::string> Mapping |
Definition at line 48 of file templateString.h.
TF_API TfTemplateString | ( | ) |
Constructs a new template string.
TF_API TfTemplateString | ( | const std::string & | template_ | ) |
Constructs a new template string.
TF_API Mapping GetEmptyMapping | ( | ) | const |
Returns an empty mapping for the current template.
This method first calls IsValid to ensure that the template is valid.
TF_API std::vector< std::string > GetParseErrors | ( | ) | const |
Returns any error messages generated during template parsing.
|
inline |
Returns the template source string supplied to the constructor.
Definition at line 59 of file templateString.h.
TF_API bool IsValid | ( | ) | const |
Returns true if the current template is well formed.
Empty templates are valid.
TF_API std::string SafeSubstitute | ( | const Mapping & | ) | const |
Like Substitute(), except that if placeholders are missing from the mapping, instead of raising a coding error, the original placeholder will appear in the resulting string intact.
TF_API std::string Substitute | ( | const Mapping & | ) | const |
Performs the template substitution, returning a new string.
The mapping contains keys which match the placeholders in the template. If a placeholder is found for which no mapping is present, a coding error is raised.