diff options
author | Max Kellermann <max@duempel.org> | 2014-01-09 20:34:56 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-09 20:56:00 +0100 |
commit | 12b139beafc191d02277e7ce97b4c59f7bb0c095 (patch) | |
tree | 209bd2c58ab47ad94f848ee446b944e3cb4e9960 /src/Expat.cxx | |
parent | 2ed1c2222735ce5fccd69b7eb4595d398c3a22f6 (diff) | |
download | mpd-12b139beafc191d02277e7ce97b4c59f7bb0c095.tar.gz mpd-12b139beafc191d02277e7ce97b4c59f7bb0c095.tar.xz mpd-12b139beafc191d02277e7ce97b4c59f7bb0c095.zip |
ExpatParser: add Parse() overload with buffer
Diffstat (limited to 'src/Expat.cxx')
-rw-r--r-- | src/Expat.cxx | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/Expat.cxx b/src/Expat.cxx index 5d5a8be24..0c7ff9315 100644 --- a/src/Expat.cxx +++ b/src/Expat.cxx @@ -37,6 +37,18 @@ ExpatParser::SetError(Error &error) } bool +ExpatParser::Parse(const char *data, size_t length, bool is_final, + Error &error) +{ + bool success = XML_Parse(parser, data, length, + is_final) == XML_STATUS_OK; + if (!success) + SetError(error); + + return success; +} + +bool ExpatParser::Parse(InputStream &is, Error &error) { assert(is.ready); @@ -47,21 +59,14 @@ ExpatParser::Parse(InputStream &is, Error &error) if (nbytes == 0) break; - if (XML_Parse(parser, buffer, nbytes, false) != XML_STATUS_OK) { - SetError(error); + if (!Parse(buffer, nbytes, false, error)) return false; - } } if (error.IsDefined()) return false; - if (XML_Parse(parser, "", 0, true) != XML_STATUS_OK) { - SetError(error); - return false; - } - - return true; + return Parse("", 0, true, error); } const char * |