31 #if defined( DEBUG_PARSER )
32 # if defined( DEBUG ) && defined( _MSC_VER )
34 # define TIXML_LOG OutputDebugString
36 # define TIXML_LOG printf
48 {
""", 6,
'\"' },
69 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
70 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
71 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
72 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
73 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
74 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
75 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
76 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
77 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
78 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
79 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
80 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
81 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
82 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
83 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
84 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
90 const unsigned long BYTE_MASK = 0xBF;
91 const unsigned long BYTE_MARK = 0x80;
92 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
96 else if ( input < 0x800 )
98 else if ( input < 0x10000 )
100 else if ( input < 0x200000 )
112 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
116 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
120 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
124 *output = (char)(input | FIRST_BYTE_MARK[*
length]);
139 return isalpha( anyByte );
160 return isalnum( anyByte );
209 const char* p =
stamp;
215 const unsigned char* pU = (
const unsigned char*)p;
264 if ( *(p+1) && *(p+2) )
270 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU )
272 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU )
324 const unsigned char* pU = (
const unsigned char*)p;
365 bool TiXmlBase::StreamWhiteSpace( std::istream * in,
TIXML_STRING * tag )
369 if ( !in->good() )
return false;
376 *tag += (char) in->get();
380 bool TiXmlBase::StreamTo( std::istream * in,
int character,
TIXML_STRING * tag )
386 if ( c == character )
417 && (
IsAlpha( (
unsigned char) *p, encoding ) || *p ==
'_' ) )
419 const char*
start = p;
421 && (
IsAlphaNum( (
unsigned char ) *p, encoding )
445 if ( *(p+1) && *(p+1) ==
'#' && *(p+2) )
447 unsigned long ucs = 0;
454 if ( !*(p+3) )
return 0;
457 q = strchr( q,
';' );
459 if ( !q || !*q )
return 0;
466 if ( *q >=
'0' && *q <=
'9' )
467 ucs += mult * (*q -
'0');
468 else if ( *q >=
'a' && *q <=
'f' )
469 ucs += mult * (*q -
'a' + 10);
470 else if ( *q >=
'A' && *q <=
'F' )
471 ucs += mult * (*q -
'A' + 10 );
481 if ( !*(p+2) )
return 0;
484 q = strchr( q,
';' );
486 if ( !q || !*q )
return 0;
493 if ( *q >=
'0' && *q <=
'9' )
494 ucs += mult * (*q -
'0');
511 return p + delta + 1;
517 if ( strncmp(
entity[i].str, p,
entity[i].strLength ) == 0 )
519 assert( strlen(
entity[i].str ) ==
entity[i].strLength );
522 return ( p +
entity[i].strLength );
551 while ( *q && *tag &&
ToLower( *q, encoding ) ==
ToLower( *tag, encoding ) )
562 while ( *q && *tag && *q == *tag )
578 bool caseInsensitive,
587 && !
StringEqual( p, endTag, caseInsensitive, encoding )
591 char cArr[4] = { 0, 0, 0, 0 };
592 p =
GetChar( p, cArr, &len, encoding );
593 text->append( cArr, len );
598 bool whitespace =
false;
603 && !
StringEqual( p, endTag, caseInsensitive, encoding ) )
605 if ( *p ==
'\r' || *p ==
'\n' )
625 char cArr[4] = { 0, 0, 0, 0 };
626 p =
GetChar( p, cArr, &len, encoding );
630 text->append( cArr, len );
635 p += strlen( endTag );
636 return ( p && *p ) ? p : 0;
641 void TiXmlDocument::StreamIn( std::istream * in,
TIXML_STRING * tag )
650 if ( !StreamTo( in,
'<', tag ) )
658 int tagIndex = (int) tag->length();
659 while ( in->good() && in->peek() !=
'>' )
679 node->StreamIn( in, tag );
680 bool isElement = node->ToElement() != 0;
737 const unsigned char* pU = (
const unsigned char*)p;
769 && node->ToDeclaration() )
810 if ( pError &&
data )
812 data->Stamp( pError, encoding );
823 if( !p || !*p || *p !=
'<' )
842 const char* xmlHeader = {
"<?xml" };
843 const char* commentHeader = {
"<!--" };
844 const char* dtdHeader = {
"<!" };
845 const char* cdataHeader = {
"<![CDATA[" };
850 TIXML_LOG(
"XML parsing Declaration\n" );
854 else if (
StringEqual( p, commentHeader,
false, encoding ) )
857 TIXML_LOG(
"XML parsing Comment\n" );
861 else if (
StringEqual( p, cdataHeader,
false, encoding ) )
864 TIXML_LOG(
"XML parsing CDATA\n" );
870 else if (
StringEqual( p, dtdHeader,
false, encoding ) )
873 TIXML_LOG(
"XML parsing Unknown(1)\n" );
877 else if (
IsAlpha( *(p+1), encoding )
881 TIXML_LOG(
"XML parsing Element\n" );
888 TIXML_LOG(
"XML parsing Unknown(2)\n" );
896 returnNode->
parent =
this;
903 void TiXmlElement::StreamIn (std::istream * in,
TIXML_STRING * tag)
923 if ( tag->length() < 3 )
return;
928 if ( tag->at( tag->length() - 1 ) ==
'>'
929 && tag->at( tag->length() - 2 ) ==
'/' )
934 else if ( tag->at( tag->length() - 1 ) ==
'>' )
943 StreamWhiteSpace( in, tag );
946 if ( in->good() && in->peek() !=
'<' )
950 text.StreamIn( in, tag );
959 if ( !in->good() )
return;
960 assert( in->peek() ==
'<' );
961 int tagIndex = (int) tag->length();
963 bool closingTag =
false;
964 bool firstCharFound =
false;
987 if ( c ==
'[' && tag->size() >= 9 )
989 size_t len = tag->size();
990 const char*
start = tag->c_str() + len - 9;
991 if ( strcmp( start,
"<![CDATA[" ) == 0 ) {
992 assert( !closingTag );
997 if ( !firstCharFound && c !=
'<' && !
IsWhiteSpace( c ) )
999 firstCharFound =
true;
1028 const char* tagloc = tag->c_str() + tagIndex;
1032 node->StreamIn( in, tag );
1056 data->Stamp( p, encoding );
1069 const char* pErr = p;
1103 else if ( *p ==
'>' )
1122 if (
StringEqual( p, endTag.c_str(),
false, encoding ) )
1124 p += endTag.length();
1126 if ( p && *p && *p ==
'>' ) {
1160 #ifdef TIXML_USE_STL
1184 const char* pWithWhiteSpace = p;
1201 p = textNode->
Parse( p,
data, encoding );
1207 p = textNode->
Parse( pWithWhiteSpace,
data, encoding );
1210 if ( !textNode->
Blank() )
1238 pWithWhiteSpace = p;
1250 #ifdef TIXML_USE_STL
1251 void TiXmlUnknown::StreamIn( std::istream * in,
TIXML_STRING * tag )
1253 while ( in->good() )
1282 data->Stamp( p, encoding );
1285 if ( !p || !*p || *p !=
'<' )
1293 while ( p && *p && *p !=
'>' )
1304 if ( p && *p ==
'>' )
1309 #ifdef TIXML_USE_STL
1310 void TiXmlComment::StreamIn( std::istream * in,
TIXML_STRING * tag )
1312 while ( in->good() )
1326 && tag->at( tag->length() - 2 ) ==
'-'
1327 && tag->at( tag->length() - 3 ) ==
'-' )
1346 data->Stamp( p, encoding );
1349 const char* startTag =
"<!--";
1350 const char* endTag =
"-->";
1352 if ( !
StringEqual( p, startTag,
false, encoding ) )
1358 p += strlen( startTag );
1380 while ( p && *p && !
StringEqual( p, endTag,
false, encoding ) )
1382 value.append( p, 1 );
1386 p += strlen( endTag );
1395 if ( !p || !*p )
return 0;
1399 data->Stamp( p, encoding );
1403 const char* pErr = p;
1411 if ( !p || !*p || *p !=
'=' )
1426 const char SINGLE_QUOTE =
'\'';
1427 const char DOUBLE_QUOTE =
'\"';
1429 if ( *p == SINGLE_QUOTE )
1435 else if ( *p == DOUBLE_QUOTE )
1449 && *p !=
'/' && *p !=
'>' )
1451 if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
1465 #ifdef TIXML_USE_STL
1466 void TiXmlText::StreamIn( std::istream * in,
TIXML_STRING * tag )
1468 while ( in->good() )
1471 if ( !
cdata && (c ==
'<' ) )
1486 if (
cdata && c ==
'>' && tag->size() >= 3 ) {
1487 size_t len = tag->size();
1488 if ( (*tag)[len-2] ==
']' && (*tag)[len-3] ==
']' ) {
1504 data->Stamp( p, encoding );
1508 const char*
const startTag =
"<![CDATA[";
1509 const char*
const endTag =
"]]>";
1515 if ( !
StringEqual( p, startTag,
false, encoding ) )
1521 p += strlen( startTag );
1533 p =
ReadText( p, &dummy,
false, endTag,
false, encoding );
1538 bool ignoreWhite =
true;
1540 const char* end =
"<";
1541 p =
ReadText( p, &
value, ignoreWhite, end,
false, encoding );
1548 #ifdef TIXML_USE_STL
1549 void TiXmlDeclaration::StreamIn( std::istream * in,
TIXML_STRING * tag )
1551 while ( in->good() )
1578 if ( !p || !*p || !
StringEqual( p,
"<?xml",
true, _encoding ) )
1585 data->Stamp( p, _encoding );
1603 if (
StringEqual( p,
"version",
true, _encoding ) )
1609 else if (
StringEqual( p,
"encoding",
true, _encoding ) )
1615 else if (
StringEqual( p,
"standalone",
true, _encoding ) )
1633 for (
unsigned i=0; i<
value.length(); i++ )