47 : variable_delimiter_(variable_delimiter),
52 at_start_of_line_(
true),
54 annotation_collector_(
NULL) {}
58 : variable_delimiter_(variable_delimiter),
63 at_start_of_line_(
true),
65 annotation_collector_(annotation_collector) {}
75 std::pair<size_t, size_t>*
range) {
76 std::map<std::string, std::pair<size_t, size_t> >::const_iterator iter =
79 GOOGLE_LOG(DFATAL) <<
" Undefined variable in annotation: " << varname;
82 if (iter->second.first > iter->second.second) {
83 GOOGLE_LOG(DFATAL) <<
" Variable used for annotation used multiple times: "
87 *
range = iter->second;
93 const std::vector<int>&
path) {
98 std::pair<size_t, size_t>
begin,
end;
104 GOOGLE_LOG(DFATAL) <<
" Annotation has negative length from " << begin_varname
105 <<
" to " << end_varname;
114 int size = strlen(text);
119 for (
int i = 0;
i <
size;
i++) {
120 if (text[
i] ==
'\n') {
141 GOOGLE_LOG(DFATAL) <<
" Unclosed variable name.";
144 int endpos =
end - text;
147 if (varname.empty()) {
152 std::map<std::string, std::string>::const_iterator iter =
153 variables.find(varname);
154 if (iter == variables.end()) {
155 GOOGLE_LOG(DFATAL) <<
" Undefined variable: " << varname;
160 WriteRaw(iter->second.data(), iter->second.size());
161 std::pair<std::map<std::string, std::pair<size_t, size_t> >::iterator,
166 if (!inserted.second) {
170 inserted.first->second = std::make_pair(1, 0);
189 GOOGLE_LOG(DFATAL) <<
" Outdent() without matching Indent().";
207 if (
size == 0)
return;
238 buffer_ =
reinterpret_cast<char*
>(void_buffer);
245 if (
size == 0)
return;
259 buffer_ =
reinterpret_cast<char*
>(void_buffer);
277 const std::map<std::string, std::string>& vars,
281 std::vector<AnnotationCollector::Annotation> annotations;
298 if (arg_index !=
args.size()) {
301 if (!annotations.empty()) {
302 GOOGLE_LOG(
FATAL) <<
" Annotation range is not-closed, expect $}$. " << save;
307 const std::vector<string>&
args,
308 const std::map<std::string, std::string>& vars,
const char*
format,
309 int* arg_index, std::vector<AnnotationCollector::Annotation>* annotations) {
326 if (idx < 0 || idx >=
args.size()) {
329 if (
idx > *arg_index) {
330 GOOGLE_LOG(
FATAL) <<
"Annotation arg must be in correct order as given. Expected"
331 <<
" ${" << (*arg_index) + 1 <<
"$ got ${" <<
idx + 1 <<
"$.";
332 }
else if (
idx == *arg_index) {
338 }
else if (*
start ==
'}') {
340 if (annotations->empty()) {
343 auto&
a = annotations->back();
346 annotations->pop_back();
349 auto start_var =
start;
350 while (start_var <
end && *start_var ==
' ') start_var++;
351 if (start_var ==
end) {
355 while (start_var < end_var && *(end_var - 1) ==
' ') end_var--;
357 start_var,
static_cast<std::string::size_type
>(end_var - start_var)};
359 if (std::isdigit(var_name[0])) {
361 int idx = var_name[0] -
'1';
366 if (
idx > *arg_index) {
367 GOOGLE_LOG(
FATAL) <<
"Arguments must be used in same order as given. Expected $"
368 << (*arg_index) + 1 <<
"$ got $" <<
idx + 1 <<
"$.";
369 }
else if (
idx == *arg_index) {
374 auto it = vars.find(var_name);
375 if (
it == vars.end()) {
383 if (sub.empty())
return format;