HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfTemplateString Class Reference

#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::stringGetTemplate () 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::stringGetParseErrors () const
 Returns any error messages generated during template parsing. More...
 

Detailed Description

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:

  • "$$" is replaced with a single "$"
  • "$identifier" names a substitution placeholder matching a mapping key of "identifier". The first non-identifier character after the "$" character terminates the placeholder specification.
  • "${identifier}" is equivalent to "$identifier". It is required when valid identifier characters follow the placeholder but are not part of the placeholder, such as "${noun}ification".
  • An identifier is a sequence of characters "[A-Z][a-z][0-9]_".

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.

Member Typedef Documentation

Definition at line 65 of file templateString.h.

Constructor & Destructor Documentation

TF_API TfTemplateString::TfTemplateString ( )

Constructs a new template string.

TF_API TfTemplateString::TfTemplateString ( const std::string template_)

Constructs a new template string.

Member Function Documentation

TF_API Mapping TfTemplateString::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> TfTemplateString::GetParseErrors ( ) const

Returns any error messages generated during template parsing.

const std::string& TfTemplateString::GetTemplate ( ) const
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.


The documentation for this class was generated from the following file: