* htmlParseTryOrFinish: * @ctxt: an HTML parser context * @terminate: last chunk indicator * * Try to progress on parsing * * Returns zero if no parsing was possible */
| 5230 | * Returns zero if no parsing was possible |
| 5231 | */ |
| 5232 | static int |
| 5233 | htmlParseTryOrFinish(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. |
no test coverage detected