Commit b3cbdac4 authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In ElementaryUtils : correct XMLParser. When attributes are separated by a return line it cannot perform parsing of attribute list correctly.
parent cd6e9ac2
......@@ -45,12 +45,12 @@ public:
private:
static const char TAB_CHARACTER;
static const char ATTRIBUTES_SEPARATOR_CHARACTER;
static const char ATTRIBUTE_KEY_VALUE_SEPARATOR_CHARACTER;
static const char XML_VERSION_CHARACTER_IDENTIFIER;
static const char XML_COMMENT_CHARACTER_IDENTIFIER;
static const char XML_END_TAG_CHARACTER_IDENTIFIER;
static const std::string XML_TAG_NAME_ALLOWED_CHARACTERS;
static const std::string XML_START_ELEMENT_TAG_NAME;
static const std::string XML_END_ELEMENT_TAG_NAME;
......@@ -65,7 +65,8 @@ private:
void parseNode(size_t startIndex);
void parseAttributesFromXMLElement(const std::string& file,
XMLAttributs &attributes, size_t elementNameEndIndex);
XMLAttributs &attributes, const size_t attributesStartIndex,
const size_t xmlEndTagIndex);
};
} // namespace ElemUtils
......
......@@ -9,11 +9,12 @@ namespace ElemUtils {
const char XMLParser::TAB_CHARACTER = '\t';
const char XMLParser::ATTRIBUTE_KEY_VALUE_SEPARATOR_CHARACTER = '=';
const char XMLParser::ATTRIBUTES_SEPARATOR_CHARACTER = ' ';
const char XMLParser::XML_VERSION_CHARACTER_IDENTIFIER = '?';
const char XMLParser::XML_COMMENT_CHARACTER_IDENTIFIER = '!';
const char XMLParser::XML_END_TAG_CHARACTER_IDENTIFIER = '/';
const std::string XMLParser::XML_TAG_NAME_ALLOWED_CHARACTERS =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
const std::string XMLParser::XML_START_ELEMENT_TAG_NAME = "<";
const std::string XMLParser::XML_END_ELEMENT_TAG_NAME = ">";
......@@ -91,14 +92,14 @@ void XMLParser::parseElement(const std::string& file,
}
// retrieve element name
size_t elementNameEndIndex =
file.find_first_not_of(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_",
xmlStartTagIndex + 1);
size_t elementNameEndIndex = file.find_first_not_of(
XMLParser::XML_TAG_NAME_ALLOWED_CHARACTERS,
xmlStartTagIndex + 1);
// retrieve its attributes
XMLAttributs attributes;
parseAttributesFromXMLElement(file, attributes, elementNameEndIndex);
parseAttributesFromXMLElement(file, attributes, elementNameEndIndex,
xmlEndTagIndex);
startElement(
file.substr(xmlStartTagIndex + 1,
......@@ -109,16 +110,15 @@ void XMLParser::parseElement(const std::string& file,
}
void XMLParser::parseAttributesFromXMLElement(const std::string& file,
XMLAttributs &attributes, size_t elementNameEndIndex) {
XMLAttributs &attributes, const size_t attributesStartIndex,
const size_t xmlEndTagIndex) {
//TODO this test fail if attributes are separated by a return line
// retrieve first character position of key attribut
size_t keyStringStartIndex = file.find_first_not_of(
XMLParser::ATTRIBUTES_SEPARATOR_CHARACTER, elementNameEndIndex);
size_t keyStringStartIndex = file.find_first_of(
XMLParser::XML_TAG_NAME_ALLOWED_CHARACTERS, attributesStartIndex);
// if this character not represents an end element
if (file.at(keyStringStartIndex) != '/'
&& file.at(keyStringStartIndex) != '>') {
if (file.at(keyStringStartIndex) < xmlEndTagIndex) {
// try find the equal char separator
size_t equalCharIndex = file.find_first_of(
......@@ -147,7 +147,7 @@ void XMLParser::parseAttributesFromXMLElement(const std::string& file,
// parse remaining attributes recursively
parseAttributesFromXMLElement(file, attributes,
valueStringEndIndex + 1);
valueStringEndIndex + 1, xmlEndTagIndex);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment