* htmlCreateDocParserCtxt: * @cur: a pointer to an array of xmlChar * @encoding: a free form C string describing the HTML document encoding, or NULL * * Create a parser context for an HTML document. * * TODO: check the need to add encoding handling there * * Returns the new parser context or NULL */
| 4405 | * Returns the new parser context or NULL |
| 4406 | */ |
| 4407 | static htmlParserCtxtPtr |
| 4408 | htmlCreateDocParserCtxt(const xmlChar *cur, const char *encoding) { |
| 4409 | int len; |
| 4410 | htmlParserCtxtPtr ctxt; |
| 4411 | |
| 4412 | if (cur == NULL) |
| 4413 | return(NULL); |
| 4414 | len = xmlStrlen(cur); |
| 4415 | ctxt = htmlCreateMemoryParserCtxt((char *)cur, len); |
| 4416 | if (ctxt == NULL) |
| 4417 | return(NULL); |
| 4418 | |
| 4419 | if (encoding != NULL) { |
| 4420 | xmlCharEncoding enc; |
| 4421 | xmlCharEncodingHandlerPtr handler; |
| 4422 | |
| 4423 | if (ctxt->input->encoding != NULL) |
| 4424 | xmlFree((xmlChar *) ctxt->input->encoding); |
| 4425 | ctxt->input->encoding = xmlStrdup((const xmlChar *) encoding); |
| 4426 | |
| 4427 | enc = xmlParseCharEncoding(encoding); |
| 4428 | /* |
| 4429 | * registered set of known encodings |
| 4430 | */ |
| 4431 | if (enc != XML_CHAR_ENCODING_ERROR) { |
| 4432 | xmlSwitchEncoding(ctxt, enc); |
| 4433 | if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { |
| 4434 | htmlParseErr(ctxt, XML_ERR_UNSUPPORTED_ENCODING, |
| 4435 | "Unsupported encoding %s\n", |
| 4436 | (const xmlChar *) encoding, NULL); |
| 4437 | } |
| 4438 | } else { |
| 4439 | /* |
| 4440 | * fallback for unknown encodings |
| 4441 | */ |
| 4442 | handler = xmlFindCharEncodingHandler((const char *) encoding); |
| 4443 | if (handler != NULL) { |
| 4444 | xmlSwitchToEncoding(ctxt, handler); |
| 4445 | } else { |
| 4446 | htmlParseErr(ctxt, XML_ERR_UNSUPPORTED_ENCODING, |
| 4447 | "Unsupported encoding %s\n", |
| 4448 | (const xmlChar *) encoding, NULL); |
| 4449 | } |
| 4450 | } |
| 4451 | } |
| 4452 | return(ctxt); |
| 4453 | } |
| 4454 | |
| 4455 | #ifdef LIBXML_PUSH_ENABLED |
| 4456 | /************************************************************************ |
no test coverage detected