1 #ifndef DDCORE_SRC_XML_TINYXMLPARSER_INL_H
2 #define DDCORE_SRC_XML_TINYXMLPARSER_INL_H
38 #if defined( DEBUG_PARSER )
39 # if defined( DEBUG ) && defined( _MSC_VER )
41 # define TIXML_LOG OutputDebugString
43 # define TIXML_LOG printf
48 #if defined __has_cpp_attribute
49 #if __has_cpp_attribute(fallthrough)
50 #define ATTR_FALLTHROUGH [[fallthrough]]
52 #define ATTR_FALLTHROUGH
55 #define ATTR_FALLTHROUGH
71 {
""", 6,
'\"' },
92 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
93 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
94 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
95 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
96 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
97 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
98 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
99 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
100 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
101 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
102 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
103 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
104 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
105 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
106 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
107 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
113 const unsigned long BYTE_MASK = 0xBF;
114 const unsigned long BYTE_MARK = 0x80;
115 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
119 else if ( input < 0x800 )
121 else if ( input < 0x10000 )
123 else if ( input < 0x200000 )
126 { *length = 0;
return; }
135 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
140 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
145 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
150 *output = (char)(input | FIRST_BYTE_MARK[*length]);
168 return isalpha( anyByte );
189 return isalnum( anyByte );
238 const char* p =
stamp;
244 const unsigned char* pU = (
const unsigned char*)p;
293 if ( *(p+1) && *(p+2) )
299 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU )
301 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU )
353 const unsigned char* pU = (
const unsigned char*)p;
386 while ( ( *p &&
IsWhiteSpace( *p ) ) || *p ==
'\n' || *p ==
'\r' )
398 if ( !in->good() )
return false;
405 *tag += (char) in->get();
415 if ( c == character )
446 && (
IsAlpha( (
unsigned char) *p, encoding ) || *p ==
'_' ) )
448 const char* start = p;
450 && (
IsAlphaNum( (
unsigned char ) *p, encoding )
460 name->assign( start, p-start );
474 if ( *(p+1) && *(p+1) ==
'#' && *(p+2) )
476 unsigned long ucs = 0;
483 if ( !*(p+3) )
return 0;
486 q = strchr( q,
';' );
488 if ( !q || !*q )
return 0;
495 if ( *q >=
'0' && *q <=
'9' )
496 ucs += mult * (*q -
'0');
497 else if ( *q >=
'a' && *q <=
'f' )
498 ucs += mult * (*q -
'a' + 10);
499 else if ( *q >=
'A' && *q <=
'F' )
500 ucs += mult * (*q -
'A' + 10 );
510 if ( !*(p+2) )
return 0;
513 q = strchr( q,
';' );
515 if ( !q || !*q )
return 0;
522 if ( *q >=
'0' && *q <=
'9' )
523 ucs += mult * (*q -
'0');
540 return p +
delta + 1;
546 if ( strncmp(
entity[i].str, p,
entity[i].strLength ) == 0 )
548 assert( strlen(
entity[i].str ) ==
entity[i].strLength );
551 return ( p +
entity[i].strLength );
580 while ( *q && *tag &&
ToLower( *q, encoding ) ==
ToLower( *tag, encoding ) )
591 while ( *q && *tag && *q == *tag )
607 bool caseInsensitive,
616 && !
StringEqual( p, endTag, caseInsensitive, encoding )
620 char cArr[4] = { 0, 0, 0, 0 };
621 p =
GetChar( p, cArr, &len, encoding );
622 text->append( cArr, len );
627 bool whitespace =
false;
632 && !
StringEqual( p, endTag, caseInsensitive, encoding ) )
634 if ( *p ==
'\r' || *p ==
'\n' )
654 char cArr[4] = { 0, 0, 0, 0 };
655 p =
GetChar( p, cArr, &len, encoding );
659 text->append( cArr, len );
664 p += strlen( endTag );
687 int tagIndex = (int) tag->length();
688 while ( in->good() && in->peek() !=
'>' )
766 const unsigned char* pU = (
const unsigned char*)p;
788 p = node->
Parse( p, &data, encoding );
839 if ( pError && data )
841 data->
Stamp( pError, encoding );
852 if( !p || !*p || *p !=
'<' )
872 const char* xmlHeader = {
"<?xml" };
873 const char* commentHeader = {
"<!--" };
874 const char* dtdHeader = {
"<!" };
875 const char* cdataHeader = {
"<![CDATA[" };
880 TIXML_LOG(
"XML parsing Declaration\n" );
884 else if (
StringEqual( p, commentHeader,
false, encoding ) )
887 TIXML_LOG(
"XML parsing Comment\n" );
891 else if (
StringEqual( p, cdataHeader,
false, encoding ) )
894 TIXML_LOG(
"XML parsing CDATA\n" );
900 else if (
StringEqual( p, dtdHeader,
false, encoding ) )
903 TIXML_LOG(
"XML parsing Unknown(1)\n" );
907 else if (
IsAlpha( *(p+1), encoding )
911 TIXML_LOG(
"XML parsing Element\n" );
918 TIXML_LOG(
"XML parsing Unknown(2)\n" );
926 returnNode->
parent =
this;
958 if ( tag->length() < 3 )
return;
963 if ( tag->at( tag->length() - 1 ) ==
'>'
964 && tag->at( tag->length() - 2 ) ==
'/' )
969 else if ( tag->at( tag->length() - 1 ) ==
'>' )
981 if ( in->good() && in->peek() !=
'<' )
985 text.StreamIn( in, tag );
994 if ( !in->good() )
return;
995 assert( in->peek() ==
'<' );
996 int tagIndex = (int) tag->length();
998 bool closingTag =
false;
999 bool firstCharFound =
false;
1022 if ( c ==
'[' && tag->size() >= 9 )
1024 size_t len = tag->size();
1025 const char* start = tag->c_str() + len - 9;
1026 if ( strcmp( start,
"<![CDATA[" ) == 0 ) {
1027 assert( !closingTag );
1032 if ( !firstCharFound && c !=
'<' && !
IsWhiteSpace( c ) )
1034 firstCharFound =
true;
1063 const char* tagloc = tag->c_str() + tagIndex;
1091 data->
Stamp( p, encoding );
1104 const char* pErr = p;
1139 else if ( *p ==
'>' )
1150 if (
StringEqual( p, endTag.c_str(),
false, encoding ) )
1152 p += endTag.length();
1173 p = attrib->
Parse( p, data, encoding );
1183 #ifdef TIXML_USE_STL
1207 const char* pWithWhiteSpace = p;
1225 p = textNode->
Parse( p, data, encoding );
1231 p = textNode->
Parse( pWithWhiteSpace, data, encoding );
1234 if ( !textNode->
Blank() )
1253 p = node->
Parse( p, data, encoding );
1262 pWithWhiteSpace = p;
1274 #ifdef TIXML_USE_STL
1277 while ( in->good() )
1306 data->
Stamp( p, encoding );
1309 if ( !p || !*p || *p !=
'<' )
1317 while ( p && *p && *p !=
'>' )
1332 #ifdef TIXML_USE_STL
1335 while ( in->good() )
1349 && tag->at( tag->length() - 2 ) ==
'-'
1350 && tag->at( tag->length() - 3 ) ==
'-' )
1369 data->
Stamp( p, encoding );
1372 const char* startTag =
"<!--";
1373 const char* endTag =
"-->";
1375 if ( !
StringEqual( p, startTag,
false, encoding ) )
1380 p += strlen( startTag );
1389 if ( !p || !*p )
return 0;
1397 data->
Stamp( p, encoding );
1401 const char* pErr = p;
1409 if ( !p || !*p || *p !=
'=' )
1424 const char SINGLE_QUOTE =
'\'';
1425 const char DOUBLE_QUOTE =
'\"';
1427 if ( *p == SINGLE_QUOTE )
1433 else if ( *p == DOUBLE_QUOTE )
1447 && *p !=
'/' && *p !=
'>' )
1449 if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
1463 #ifdef TIXML_USE_STL
1466 while ( in->good() )
1469 if ( !
cdata && (c ==
'<' ) )
1484 if (
cdata && c ==
'>' && tag->size() >= 3 ) {
1485 size_t len = tag->size();
1486 if ( (*tag)[len-2] ==
']' && (*tag)[len-3] ==
']' ) {
1502 data->
Stamp( p, encoding );
1506 const char*
const startTag =
"<![CDATA[";
1507 const char*
const endTag =
"]]>";
1513 if ( !
StringEqual( p, startTag,
false, encoding ) )
1518 p += strlen( startTag );
1530 p =
ReadText( p, &dummy,
false, endTag,
false, encoding );
1535 bool ignoreWhite =
true;
1537 const char* end =
"<";
1538 p =
ReadText( p, &
value, ignoreWhite, end,
false, encoding );
1545 #ifdef TIXML_USE_STL
1548 while ( in->good() )
1575 if ( !p || !*p || !
StringEqual( p,
"<?xml",
true, _encoding ) )
1582 data->
Stamp( p, _encoding );
1600 if (
StringEqual( p,
"version",
true, _encoding ) )
1603 p = attrib.
Parse( p, data, _encoding );
1606 else if (
StringEqual( p,
"encoding",
true, _encoding ) )
1609 p = attrib.
Parse( p, data, _encoding );
1612 else if (
StringEqual( p,
"standalone",
true, _encoding ) )
1615 p = attrib.
Parse( p, data, _encoding );
1630 for (
unsigned i=0; i<
value.length(); i++ )