void ParserEngine::parseExternalByteInputStream(XML_Parser extParser, XMLByteInputStream& istr) { char *pBuffer = new char[PARSE_BUFFER_SIZE]; try { istr.read(pBuffer, PARSE_BUFFER_SIZE); int n = static_cast<int>(istr.gcount()); while (n > 0) { if (!XML_Parse(extParser, pBuffer, n, 0)) handleError(XML_GetErrorCode(extParser)); if (istr.good()) { istr.read(pBuffer, PARSE_BUFFER_SIZE); n = static_cast<int>(istr.gcount()); } else n = 0; } if (!XML_Parse(extParser, pBuffer, 0, 1)) handleError(XML_GetErrorCode(extParser)); } catch (...) { delete [] pBuffer; throw; } delete [] pBuffer; }
void ParserEngine::parseByteInputStream(XMLByteInputStream& istr) { istr.read(_pBuffer, PARSE_BUFFER_SIZE); int n = static_cast<int>(istr.gcount()); while (n > 0) { if (!XML_Parse(_parser, _pBuffer, n, 0)) handleError(XML_GetErrorCode(_parser)); if (istr.good()) { istr.read(_pBuffer, PARSE_BUFFER_SIZE); n = static_cast<int>(istr.gcount()); } else n = 0; } if (!XML_Parse(_parser, _pBuffer, 0, 1)) handleError(XML_GetErrorCode(_parser)); }
std::streamsize ParserEngine::readBytes(XMLByteInputStream& istr, char* pBuffer, std::streamsize bufferSize) { if (_enablePartialReads) { istr.read(pBuffer, 1); if (istr.gcount() == 1) { std::streamsize n = istr.readsome(pBuffer + 1, bufferSize - 1); return n + 1; } else return 0; } else { istr.read(pBuffer, bufferSize); return istr.gcount(); } }