MCPcopy Create free account
hub / github.com/Norbyte/bg3se / GetCharacterRef

Method GetCharacterRef

CoreLib/tinyxml2.cpp:470–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468
469
470const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
471{
472 // Presume an entity, and pull it out.
473 *length = 0;
474
475 if ( *(p+1) == '#' && *(p+2) ) {
476 unsigned long ucs = 0;
477 TIXMLASSERT( sizeof( ucs ) >= 4 );
478 ptrdiff_t delta = 0;
479 unsigned mult = 1;
480 static const char SEMICOLON = ';';
481
482 if ( *(p+2) == 'x' ) {
483 // Hexadecimal.
484 const char* q = p+3;
485 if ( !(*q) ) {
486 return 0;
487 }
488
489 q = strchr( q, SEMICOLON );
490
491 if ( !q ) {
492 return 0;
493 }
494 TIXMLASSERT( *q == SEMICOLON );
495
496 delta = q-p;
497 --q;
498
499 while ( *q != 'x' ) {
500 unsigned int digit = 0;
501
502 if ( *q >= '0' && *q <= '9' ) {
503 digit = *q - '0';
504 }
505 else if ( *q >= 'a' && *q <= 'f' ) {
506 digit = *q - 'a' + 10;
507 }
508 else if ( *q >= 'A' && *q <= 'F' ) {
509 digit = *q - 'A' + 10;
510 }
511 else {
512 return 0;
513 }
514 TIXMLASSERT( digit < 16 );
515 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
516 const unsigned int digitScaled = mult * digit;
517 TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
518 ucs += digitScaled;
519 TIXMLASSERT( mult <= UINT_MAX / 16 );
520 mult *= 16;
521 --q;
522 }
523 }
524 else {
525 // Decimal.
526 const char* q = p+2;
527 if ( !(*q) ) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected