mirror of
https://github.com/OlafvdSpek/ctemplate.git
synced 2025-09-28 19:05:49 +08:00
Add begin(), end(), data() and size() to TemplateString
This commit is contained in:
parent
9c4e28e06f
commit
9f7baaec47
|
@ -187,6 +187,22 @@ class @ac_windows_dllexport@ TemplateString {
|
|||
is_immutable_(true), id_(s.do_not_use_directly_.id_) {
|
||||
}
|
||||
|
||||
const char* begin() const {
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
const char* end() const {
|
||||
return ptr_ + length_;
|
||||
}
|
||||
|
||||
const char* data() const {
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return length_;
|
||||
}
|
||||
|
||||
inline bool empty() const {
|
||||
return length_ == 0;
|
||||
};
|
||||
|
@ -198,7 +214,6 @@ class @ac_windows_dllexport@ TemplateString {
|
|||
// Only TemplateDictionaries and template expansion code can read these.
|
||||
friend class TemplateDictionary;
|
||||
friend class TemplateDictionaryPeer; // TDP::GetSectionValue()
|
||||
friend class Template; // for StringToTemplate()
|
||||
friend class VariableTemplateNode; // VTN::Expand()
|
||||
friend class TemplateCache; // for GetGlobalId
|
||||
friend class StaticTemplateStringInitializer; // for AddToGlo...
|
||||
|
|
|
@ -2141,9 +2141,9 @@ Template* Template::StringToTemplate(const TemplateString& content,
|
|||
// But we have to do the "loading" and parsing ourselves:
|
||||
|
||||
// BuildTree deletes the buffer when done, so we need a copy for it.
|
||||
char* buffer = new char[content.length_];
|
||||
size_t content_len = content.length_;
|
||||
memcpy(buffer, content.ptr_, content_len);
|
||||
char* buffer = new char[content.size()];
|
||||
size_t content_len = content.size();
|
||||
memcpy(buffer, content.data(), content_len);
|
||||
tpl->StripBuffer(&buffer, &content_len);
|
||||
if ( tpl->BuildTree(buffer, buffer + content_len) ) {
|
||||
assert(tpl->state() == TS_READY);
|
||||
|
@ -2171,7 +2171,7 @@ Template* Template::StringToTemplate(const TemplateString& content,
|
|||
Template::Template(const TemplateString& filename, Strip strip,
|
||||
TemplateCache* owner)
|
||||
// TODO(csilvers): replace ToString() with an is_immutable() check
|
||||
: original_filename_(filename.ToString()), resolved_filename_(),
|
||||
: original_filename_(filename.data(), filename.size()), resolved_filename_(),
|
||||
filename_mtime_(0), strip_(strip), state_(TS_EMPTY),
|
||||
template_cache_(owner), template_text_(NULL), template_text_len_(0),
|
||||
tree_(NULL), parse_state_(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user