diff options
-rw-r--r-- | common/xmlparser.cpp | 22 | ||||
-rw-r--r-- | common/xmlparser.h | 9 |
2 files changed, 28 insertions, 3 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index b845f7f66f..6c6bc4b7f8 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -135,7 +135,7 @@ bool XMLParser::parseActiveKey(bool closed) { } if (closed) - delete _activeKey.pop(); + return closeKey(); return true; } @@ -166,6 +166,23 @@ bool XMLParser::parseKeyValue(Common::String keyName) { return true; } +bool XMLParser::closeKey() { + bool ignore = false; + bool result = true; + + for (int i = _activeKey.size() - 1; i >= 0; --i) { + if (_activeKey[i]->ignore) + ignore = true; + } + + if (ignore == false) + result = closedKeyCallback(_activeKey.top()); + + delete _activeKey.pop(); + + return result; +} + bool XMLParser::parse() { if (_text.ready() == false) @@ -235,13 +252,12 @@ bool XMLParser::parse() { case kParserNeedPropertyName: if (activeClosure) { - if (!closedKeyCallback(_activeKey.top())) { + if (!closeKey()) { parserError("Missing data when closing key '%s'.", _activeKey.top()->name.c_str()); break; } activeClosure = false; - delete _activeKey.pop(); if (_text[_pos++] != '>') parserError("Invalid syntax in key closure."); diff --git a/common/xmlparser.h b/common/xmlparser.h index e26ea1eb53..d1abd321e7 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -423,12 +423,21 @@ protected: * The closedKeyCallback is issued once a key has been finished parsing, to let * the parser verify that all the required subkeys, etc, were included. * + * Unlike the keyCallbacks(), there's just a closedKeyCallback() for all keys. + * Use "node->name" to distinguish between each key type. + * * Returns true if the key was properly closed, false otherwise. * By default, all keys are properly closed. */ virtual bool closedKeyCallback(ParserNode *node) { return true; } + + /** + * Called when a node is closed. Manages its cleanup and calls the + * closing callback function if needed. + */ + bool closeKey(); /** * Parses the value of a given key. There's no reason to overload this. |