Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Feb 1, 2024
1 parent da190f3 commit 84e8fd1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/coders/xml.cpp
Expand Up @@ -115,7 +115,7 @@ Parser::Parser(std::string filename, std::string source)
}

xmlelement Parser::parseOpenTag() {
std::string tag = parseName();
std::string tag = parseXMLName();
auto node = std::make_shared<Node>(tag);

char c;
Expand All @@ -124,7 +124,7 @@ xmlelement Parser::parseOpenTag() {
c = peek();
if (c == '/' || c == '>' || c == '?')
break;
std::string attrname = parseName();
std::string attrname = parseXMLName();
std::string attrtext = "";
skipWhitespace();
if (peek() == '=') {
Expand Down Expand Up @@ -181,6 +181,26 @@ std::string Parser::parseText() {
return source.substr(start, pos-start);
}

inline bool is_xml_identifier_start(char c) {
return is_identifier_start(c) || c == ':';
}

inline bool is_xml_identifier_part(char c) {
return is_identifier_part(c) || c == '-' || c == '.' || c == ':';
}

std::string Parser::parseXMLName() {
char c = peek();
if (!is_xml_identifier_start(c)) {
throw error("identifier expected");
}
int start = pos;
while (hasNext() && is_xml_identifier_part(source[pos])) {
pos++;
}
return source.substr(start, pos-start);
}

xmlelement Parser::parseElement() {
// text element
if (peek() != '<') {
Expand Down Expand Up @@ -235,7 +255,12 @@ xmlelement Parser::parseElement() {

xmldocument Parser::parse() {
parseDeclaration();
document->setRoot(parseElement());

xmlelement root = nullptr;
while (root == nullptr) {
root = parseElement();
}
document->setRoot(root);
return document;
}

Expand Down
1 change: 1 addition & 0 deletions src/coders/xml.h
Expand Up @@ -105,6 +105,7 @@ namespace xml {
void parseDeclaration();
void parseComment();
std::string parseText();
std::string parseXMLName();
public:
Parser(std::string filename, std::string source);

Expand Down

0 comments on commit 84e8fd1

Please sign in to comment.