Commit 03aa225a authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In ElementaryUtils (trunk):
- In XMLParser class correct bad behavior when equal character was surrounding by space character.
parent 17c2a370
......@@ -117,6 +117,7 @@ void XMLParser::parseAttributesFromXMLElement(const std::string& file,
size_t keyStringStartIndex = file.find_first_of(
XMLParser::XML_TAG_NAME_ALLOWED_CHARACTERS, attributesStartIndex);
// if a character is found before the end of the xml end tag element ; there is an attribute
if (keyStringStartIndex < xmlEndTagIndex) {
// try find the equal char separator
......@@ -130,35 +131,35 @@ void XMLParser::parseAttributesFromXMLElement(const std::string& file,
size_t valueStringStartIndex = file.find_first_of('"',
equalCharIndex) + 1;
if (file.at(valueStringStartIndex) == '"') {
// attribut value is EMPTY
std::string attributeName = StringUtils::EMPTY;
std::string attributeValue = StringUtils::EMPTY;
attributes.add(
file.substr(keyStringStartIndex,
equalCharIndex - keyStringStartIndex),
StringUtils::EMPTY);
} else {
if (file.at(valueStringStartIndex) != '"') {
// try to retrieve end index of value
size_t valueStringEndIndex = file.find_first_of('"',
valueStringStartIndex);
if (valueStringStartIndex != std::string::npos
&& valueStringEndIndex != std::string::npos
&& valueStringEndIndex < xmlEndTagIndex) {
// if value retrieve then extract key and value to add them to attributs
attributes.add(
file.substr(keyStringStartIndex,
equalCharIndex - keyStringStartIndex),
file.substr(valueStringStartIndex,
valueStringEndIndex
- valueStringStartIndex));
// parse remaining attributes recursively
parseAttributesFromXMLElement(file, attributes,
valueStringEndIndex + 1, xmlEndTagIndex);
if (valueStringEndIndex != std::string::npos
|| valueStringEndIndex < xmlEndTagIndex) {
attributeValue = file.substr(valueStringStartIndex,
valueStringEndIndex - valueStringStartIndex);
} else {
std::runtime_error(
"(XMLParser::parseAttributesFromXMLElement) Bad XML file : missing character");
}
std::string attributeName = file.substr(keyStringStartIndex,
equalCharIndex - keyStringStartIndex);
StringUtils::replaceAll(attributeName, " ", StringUtils::EMPTY);
// if value retrieve then extract key and value to add them to attributs
attributes.add(attributeName, attributeValue);
// parse remaining attributes recursively
parseAttributesFromXMLElement(file, attributes,
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