mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-22 17:16:17 +00:00
Refactor to only use a position variable
This commit is contained in:
@@ -82,24 +82,22 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
const tinyxml2::XMLElement*
|
const tinyxml2::XMLElement*
|
||||||
element_access(const tinyxml2::XMLElement* elem, std::string elemNames) {
|
element_access(const tinyxml2::XMLElement* elem, std::string element_names) {
|
||||||
// Helper function to check each step of a element access, in lieu of XPath
|
// Helper function to check each step of a element access, in lieu of XPath
|
||||||
char token = ',';
|
std::string stack;
|
||||||
std::string stack("");
|
|
||||||
const tinyxml2::XMLElement* result = elem;
|
const tinyxml2::XMLElement* result = elem;
|
||||||
size_t start = 0;
|
size_t pos = 0;
|
||||||
size_t end = 0;
|
|
||||||
do {
|
do {
|
||||||
end = elemNames.find(token, start);
|
auto previous_pos = pos;
|
||||||
auto item = elemNames.substr(start, end - start);
|
pos = element_names.find(',', pos + 1);
|
||||||
|
auto item = element_names.substr(pos, previous_pos - pos);
|
||||||
stack.append(item);
|
stack.append(item);
|
||||||
result = result->FirstChildElement(item.c_str());
|
result = result->FirstChildElement(item.c_str());
|
||||||
if (result == nullptr) {
|
if (result == nullptr) {
|
||||||
throw xmlrpc_error(XMLRPC_PARSE_ERROR, "could not find expected element " + stack);
|
throw xmlrpc_error(XMLRPC_PARSE_ERROR, "could not find expected element " + stack);
|
||||||
}
|
}
|
||||||
stack.append("->");
|
stack.append("->");
|
||||||
start = end + 1;
|
} while (pos != std::string::npos);
|
||||||
} while (end != std::string::npos);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user