Removed duplication when one replaces a value in a (PR #232 by @ulion)

This commit is contained in:
ulion
2016-02-23 21:27:52 +01:00
committed by Benoit Blanchon
parent 6ab23bd523
commit b47a3b566a
3 changed files with 35 additions and 2 deletions

View File

@ -55,8 +55,12 @@ inline void JsonObject::remove(JsonObjectKey key) {
template <typename T>
inline bool JsonObject::setNodeAt(JsonObjectKey key, T value) {
node_type *node = getNodeAt(key.c_str());
if (!node) node = addNewNode();
return node && setNodeKey(node, key) && setNodeValue<T>(node, value);
if (!node) {
node = addNewNode();
if (!node || !setNodeKey(node, key))
return false;
}
return setNodeValue<T>(node, value);
}
inline bool JsonObject::setNodeKey(node_type *node, JsonObjectKey key) {