ExpatParser: add Parse() overload with buffer

This commit is contained in:
Max Kellermann 2014-01-09 20:34:56 +01:00
parent 2ed1c22227
commit 12b139beaf
2 changed files with 22 additions and 9 deletions

View File

@ -36,6 +36,18 @@ ExpatParser::SetError(Error &error)
XML_ErrorString(code)); XML_ErrorString(code));
} }
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 bool
ExpatParser::Parse(InputStream &is, Error &error) ExpatParser::Parse(InputStream &is, Error &error)
{ {
@ -47,21 +59,14 @@ ExpatParser::Parse(InputStream &is, Error &error)
if (nbytes == 0) if (nbytes == 0)
break; break;
if (XML_Parse(parser, buffer, nbytes, false) != XML_STATUS_OK) { if (!Parse(buffer, nbytes, false, error))
SetError(error);
return false; return false;
}
} }
if (error.IsDefined()) if (error.IsDefined())
return false; return false;
if (XML_Parse(parser, "", 0, true) != XML_STATUS_OK) { return Parse("", 0, true, error);
SetError(error);
return false;
}
return true;
} }
const char * const char *

View File

@ -50,6 +50,9 @@ public:
XML_SetCharacterDataHandler(parser, charhndl); XML_SetCharacterDataHandler(parser, charhndl);
} }
bool Parse(const char *data, size_t length, bool is_final,
Error &error);
bool Parse(InputStream &is, Error &error); bool Parse(InputStream &is, Error &error);
gcc_pure gcc_pure
@ -73,6 +76,11 @@ public:
parser.SetCharacterDataHandler(CharacterData); 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) { bool Parse(InputStream &is, Error &error) {
return parser.Parse(is, error); return parser.Parse(is, error);
} }