Move JSON Pointer leading slash check out of recursive function

This commit is contained in:
Tristan Penman 2015-05-06 07:02:27 +10:00
parent 454ec19914
commit feaea37aee

View File

@ -33,15 +33,6 @@ inline AdapterType resolveJsonPointer(
const std::string::const_iterator jsonPointerEnd = jsonPointer.end();
// Check for leading forward slash
if (std::find(jsonPointerItr, jsonPointerEnd, '/') == jsonPointerEnd) {
throw std::runtime_error(
"Expected '/' while parsing JSON Pointer.");
}
// Proceed past leading slash
jsonPointerItr++;
// Recursion bottoms out here
if (jsonPointerItr == jsonPointerEnd) {
return node;
@ -149,7 +140,12 @@ inline AdapterType resolveJsonPointer(
const AdapterType &rootNode,
const std::string &jsonPointer)
{
return ::resolveJsonPointer(rootNode, jsonPointer, jsonPointer.begin());
if (jsonPointer.find("/") != 0) {
throw std::runtime_error(
"Expected leading '/' while parsing JSON Pointer.");
}
return ::resolveJsonPointer(rootNode, jsonPointer, jsonPointer.begin() + 1);
}
} // namespace json_reference