7#ifndef PXR_BASE_TF_TEMPLATE_STRING_H
8#define PXR_BASE_TF_TEMPLATE_STRING_H
14#include "pxr/base/tf/api.h"
16#include <tbb/spin_mutex.h>
23PXR_NAMESPACE_OPEN_SCOPE
48 typedef std::map<std::string, std::string> Mapping;
59 const std::string&
GetTemplate()
const {
return _data->template_; }
90 _PlaceHolder(
const std::string& n,
size_t p,
size_t l)
91 : name(n), pos(p), len(l) {}
98 std::string _Evaluate(
const Mapping&, std::vector<std::string>* = 0)
const;
104 bool _FindNextPlaceHolder(
size_t*, std::vector<std::string>*)
const;
108 void _ParseTemplate()
const;
111 void _EmitParseErrors()
const;
116 _Data(_Data
const &) =
delete;
117 _Data &operator=(_Data
const &) =
delete;
119 _Data() : parsed(false) {}
121 std::string template_;
122 mutable std::vector<_PlaceHolder> placeholders;
124 mutable std::vector<std::string> parseErrors;
125 mutable tbb::spin_mutex mutex;
128 std::shared_ptr<_Data> _data;
131PXR_NAMESPACE_CLOSE_SCOPE
TfTemplateString provides simple string substitutions based on named placeholders.
TF_API TfTemplateString()
Constructs a new template string.
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 std::string Substitute(const Mapping &) const
Performs the template substitution, returning a new string.
TF_API bool IsValid() const
Returns true if the current template is well formed.
TF_API Mapping GetEmptyMapping() const
Returns an empty mapping for the current template.
const std::string & GetTemplate() const
Returns the template source string supplied to the constructor.
TF_API TfTemplateString(const std::string &template_)
Constructs a new template string.
TF_API std::vector< std::string > GetParseErrors() const
Returns any error messages generated during template parsing.