24 #ifndef PXR_BASE_TF_TEMPLATE_STRING_H
25 #define PXR_BASE_TF_TEMPLATE_STRING_H
31 #include "pxr/base/tf/api.h"
33 #include <tbb/spin_mutex.h>
40 PXR_NAMESPACE_OPEN_SCOPE
65 typedef std::map<std::string, std::string> Mapping;
76 const std::string&
GetTemplate()
const {
return _data->template_; }
106 struct _PlaceHolder {
107 _PlaceHolder(
const std::string& n,
size_t p,
size_t l)
108 : name(n), pos(p), len(l) {}
115 std::string _Evaluate(
const Mapping&, std::vector<std::string>* = 0)
const;
121 bool _FindNextPlaceHolder(
size_t*, std::vector<std::string>*)
const;
125 void _ParseTemplate()
const;
128 void _EmitParseErrors()
const;
133 _Data(_Data
const &) =
delete;
134 _Data &operator=(_Data
const &) =
delete;
136 _Data() : parsed(false) {}
138 std::string template_;
139 mutable std::vector<_PlaceHolder> placeholders;
141 mutable std::vector<std::string> parseErrors;
142 mutable tbb::spin_mutex mutex;
145 std::shared_ptr<_Data> _data;
148 PXR_NAMESPACE_CLOSE_SCOPE
150 #endif // PXR_BASE_TF_TEMPLATE_STRING_H
TF_API std::vector< std::string > GetParseErrors() const
Returns any error messages generated during template parsing.
const std::string & GetTemplate() const
Returns the template source string supplied to the constructor.
TF_API std::string SafeSubstitute(const Mapping &) const
Like Substitute(), except that if placeholders are missing from the mapping, instead of raising a cod...
TF_API TfTemplateString()
Constructs a new template string.
TF_API std::string Substitute(const Mapping &) const
Performs the template substitution, returning a new string.
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.
TfTemplateString provides simple string substitutions based on named placeholders.