ReactOS 0.4.15-dev-8135-g1bc6c90
tinyxml2::XMLUtil Class Reference

#include <tinyxml2.h>

Static Public Member Functions

static const charSkipWhiteSpace (const char *p)
 
static charSkipWhiteSpace (char *p)
 
static bool IsWhiteSpace (char p)
 
static bool IsNameStartChar (unsigned char ch)
 
static bool IsNameChar (unsigned char ch)
 
static bool StringEqual (const char *p, const char *q, int nChar=INT_MAX)
 
static bool IsUTF8Continuation (char p)
 
static const charReadBOM (const char *p, bool *hasBOM)
 
static const charGetCharacterRef (const char *p, char *value, int *length)
 
static void ConvertUTF32ToUTF8 (unsigned long input, char *output, int *length)
 
static void ToStr (int v, char *buffer, int bufferSize)
 
static void ToStr (unsigned v, char *buffer, int bufferSize)
 
static void ToStr (bool v, char *buffer, int bufferSize)
 
static void ToStr (float v, char *buffer, int bufferSize)
 
static void ToStr (double v, char *buffer, int bufferSize)
 
static bool ToInt (const char *str, int *value)
 
static bool ToUnsigned (const char *str, unsigned *value)
 
static bool ToBool (const char *str, bool *value)
 
static bool ToFloat (const char *str, float *value)
 
static bool ToDouble (const char *str, double *value)
 

Detailed Description

Definition at line 516 of file tinyxml2.h.

Member Function Documentation

◆ ConvertUTF32ToUTF8()

void tinyxml2::XMLUtil::ConvertUTF32ToUTF8 ( unsigned long  input,
char output,
int length 
)
static

Definition at line 381 of file tinyxml2.cpp.

382{
383 const unsigned long BYTE_MASK = 0xBF;
384 const unsigned long BYTE_MARK = 0x80;
385 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
386
387 if (input < 0x80) {
388 *length = 1;
389 }
390 else if ( input < 0x800 ) {
391 *length = 2;
392 }
393 else if ( input < 0x10000 ) {
394 *length = 3;
395 }
396 else if ( input < 0x200000 ) {
397 *length = 4;
398 }
399 else {
400 *length = 0; // This code won't convert this correctly anyway.
401 return;
402 }
403
404 output += *length;
405
406 // Scary scary fall throughs.
407 switch (*length) {
408 case 4:
409 --output;
410 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
411 input >>= 6;
412 case 3:
413 --output;
414 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
415 input >>= 6;
416 case 2:
417 --output;
418 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
419 input >>= 6;
420 case 1:
421 --output;
422 *output = (char)(input | FIRST_BYTE_MARK[*length]);
423 break;
424 default:
425 TIXMLASSERT( false );
426 }
427}
unsigned char
Definition: typeof.h:29
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLenum GLenum GLenum input
Definition: glext.h:9031
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

Referenced by GetCharacterRef().

◆ GetCharacterRef()

const char * tinyxml2::XMLUtil::GetCharacterRef ( const char p,
char value,
int length 
)
static

Definition at line 430 of file tinyxml2.cpp.

431{
432 // Presume an entity, and pull it out.
433 *length = 0;
434
435 if ( *(p+1) == '#' && *(p+2) ) {
436 unsigned long ucs = 0;
437 TIXMLASSERT( sizeof( ucs ) >= 4 );
438 ptrdiff_t delta = 0;
439 unsigned mult = 1;
440 static const char SEMICOLON = ';';
441
442 if ( *(p+2) == 'x' ) {
443 // Hexadecimal.
444 const char* q = p+3;
445 if ( !(*q) ) {
446 return 0;
447 }
448
449 q = strchr( q, SEMICOLON );
450
451 if ( !q ) {
452 return 0;
453 }
454 TIXMLASSERT( *q == SEMICOLON );
455
456 delta = q-p;
457 --q;
458
459 while ( *q != 'x' ) {
460 unsigned int digit = 0;
461
462 if ( *q >= '0' && *q <= '9' ) {
463 digit = *q - '0';
464 }
465 else if ( *q >= 'a' && *q <= 'f' ) {
466 digit = *q - 'a' + 10;
467 }
468 else if ( *q >= 'A' && *q <= 'F' ) {
469 digit = *q - 'A' + 10;
470 }
471 else {
472 return 0;
473 }
474 TIXMLASSERT( digit < 16 );
475 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
476 const unsigned int digitScaled = mult * digit;
477 TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
478 ucs += digitScaled;
479 TIXMLASSERT( mult <= UINT_MAX / 16 );
480 mult *= 16;
481 --q;
482 }
483 }
484 else {
485 // Decimal.
486 const char* q = p+2;
487 if ( !(*q) ) {
488 return 0;
489 }
490
491 q = strchr( q, SEMICOLON );
492
493 if ( !q ) {
494 return 0;
495 }
496 TIXMLASSERT( *q == SEMICOLON );
497
498 delta = q-p;
499 --q;
500
501 while ( *q != '#' ) {
502 if ( *q >= '0' && *q <= '9' ) {
503 const unsigned int digit = *q - '0';
504 TIXMLASSERT( digit < 10 );
505 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
506 const unsigned int digitScaled = mult * digit;
507 TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
508 ucs += digitScaled;
509 }
510 else {
511 return 0;
512 }
513 TIXMLASSERT( mult <= UINT_MAX / 10 );
514 mult *= 10;
515 --q;
516 }
517 }
518 // convert the UCS to UTF-8
520 return p + delta + 1;
521 }
522 return p+1;
523}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
Definition: tinyxml2.cpp:381
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
#define ULONG_MAX
Definition: limits.h:44
#define UINT_MAX
Definition: limits.h:41
Definition: pdh_main.c:94

