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 )
103 { *length = 0;
return; }
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 );
207 int row = cursor.row;
208 int col = cursor.col;
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 )
307 assert( cursor.row >= -1 );
308 assert( cursor.col >= -1 );
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 )
431 name->assign( start, p-start );
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 );
737 const unsigned char* pU = (
const unsigned char*)p;
759 p = node->
Parse( p, &data, encoding );
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 ==
'>' )
1109 p = ReadValue( p, data, encoding );
1122 if (
StringEqual( p, endTag.c_str(),
false, encoding ) )
1124 p += endTag.length();
1126 if ( p && *p && *p ==
'>' ) {
1150 p = attrib->
Parse( p, data, encoding );
1160 #ifdef TIXML_USE_STL 1172 attributeSet.Add( attrib );
1184 const char* pWithWhiteSpace = p;
1201 p = textNode->
Parse( p, data, encoding );
1207 p = textNode->
Parse( pWithWhiteSpace, data, encoding );
1210 if ( !textNode->
Blank() )
1229 p = node->
Parse( p, data, encoding );
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;
1404 p =
ReadName( p, &name, encoding );
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 =
"]]>";
1511 if ( cdata ||
StringEqual( p, startTag,
false, encoding ) )
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 ) )
1606 p = attrib.
Parse( p, data, _encoding );
1607 version = attrib.
Value();
1609 else if (
StringEqual( p,
"encoding",
true, _encoding ) )
1612 p = attrib.
Parse( p, data, _encoding );
1613 encoding = attrib.
Value();
1615 else if (
StringEqual( p,
"standalone",
true, _encoding ) )
1618 p = attrib.
Parse( p, data, _encoding );
1619 standalone = attrib.
Value();
1633 for (
unsigned i=0; i<
value.length(); i++ )
static const int utf8ByteTable[256]
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
friend class TiXmlElement
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
static int ToLower(int v, TiXmlEncoding encoding)
static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding)
const TIXML_STRING & NameTStr() const
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
const unsigned char TIXML_UTF_LEAD_2
const char * Value() const
Return the value of this attribute.
static const char * errorString[TIXML_ERROR_STRING_COUNT]
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
static bool condenseWhiteSpace
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
const char * Encoding() const
Encoding. Will return an empty string if none was found.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
const char * Name() const
Return the name of this attribute.
static bool IsWhiteSpace(char c)
const TiXmlEncoding TIXML_DEFAULT_ENCODING
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
static const char * ReadText(const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
const unsigned char TIXML_UTF_LEAD_1
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
void SetCDATA(bool _cdata)
Turns on or off a CDATA representation of text.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
const unsigned char TIXML_UTF_LEAD_0
static Entity entity[NUM_ENTITY]
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
const char * ReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
const TiXmlDocument * GetDocument() const
static const char * GetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding)
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
void Stamp(const char *now, TiXmlEncoding encoding)
const TiXmlCursor & Cursor() const
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
TiXmlParsingData(const char *start, int _tabsize, int row, int col)
void SetDocument(TiXmlDocument *doc)
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
TiXmlCursor errorLocation