diff options
author | crupest <crupest@outlook.com> | 2022-03-04 20:07:50 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-04 20:07:50 +0800 |
commit | 14e1b0f188d302b69816ddf12f5ac591fd76b91d (patch) | |
tree | 8481328cfa20a43b67abd5455c2e34fd42639e0b /src/xml/XmlParser.cpp | |
parent | 57353bd3acd97957cb5f970016fec52977cc6e95 (diff) | |
download | cru-14e1b0f188d302b69816ddf12f5ac591fd76b91d.tar.gz cru-14e1b0f188d302b69816ddf12f5ac591fd76b91d.tar.bz2 cru-14e1b0f188d302b69816ddf12f5ac591fd76b91d.zip |
...
Diffstat (limited to 'src/xml/XmlParser.cpp')
-rw-r--r-- | src/xml/XmlParser.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/xml/XmlParser.cpp b/src/xml/XmlParser.cpp index babb6b00..313015d5 100644 --- a/src/xml/XmlParser.cpp +++ b/src/xml/XmlParser.cpp @@ -22,7 +22,7 @@ char16_t XmlParser::Read1() { String XmlParser::ReadWithoutAdvance(int count) { if (current_position_ + count > xml_.size()) { - return u""; + count = xml_.size() - current_position_; } return xml_.substr(current_position_, count); } @@ -108,6 +108,19 @@ XmlElementNode* XmlParser::DoParse() { } current_ = current_->GetParent(); + } else if (ReadWithoutAdvance(3) == u"!--") { + current_position_ += 3; + + String text; + while (true) { + auto str = ReadWithoutAdvance(3); + if (str == u"-->") break; + if (str.empty()) throw XmlParsingException(u"Unexpected end of xml"); + text += Read1(); + } + + current_position_ += 3; + current_->AddChild(new XmlCommentNode(text.Trim())); } else { ReadSpacesAndDiscard(); @@ -173,10 +186,8 @@ XmlElementNode* XmlParser::DoParse() { throw XmlParsingException(u"Unexpected end of xml"); } - if (pseudo_root_node_->GetChildren().size() != 1 || - pseudo_root_node_->GetChildren()[0]->GetType() != - XmlNode::Type::Element) { - throw XmlParsingException(u"Expected 1 element node as root."); + if (pseudo_root_node_->GetChildren().size() != 1) { + throw XmlParsingException(u"Expected 1 node as root."); } return static_cast<XmlElementNode*>(pseudo_root_node_->GetChildren()[0]); |