MCPcopy Create free account
hub / github.com/NanoMichael/MicroTeX / GetCharacterRef

Method GetCharacterRef

src/xml/tinyxml2.cpp:334–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332
333
334const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) {
335 // Presume an entity, and pull it out.
336 *length = 0;
337
338 if ( *(p+1) == '#' && *(p+2) ) {
339 unsigned long ucs = 0;
340 TIXMLASSERT( sizeof( ucs ) >= 4 );
341 ptrdiff_t delta = 0;
342 unsigned mult = 1;
343 static const char SEMICOLON = ';';
344
345 if ( *(p+2) == 'x' ) {
346 // Hexadecimal.
347 const char* q = p+3;
348 if ( !(*q) ) {
349 return 0;
350 }
351
352 q = strchr( q, SEMICOLON );
353
354 if ( !q ) {
355 return 0;
356 }
357 TIXMLASSERT( *q == SEMICOLON );
358
359 delta = q-p;
360 --q;
361
362 while ( *q != 'x' ) {
363 unsigned int digit = 0;
364
365 if ( *q >= '0' && *q <= '9' ) {
366 digit = *q - '0';
367 } else if ( *q >= 'a' && *q <= 'f' ) {
368 digit = *q - 'a' + 10;
369 } else if ( *q >= 'A' && *q <= 'F' ) {
370 digit = *q - 'A' + 10;
371 } else {
372 return 0;
373 }
374 TIXMLASSERT( digit >= 0 && digit < 16);
375 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
376 const unsigned int digitScaled = mult * digit;
377 TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
378 ucs += digitScaled;
379 TIXMLASSERT( mult <= UINT_MAX / 16 );
380 mult *= 16;
381 --q;
382 }
383 } else {
384 // Decimal.
385 const char* q = p+2;
386 if ( !(*q) ) {
387 return 0;
388 }
389
390 q = strchr( q, SEMICOLON );
391

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected