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

Function htmlFindEncoding

ThirdParty/libxml2/vtklibxml2/HTMLparser.c:312–351  ·  view source on GitHub ↗

* htmlFindEncoding: * @the HTML parser context * * Ty to find and encoding in the current data available in the input * buffer this is needed to try to switch to the proper encoding when * one face a character error. * That's an heuristic, since it's operating outside of parsing it could * try to use a meta which had been commented out, that's the reason it * should only be used in case of

Source from the content-addressed store, hash-verified

310 * be freed
311 */
312static xmlChar *
313htmlFindEncoding(xmlParserCtxtPtr ctxt) {
314 const xmlChar *start, *cur, *end;
315 xmlChar *ret;
316
317 if ((ctxt == NULL) || (ctxt->input == NULL) ||
318 (ctxt->input->flags & XML_INPUT_HAS_ENCODING))
319 return(NULL);
320 if ((ctxt->input->cur == NULL) || (ctxt->input->end == NULL))
321 return(NULL);
322
323 start = ctxt->input->cur;
324 end = ctxt->input->end;
325 /* we also expect the input buffer to be zero terminated */
326 if (*end != 0)
327 return(NULL);
328
329 cur = xmlStrcasestr(start, BAD_CAST "HTTP-EQUIV");
330 if (cur == NULL)
331 return(NULL);
332 cur = xmlStrcasestr(cur, BAD_CAST "CONTENT");
333 if (cur == NULL)
334 return(NULL);
335 cur = xmlStrcasestr(cur, BAD_CAST "CHARSET=");
336 if (cur == NULL)
337 return(NULL);
338 cur += 8;
339 start = cur;
340 while (((*cur >= 'A') && (*cur <= 'Z')) ||
341 ((*cur >= 'a') && (*cur <= 'z')) ||
342 ((*cur >= '0') && (*cur <= '9')) ||
343 (*cur == '-') || (*cur == '_') || (*cur == ':') || (*cur == '/'))
344 cur++;
345 if (cur == start)
346 return(NULL);
347 ret = xmlStrndup(start, cur - start);
348 if (ret == NULL)
349 htmlErrMemory(ctxt);
350 return(ret);
351}
352
353/**
354 * htmlCurrentChar:

Callers 1

htmlCurrentCharFunction · 0.85

Calls 3

xmlStrcasestrFunction · 0.85
xmlStrndupFunction · 0.85
htmlErrMemoryFunction · 0.85

Tested by

no test coverage detected