void ParserEngine::parseExternalCharInputStream(XML_Parser extParser, XMLCharInputStream& istr) { XMLChar *pBuffer = new XMLChar[PARSE_BUFFER_SIZE/sizeof(XMLChar)]; try { istr.read(pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar)); int n = static_cast<int>(istr.gcount()); while (n > 0) { if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), n*sizeof(XMLChar), 0)) handleError(XML_GetErrorCode(extParser)); if (istr.good()) { istr.read(pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar)); n = static_cast<int>(istr.gcount()); } else n = 0; } if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), 0, 1)) handleError(XML_GetErrorCode(extParser)); } catch (...) { delete [] pBuffer; throw; } delete [] pBuffer; }
std::streamsize ParserEngine::readChars(XMLCharInputStream& istr, XMLChar* 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(); } }
void ParserEngine::parseCharInputStream(XMLCharInputStream& istr) { istr.read(reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar)); int n = static_cast<int>(istr.gcount()); while (n > 0) { if (!XML_Parse(_parser, _pBuffer, n*sizeof(XMLChar), 0)) handleError(XML_GetErrorCode(_parser)); if (istr.good()) { istr.read(reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar)); n = static_cast<int>(istr.gcount()); } else n = 0; } if (!XML_Parse(_parser, _pBuffer, 0, 1)) handleError(XML_GetErrorCode(_parser)); }
void ParserEngine::parseCharInputStream(XMLCharInputStream& istr) { std::streamsize n = readChars(istr, reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar)); while (n > 0) { if (!XML_Parse(_parser, _pBuffer, static_cast<int>(n*sizeof(XMLChar)), 0)) handleError(XML_GetErrorCode(_parser)); if (istr.good()) n = readChars(istr, reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar)); else n = 0; } if (!XML_Parse(_parser, _pBuffer, 0, 1)) handleError(XML_GetErrorCode(_parser)); }