HDK
|
#include <templateString.h>
Public Types | |
typedef std::map< std::string, std::string > | Mapping |
Public Member Functions | |
TF_API | TfTemplateString () |
Constructs a new template string. More... | |
TF_API | TfTemplateString (const std::string &template_) |
Constructs a new template string. More... | |
const std::string & | GetTemplate () const |
Returns the template source string supplied to the constructor. More... | |
TF_API std::string | Substitute (const Mapping &) const |
TF_API std::string | SafeSubstitute (const Mapping &) const |
TF_API Mapping | GetEmptyMapping () const |
TF_API bool | IsValid () const |
TF_API std::vector< std::string > | GetParseErrors () const |
Returns any error messages generated during template parsing. More... | |
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 63 of file templateString.h.
typedef std::map<std::string, std::string> TfTemplateString::Mapping |
Definition at line 65 of file templateString.h.
TF_API TfTemplateString::TfTemplateString | ( | ) |
Constructs a new template string.
TF_API TfTemplateString::TfTemplateString | ( | const std::string & | template_ | ) |
Constructs a new template string.
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> TfTemplateString::GetParseErrors | ( | ) | const |
Returns any error messages generated during template parsing.
|
inline |
Returns the template source string supplied to the constructor.
Definition at line 76 of file templateString.h.
TF_API bool TfTemplateString::IsValid | ( | ) | const |
Returns true if the current template is well formed. Empty templates are valid.
TF_API std::string TfTemplateString::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 TfTemplateString::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.