Include tag stack size when serializing external scanner
This commit is contained in:
parent
bd235b794b
commit
331b0a4b00
|
@ -26,41 +26,44 @@ struct Scanner {
|
||||||
|
|
||||||
unsigned serialize(char *buffer) {
|
unsigned serialize(char *buffer) {
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
|
unsigned n = tags.size();
|
||||||
for (unsigned j = 0, n = tags.size(); j < n; j++) {
|
buffer[i++] = n;
|
||||||
|
for (unsigned j = 0; j < n; j++) {
|
||||||
Tag &tag = tags[j];
|
Tag &tag = tags[j];
|
||||||
buffer[i] = static_cast<char>(tag.type);
|
buffer[i++] = static_cast<char>(tag.type);
|
||||||
i++;
|
|
||||||
|
|
||||||
if (tag.type == CUSTOM) {
|
if (tag.type == CUSTOM) {
|
||||||
buffer[i++] = tag.custom_tag_name.size();
|
unsigned name_length = tag.custom_tag_name.size();
|
||||||
tag.custom_tag_name.copy(&buffer[i], tag.custom_tag_name.size());
|
buffer[i++] = name_length;
|
||||||
i += tag.custom_tag_name.size();
|
tag.custom_tag_name.copy(&buffer[i], name_length);
|
||||||
|
i += name_length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deserialize(const char *buffer, unsigned length) {
|
void deserialize(const char *buffer, unsigned length) {
|
||||||
tags.clear();
|
tags.clear();
|
||||||
|
if (length > 0) {
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
while (i < length) {
|
unsigned n = buffer[i++];
|
||||||
Tag tag(static_cast<TagType>(buffer[i]), "");
|
tags.resize(n);
|
||||||
i++;
|
for (unsigned j = 0; j < n; j++) {
|
||||||
|
Tag &tag = tags[j];
|
||||||
|
tag.type = static_cast<TagType>(buffer[i++]);
|
||||||
if (tag.type == CUSTOM) {
|
if (tag.type == CUSTOM) {
|
||||||
unsigned length = buffer[i++];
|
unsigned name_length = buffer[i++];
|
||||||
tag.custom_tag_name.assign(&buffer[i], &buffer[i + length]);
|
tag.custom_tag_name.assign(&buffer[i], &buffer[i + name_length]);
|
||||||
i += length;
|
i += name_length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tags.push_back(tag);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string scan_tag_name(TSLexer *lexer) {
|
string scan_tag_name(TSLexer *lexer) {
|
||||||
string tag_name;
|
string tag_name;
|
||||||
while (iswalnum(lexer->lookahead) || lexer->lookahead == '-' || lexer->lookahead == ':') {
|
while (iswalnum(lexer->lookahead) ||
|
||||||
|
lexer->lookahead == '-' ||
|
||||||
|
lexer->lookahead == ':') {
|
||||||
tag_name += towupper(lexer->lookahead);
|
tag_name += towupper(lexer->lookahead);
|
||||||
lexer->advance(lexer, false);
|
lexer->advance(lexer, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -310,6 +310,7 @@ struct Tag {
|
||||||
TagType type;
|
TagType type;
|
||||||
string custom_tag_name;
|
string custom_tag_name;
|
||||||
|
|
||||||
|
Tag() : type(DIV) {}
|
||||||
Tag(TagType type, const string &name) : type(type), custom_tag_name(name) {}
|
Tag(TagType type, const string &name) : type(type), custom_tag_name(name) {}
|
||||||
|
|
||||||
bool operator==(const Tag &other) const {
|
bool operator==(const Tag &other) const {
|
||||||
|
|
Loading…
Reference in New Issue