MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCOLLADA / htmlCheckEncoding

Function htmlCheckEncoding

Externals/LibXML/HTMLparser.c:3290–3374  ·  view source on GitHub ↗

* htmlCheckEncoding: * @ctxt: an HTML parser context * @attvalue: the attribute value * * Checks an http-equiv attribute from a Meta tag to detect * the encoding * If a new encoding is detected the parser is switched to decode * it and pass UTF8 */

Source from the content-addressed store, hash-verified

3288 * it and pass UTF8
3289 */
3290static void
3291htmlCheckEncoding(htmlParserCtxtPtr ctxt, const xmlChar *attvalue) {
3292 const xmlChar *encoding;
3293
3294 if ((ctxt == NULL) || (attvalue == NULL))
3295 return;
3296
3297 /* do not change encoding */
3298 if (ctxt->input->encoding != NULL)
3299 return;
3300
3301 encoding = xmlStrcasestr(attvalue, BAD_CAST"charset=");
3302 if (encoding != NULL) {
3303 encoding += 8;
3304 } else {
3305 encoding = xmlStrcasestr(attvalue, BAD_CAST"charset =");
3306 if (encoding != NULL)
3307 encoding += 9;
3308 }
3309 if (encoding != NULL) {
3310 xmlCharEncoding enc;
3311 xmlCharEncodingHandlerPtr handler;
3312
3313 while ((*encoding == ' ') || (*encoding == '\t')) encoding++;
3314
3315 if (ctxt->input->encoding != NULL)
3316 xmlFree((xmlChar *) ctxt->input->encoding);
3317 ctxt->input->encoding = xmlStrdup(encoding);
3318
3319 enc = xmlParseCharEncoding((const char *) encoding);
3320 /*
3321 * registered set of known encodings
3322 */
3323 if (enc != XML_CHAR_ENCODING_ERROR) {
3324 if (((enc == XML_CHAR_ENCODING_UTF16LE) ||
3325 (enc == XML_CHAR_ENCODING_UTF16BE) ||
3326 (enc == XML_CHAR_ENCODING_UCS4LE) ||
3327 (enc == XML_CHAR_ENCODING_UCS4BE)) &&
3328 (ctxt->input->buf != NULL) &&
3329 (ctxt->input->buf->encoder == NULL)) {
3330 htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING,
3331 "htmlCheckEncoding: wrong encoding meta\n",
3332 NULL, NULL);
3333 } else {
3334 xmlSwitchEncoding(ctxt, enc);
3335 }
3336 ctxt->charset = XML_CHAR_ENCODING_UTF8;
3337 } else {
3338 /*
3339 * fallback for unknown encodings
3340 */
3341 handler = xmlFindCharEncodingHandler((const char *) encoding);
3342 if (handler != NULL) {
3343 xmlSwitchToEncoding(ctxt, handler);
3344 ctxt->charset = XML_CHAR_ENCODING_UTF8;
3345 } else {
3346 ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;
3347 }

Callers 2

htmlCheckMetaFunction · 0.85
htmlCreateFileParserCtxtFunction · 0.85

Calls 9

xmlStrcasestrFunction · 0.85
xmlStrdupFunction · 0.85
xmlParseCharEncodingFunction · 0.85
htmlParseErrFunction · 0.85
xmlSwitchEncodingFunction · 0.85
xmlSwitchToEncodingFunction · 0.85
xmlBufferShrinkFunction · 0.85
xmlCharEncInFuncFunction · 0.85

Tested by

no test coverage detected