diff --git a/Jzon.cpp b/Jzon.cpp index a214ee4..34d6ee2 100644 --- a/Jzon.cpp +++ b/Jzon.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. #include #include #include +#include namespace Jzon { @@ -305,14 +306,7 @@ namespace Jzon { detach(); NamedNodeList &children = data->children; - for (NamedNodeList::iterator it = children.begin(); it != children.end(); ++it) - { - if ((*it).first == name) - { - children.erase(it); - break; - } - } + children.erase(std::remove_if(children.begin(), children.end(), NamedNodeComparator(name)), children.end()); } } void Node::clear() diff --git a/Jzon.h b/Jzon.h index 901ebed..f977e6f 100644 --- a/Jzon.h +++ b/Jzon.h @@ -208,6 +208,7 @@ namespace Jzon std::string valueStr; NamedNodeList children; } *data; + }; JZON_API std::string escapeString(const std::string &value); @@ -218,6 +219,16 @@ namespace Jzon JZON_API Node object(); JZON_API Node array(); + class JZON_API NamedNodeComparator + { + private: + const std::string& name; + public: + NamedNodeComparator(const std::string& name_) : name(name_) {} + bool operator()(const NamedNode& n) { return n.first == name;} + }; + + struct JZON_API Format { bool newline;