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

Function xmlParseCharRef

ThirdParty/libxml2/vtklibxml2/parser.c:2594–2682  ·  view source on GitHub ↗

* xmlParseCharRef: * @ctxt: an XML parser context * * DEPRECATED: Internal function, don't use. * * Parse a numeric character reference. Always consumes '&'. * * [66] CharRef ::= '&#' [0-9]+ ';' | * '&#x' [0-9a-fA-F]+ ';' * * [ WFC: Legal Character ] * Characters referred to using character references must match the * production for Char. * * Returns the value parse

Source from the content-addressed store, hash-verified

2592 * Returns the value parsed (as an int), 0 in case of error
2593 */
2594int
2595xmlParseCharRef(xmlParserCtxtPtr ctxt) {
2596 int val = 0;
2597 int count = 0;
2598
2599 /*
2600 * Using RAW/CUR/NEXT is okay since we are working on ASCII range here
2601 */
2602 if ((RAW == '&') && (NXT(1) == '#') &&
2603 (NXT(2) == 'x')) {
2604 SKIP(3);
2605 GROW;
2606 while ((RAW != ';') && (PARSER_STOPPED(ctxt) == 0)) {
2607 if (count++ > 20) {
2608 count = 0;
2609 GROW;
2610 }
2611 if ((RAW >= '0') && (RAW <= '9'))
2612 val = val * 16 + (CUR - '0');
2613 else if ((RAW >= 'a') && (RAW <= 'f') && (count < 20))
2614 val = val * 16 + (CUR - 'a') + 10;
2615 else if ((RAW >= 'A') && (RAW <= 'F') && (count < 20))
2616 val = val * 16 + (CUR - 'A') + 10;
2617 else {
2618 xmlFatalErr(ctxt, XML_ERR_INVALID_HEX_CHARREF, NULL);
2619 val = 0;
2620 break;
2621 }
2622 if (val > 0x110000)
2623 val = 0x110000;
2624
2625 NEXT;
2626 count++;
2627 }
2628 if (RAW == ';') {
2629 /* on purpose to avoid reentrancy problems with NEXT and SKIP */
2630 ctxt->input->col++;
2631 ctxt->input->cur++;
2632 }
2633 } else if ((RAW == '&') && (NXT(1) == '#')) {
2634 SKIP(2);
2635 GROW;
2636 while (RAW != ';') { /* loop blocked by count */
2637 if (count++ > 20) {
2638 count = 0;
2639 GROW;
2640 }
2641 if ((RAW >= '0') && (RAW <= '9'))
2642 val = val * 10 + (CUR - '0');
2643 else {
2644 xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL);
2645 val = 0;
2646 break;
2647 }
2648 if (val > 0x110000)
2649 val = 0x110000;
2650
2651 NEXT;

Callers 2

xmlParseAttValueInternalFunction · 0.85
xmlParseReferenceFunction · 0.85

Calls 1

xmlFatalErrFunction · 0.85

Tested by

no test coverage detected