lib/expat/ExpatParser: add constructor overload for XML_ParserCreateNS()

This commit is contained in:
Max Kellermann 2017-01-07 16:17:53 +01:00
parent 8986d14e98
commit 981dc0626b

View File

@ -38,6 +38,10 @@ public:
:ExpatError(XML_GetErrorCode(parser)) {}
};
struct ExpatNamespaceSeparator {
char separator;
};
class ExpatParser final {
const XML_Parser parser;
@ -47,6 +51,11 @@ public:
XML_SetUserData(parser, userData);
}
ExpatParser(ExpatNamespaceSeparator ns, void *userData)
:parser(XML_ParserCreateNS(nullptr, ns.separator)) {
XML_SetUserData(parser, userData);
}
~ExpatParser() {
XML_ParserFree(parser);
}
@ -89,6 +98,12 @@ public:
parser.SetCharacterDataHandler(CharacterData);
}
explicit CommonExpatParser(ExpatNamespaceSeparator ns)
:parser(ns, this) {
parser.SetElementHandler(StartElement, EndElement);
parser.SetCharacterDataHandler(CharacterData);
}
void Parse(const char *data, size_t length, bool is_final) {
parser.Parse(data, length, is_final);
}