~ubuntu-branches/debian/stretch/protobuf/stretch

« back to all changes in this revision

Viewing changes to src/google/protobuf/io/tokenizer.cc

  • Committer: Package Import Robot
  • Author(s): Robert S. Edmonds
  • Date: 2014-09-11 22:50:10 UTC
  • mfrom: (10.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20140911225010-wt4yo9dpc1fzuq5g
Tags: 2.6.0-3
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
#include <google/protobuf/io/tokenizer.h>
92
92
#include <google/protobuf/stubs/common.h>
93
93
#include <google/protobuf/stubs/stringprintf.h>
 
94
#include <google/protobuf/io/strtod.h>
94
95
#include <google/protobuf/io/zero_copy_stream.h>
95
96
#include <google/protobuf/stubs/strutil.h>
96
97
#include <google/protobuf/stubs/stl_util.h>
195
196
    record_target_(NULL),
196
197
    record_start_(-1),
197
198
    allow_f_after_float_(false),
198
 
    comment_style_(CPP_COMMENT_STYLE) {
 
199
    comment_style_(CPP_COMMENT_STYLE),
 
200
    require_space_after_number_(true),
 
201
    allow_multiline_strings_(false) {
199
202
 
200
203
  current_.line = 0;
201
204
  current_.column = 0;
350
353
  while (true) {
351
354
    switch (current_char_) {
352
355
      case '\0':
 
356
        AddError("Unexpected end of string.");
 
357
        return;
 
358
 
353
359
      case '\n': {
354
 
        AddError("String literals cannot cross line boundaries.");
355
 
        return;
 
360
        if (!allow_multiline_strings_) {
 
361
          AddError("String literals cannot cross line boundaries.");
 
362
          return;
 
363
        }
 
364
        NextChar();
 
365
        break;
356
366
      }
357
367
 
358
368
      case '\\': {
449
459
    }
450
460
  }
451
461
 
452
 
  if (LookingAt<Letter>()) {
 
462
  if (LookingAt<Letter>() && require_space_after_number_) {
453
463
    AddError("Need space between number and identifier.");
454
464
  } else if (current_char_ == '.') {
455
465
    if (is_float) {
618
628
        ConsumeString('\'');
619
629
        current_.type = TYPE_STRING;
620
630
      } else {
 
631
        // Check if the high order bit is set.
 
632
        if (current_char_ & 0x80) {
 
633
          error_collector_->AddError(line_, column_,
 
634
              StringPrintf("Interpreting non ascii codepoint %d.",
 
635
                           static_cast<unsigned char>(current_char_)));
 
636
        }
621
637
        NextChar();
622
638
        current_.type = TYPE_SYMBOL;
623
639
      }
1086
1102
  }
1087
1103
}
1088
1104
 
 
1105
template<typename CharacterClass>
 
1106
static bool AllInClass(const string& s) {
 
1107
  for (int i = 0; i < s.size(); ++i) {
 
1108
    if (!CharacterClass::InClass(s[i]))
 
1109
      return false;
 
1110
  }
 
1111
  return true;
 
1112
}
 
1113
 
 
1114
bool Tokenizer::IsIdentifier(const string& text) {
 
1115
  // Mirrors IDENTIFIER definition in Tokenizer::Next() above.
 
1116
  if (text.size() == 0)
 
1117
    return false;
 
1118
  if (!Letter::InClass(text.at(0)))
 
1119
    return false;
 
1120
  if (!AllInClass<Alphanumeric>(text.substr(1)))
 
1121
    return false;
 
1122
  return true;
 
1123
}
 
1124
 
1089
1125
}  // namespace io
1090
1126
}  // namespace protobuf
1091
1127
}  // namespace google