aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Expat.cxx23
-rw-r--r--src/Expat.hxx8
2 files changed, 22 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 *
diff --git a/src/Expat.hxx b/src/Expat.hxx
index 0ea35c618..9fcdf61d4 100644
--- a/src/Expat.hxx
+++ b/src/Expat.hxx
@@ -50,6 +50,9 @@ public:
XML_SetCharacterDataHandler(parser, charhndl);
}
+ bool Parse(const char *data, size_t length, bool is_final,
+ Error &error);
+
bool Parse(InputStream &is, Error &error);
gcc_pure
@@ -73,6 +76,11 @@ public:
parser.SetCharacterDataHandler(CharacterData);
}
+ bool Parse(const char *data, size_t length, bool is_final,
+ Error &error) {
+ return parser.Parse(data, length, is_final, error);
+ }
+
bool Parse(InputStream &is, Error &error) {
return parser.Parse(is, error);
}