Referenced by tinyxml2::StrPair::GetStr().

◆ IsNameChar()

static bool tinyxml2::XMLUtil::IsNameChar ( unsigned char  ch)
inlinestatic

Definition at line 548 of file tinyxml2.h.

548 {
549 return IsNameStartChar( ch )
550 || isdigit( ch )
551 || ch == '.'
552 || ch == '-';
553 }
#define isdigit(c)
Definition: acclib.h:68
static bool IsNameStartChar(unsigned char ch)
Definition: tinyxml2.h:537

Referenced by tinyxml2::StrPair::ParseName().

◆ IsNameStartChar()

static bool tinyxml2::XMLUtil::IsNameStartChar ( unsigned char  ch)
inlinestatic

Definition at line 537 of file tinyxml2.h.

537 {
538 if ( ch >= 128 ) {
539 // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
540 return true;
541 }
542 if ( isalpha( ch ) ) {
543 return true;
544 }
545 return ch == ':' || ch == '_';
546 }
#define isalpha(c)
Definition: acclib.h:74

Referenced by IsNameChar(), tinyxml2::XMLElement::ParseAttributes(), and tinyxml2::StrPair::ParseName().

◆ IsUTF8Continuation()

static bool tinyxml2::XMLUtil::IsUTF8Continuation ( char  p)
inlinestatic

Definition at line 562 of file tinyxml2.h.

562 {
563 return ( p & 0x80 ) != 0;
564 }

Referenced by IsWhiteSpace().

◆ IsWhiteSpace()

static bool tinyxml2::XMLUtil::IsWhiteSpace ( char  p)
inlinestatic

Definition at line 533 of file tinyxml2.h.

533 {
534 return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
535 }
#define isspace(c)
Definition: acclib.h:69
static bool IsUTF8Continuation(char p)
Definition: tinyxml2.h:562

Referenced by tinyxml2::StrPair::CollapseWhitespace(), and SkipWhiteSpace().

◆ ReadBOM()

const char * tinyxml2::XMLUtil::ReadBOM ( const char p,
bool hasBOM 
)
static

Definition at line 363 of file tinyxml2.cpp.

364{
365 TIXMLASSERT( p );
366 TIXMLASSERT( bom );
367 *bom = false;
368 const unsigned char* pu = reinterpret_cast<const unsigned char*>(p);
369 // Check for BOM:
370 if ( *(pu+0) == TIXML_UTF_LEAD_0
371 && *(pu+1) == TIXML_UTF_LEAD_1
372 && *(pu+2) == TIXML_UTF_LEAD_2 ) {
373 *bom = true;
374 p += 3;
375 }
376 TIXMLASSERT( p );
377 return p;
378}
static const unsigned char TIXML_UTF_LEAD_0
Definition: tinyxml2.cpp:115
static const unsigned char TIXML_UTF_LEAD_1
Definition: tinyxml2.cpp:116
static const unsigned char TIXML_UTF_LEAD_2
Definition: tinyxml2.cpp:117

Referenced by tinyxml2::XMLDocument::Parse().

◆ SkipWhiteSpace() [1/2]

static char * tinyxml2::XMLUtil::SkipWhiteSpace ( char p)
inlinestatic

