MCPcopy Create free account
hub / github.com/Kitware/VTK / htmlParseTryOrFinish

Function htmlParseTryOrFinish

ThirdParty/libxml2/vtklibxml2/HTMLparser.c:5232–5729  ·  view source on GitHub ↗

* htmlParseTryOrFinish: * @ctxt: an HTML parser context * @terminate: last chunk indicator * * Try to progress on parsing * * Returns zero if no parsing was possible */

Source from the content-addressed store, hash-verified

5230 * Returns zero if no parsing was possible
5231 */
5232static int
5233htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
5234 int ret = 0;
5235 htmlParserInputPtr in;
5236 ptrdiff_t avail = 0;
5237 xmlChar cur, next;
5238
5239 htmlParserNodeInfo node_info;
5240
5241 while (PARSER_STOPPED(ctxt) == 0) {
5242
5243 in = ctxt->input;
5244 if (in == NULL) break;
5245 avail = in->end - in->cur;
5246 if ((avail == 0) && (terminate)) {
5247 htmlAutoCloseOnEnd(ctxt);
5248 if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
5249 /*
5250 * SAX: end of the document processing.
5251 */
5252 ctxt->instate = XML_PARSER_EOF;
5253 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5254 ctxt->sax->endDocument(ctxt->userData);
5255 }
5256 }
5257 if (avail < 1)
5258 goto done;
5259 /*
5260 * This is done to make progress and avoid an infinite loop
5261 * if a parsing attempt was aborted by hitting a NUL byte. After
5262 * changing htmlCurrentChar, this probably isn't necessary anymore.
5263 * We should consider removing this check.
5264 */
5265 cur = in->cur[0];
5266 if (cur == 0) {
5267 SKIP(1);
5268 continue;
5269 }
5270
5271 switch (ctxt->instate) {
5272 case XML_PARSER_EOF:
5273 /*
5274 * Document parsing is done !
5275 */
5276 goto done;
5277 case XML_PARSER_START:
5278 /*
5279 * This is wrong but matches long-standing behavior. In most
5280 * cases, a document starting with an XML declaration will
5281 * specify UTF-8.
5282 */
5283 if (((ctxt->input->flags & XML_INPUT_HAS_ENCODING) == 0) &&
5284 (xmlStrncmp(ctxt->input->cur, BAD_CAST "<?xm", 4) == 0)) {
5285 xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_UTF8);
5286 }
5287
5288 /*
5289 * Very first chars read from the document flow.

Callers 1

htmlParseChunkFunction · 0.85

Calls 15

htmlAutoCloseOnEndFunction · 0.85
xmlStrncmpFunction · 0.85
xmlSwitchEncodingFunction · 0.85
htmlParseLookupSequenceFunction · 0.85
htmlParseDocTypeDeclFunction · 0.85
htmlParseCommentFunction · 0.85
htmlParsePIFunction · 0.85
htmlParseCharDataFunction · 0.85
htmlParseStartTagFunction · 0.85
htmlTagLookupFunction · 0.85
htmlnamePopFunction · 0.85

Tested by

no test coverage detected