Added check (& skipping) of the utf-8 byte order mark (0xEF BB BF) at the beginning of the file

This commit is contained in:
Oli Wilkinson
2016-01-18 18:58:53 +00:00
parent 63b526db52
commit cbe8747b59
2 changed files with 10 additions and 0 deletions

View File

@@ -200,6 +200,14 @@ CheckedError Parser::ParseHexNum(int nibbles, int64_t *val) {
return NoError();
}
CheckedError Parser::SkipByteOrderMark() {
if (static_cast<unsigned char>(*cursor_) != 0xef) return NoError();
cursor_++;
if (static_cast<unsigned char>(*cursor_++) != 0xbb) return Error("invalid utf-8 byte order mark");
if (static_cast<unsigned char>(*cursor_++) != 0xbf) return Error("invalid utf-8 byte order mark");
return NoError();
}
CheckedError Parser::Next() {
doc_comment_.clear();
bool seen_newline = false;
@@ -1584,6 +1592,7 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
builder_.Clear();
// Start with a blank namespace just in case this file doesn't have one.
namespaces_.push_back(new Namespace());
ECHECK(SkipByteOrderMark());
NEXT();
// Includes must come before type declarations:
for (;;) {