Definition at line 527 of file tinyxml2.h.

527 {
528 return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p) ) );
529 }
static const char * SkipWhiteSpace(const char *p)
Definition: tinyxml2.h:519

◆ SkipWhiteSpace() [2/2]

static const char * tinyxml2::XMLUtil::SkipWhiteSpace ( const char p)
inlinestatic

◆ StringEqual()

◆ ToBool()

bool tinyxml2::XMLUtil::ToBool ( const char str,
bool value 
)
static

Definition at line 575 of file tinyxml2.cpp.

576{
577 int ival = 0;
578 if ( ToInt( str, &ival )) {
579 *value = (ival==0) ? false : true;
580 return true;
581 }
582 if ( StringEqual( str, "true" ) ) {
583 *value = true;
584 return true;
585 }
586 else if ( StringEqual( str, "false" ) ) {
587 *value = false;
588 return true;
589 }
590 return false;
591}
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
Definition: tinyxml2.h:555
static bool ToInt(const char *str, int *value)
Definition: tinyxml2.cpp:559
const WCHAR * str

Referenced by tinyxml2::XMLElement::QueryBoolText(), and tinyxml2::XMLAttribute::QueryBoolValue().

◆ ToDouble()

bool tinyxml2::XMLUtil::ToDouble ( const char str,
double value 
)
static

Definition at line 602 of file tinyxml2.cpp.

603{
604 if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) {
605 return true;
606 }
607 return false;
608}
#define TIXML_SSCANF
Definition: tinyxml2.cpp:100

Referenced by tinyxml2::XMLElement::QueryDoubleText(), and tinyxml2::XMLAttribute::QueryDoubleValue().

◆ ToFloat()

bool tinyxml2::XMLUtil::ToFloat ( const char str,
float value 
)
static

Definition at line 594 of file tinyxml2.cpp.

595{
596 if ( TIXML_SSCANF( str, "%f", value ) == 1 ) {
597 return true;
598 }
599 return false;
600}

Referenced by tinyxml2::XMLElement::QueryFloatText(), and tinyxml2::XMLAttribute::QueryFloatValue().

◆ ToInt()

bool tinyxml2::XMLUtil::ToInt ( const char str,
int value 
)
static

Definition at line 559 of file tinyxml2.cpp.

560{
561 if ( TIXML_SSCANF( str, "%d", value ) == 1 ) {
562 return true;
563 }
564 return false;
565}

Referenced by tinyxml2::XMLElement::QueryIntText(), tinyxml2::XMLAttribute::QueryIntValue(), and ToBool().

◆ ToStr() [1/5]

void tinyxml2::XMLUtil::ToStr ( bool  v,
char buffer,
int  bufferSize 
)
static

Definition at line 538 of file tinyxml2.cpp.

539{
540 TIXML_SNPRINTF( buffer, bufferSize, "%d", v ? 1 : 0 );
541}
size_t bufferSize
const GLdouble * v
Definition: gl.h:2040
GLuint buffer
Definition: glext.h:5915
#define TIXML_SNPRINTF
Definition: tinyxml2.cpp:92

◆ ToStr() [2/5]

void tinyxml2::XMLUtil::ToStr ( double  v,
char buffer,
int  bufferSize 
)
static

Definition at line 553 of file tinyxml2.cpp.

554{
555 TIXML_SNPRINTF( buffer, bufferSize, "%.17g", v );
556}

◆ ToStr() [3/5]

void tinyxml2::XMLUtil::ToStr ( float  v,
char buffer,
int  bufferSize 
)
static

Definition at line 547 of file tinyxml2.cpp.

548{
549 TIXML_SNPRINTF( buffer, bufferSize, "%.8g", v );
550}

◆ ToStr() [4/5]

void tinyxml2::XMLUtil::ToStr ( int  v,
char buffer,
int  bufferSize 
)
static

◆ ToStr() [5/5]

void tinyxml2::XMLUtil::ToStr ( unsigned  v,
char buffer,
int  bufferSize 
)
static

Definition at line 532 of file tinyxml2.cpp.

533{
535}

◆ ToUnsigned()

bool tinyxml2::XMLUtil::ToUnsigned ( const char str,
unsigned value 
)
static

Definition at line 567 of file tinyxml2.cpp.

568{
569 if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
570 return true;
571 }
572 return false;
573}

Referenced by tinyxml2::XMLElement::QueryUnsignedText(), and tinyxml2::XMLAttribute::QueryUnsignedValue().


The documentation for this class was generated from the following files: