35 #if defined( DEBUG_PARSER )
36 # if defined( DEBUG ) && defined( _MSC_VER )
38 # define TIXML_LOG OutputDebugString
40 # define TIXML_LOG printf
52 {
""", 6,
'\"' },
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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
82 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
83 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
84 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
85 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
86 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
87 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
88 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
94 const unsigned long BYTE_MASK = 0xBF;
95 const unsigned long BYTE_MARK = 0x80;
96 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
100 else if ( input < 0x800 )
102 else if ( input < 0x10000 )
104 else if ( input < 0x200000 )
107 { *length = 0;
return; }
116 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
120 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
124 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
128 *output = (char)(input | FIRST_BYTE_MARK[*length]);
143 return isalpha( anyByte );
164 return isalnum( anyByte );
219 const unsigned char* pU = (
const unsigned char*)p;
268 if ( *(p+1) && *(p+2) )
274 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU )
276 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU )
328 const unsigned char* pU = (
const unsigned char*)p;
362 while ( ( *p &&
IsWhiteSpace( *p ) ) || *p ==
'\n' || *p ==
'\r' )
374 if ( !in->good() )
return false;
381 *tag += (char) in->get();
391 if ( c == character )
422 && (
IsAlpha( (
unsigned char) *p, encoding ) || *p ==
'_' ) )
424 const char* start =
p;
426 && (
IsAlphaNum( (
unsigned char ) *p, encoding )
436 name->assign( start, p-start );
450 if ( *(p+1) && *(p+1) ==
'#' && *(p+2) )
452 unsigned long ucs = 0;
459 if ( !*(p+3) )
return 0;
462 q = strchr( q,
';' );
464 if ( !q || !*q )
return 0;
471 if ( *q >=
'0' && *q <=
'9' )
472 ucs += mult * (*q -
'0');
473 else if ( *q >=
'a' && *q <=
'f' )
474 ucs += mult * (*q -
'a' + 10);
475 else if ( *q >=
'A' && *q <=
'F' )
476 ucs += mult * (*q -
'A' + 10 );
486 if ( !*(p+2) )
return 0;
489 q = strchr( q,
';' );
491 if ( !q || !*q )
return 0;
498 if ( *q >=
'0' && *q <=
'9' )
499 ucs += mult * (*q -
'0');
516 return p + delta + 1;
522 if ( strncmp(
entity[i].str, p,
entity[i].strLength ) == 0 )
524 assert( strlen(
entity[i].str ) ==
entity[i].strLength );
527 return ( p +
entity[i].strLength );
556 while ( *q && *tag &&
ToLower( *q, encoding ) ==
ToLower( *tag, encoding ) )
567 while ( *q && *tag && *q == *tag )
583 bool caseInsensitive,
592 && !
StringEqual( p, endTag, caseInsensitive, encoding )
596 char cArr[4] = { 0, 0, 0, 0 };
597 p =
GetChar( p, cArr, &len, encoding );
598 text->append( cArr, len );
603 bool whitespace =
false;
608 && !
StringEqual( p, endTag, caseInsensitive, encoding ) )
610 if ( *p ==
'\r' || *p ==
'\n' )
630 char cArr[4] = { 0, 0, 0, 0 };
631 p =
GetChar( p, cArr, &len, encoding );
635 text->append( cArr, len );
640 p += strlen( endTag );
663 int tagIndex = (int) tag->length();
664 while ( in->good() && in->peek() !=
'>' )
742 const unsigned char* pU = (
const unsigned char*)p;
764 p = node->
Parse( p, &data, encoding );
815 if ( pError && data )
817 data->
Stamp( pError, encoding );
828 if( !p || !*p || *p !=
'<' )
848 const char* xmlHeader = {
"<?xml" };
849 const char* commentHeader = {
"<!--" };
850 const char* dtdHeader = {
"<!" };
851 const char* cdataHeader = {
"<![CDATA[" };
856 TIXML_LOG(
"XML parsing Declaration\n" );
860 else if (
StringEqual( p, commentHeader,
false, encoding ) )
863 TIXML_LOG(
"XML parsing Comment\n" );
867 else if (
StringEqual( p, cdataHeader,
false, encoding ) )
870 TIXML_LOG(
"XML parsing CDATA\n" );
876 else if (
StringEqual( p, dtdHeader,
false, encoding ) )
879 TIXML_LOG(
"XML parsing Unknown(1)\n" );
883 else if (
IsAlpha( *(p+1), encoding )
887 TIXML_LOG(
"XML parsing Element\n" );
894 TIXML_LOG(
"XML parsing Unknown(2)\n" );
902 returnNode->
parent =
this;
934 if ( tag->length() < 3 )
return;
939 if ( tag->at( tag->length() - 1 ) ==
'>'
940 && tag->at( tag->length() - 2 ) ==
'/' )
945 else if ( tag->at( tag->length() - 1 ) ==
'>' )
957 if ( in->good() && in->peek() !=
'<' )
970 if ( !in->good() )
return;
971 assert( in->peek() ==
'<' );
972 int tagIndex = (int) tag->length();
974 bool closingTag =
false;
975 bool firstCharFound =
false;
998 if ( c ==
'[' && tag->size() >= 9 )
1000 size_t len = tag->size();
1001 const char* start = tag->c_str() + len - 9;
1002 if ( strcmp( start,
"<![CDATA[" ) == 0 ) {
1003 assert( !closingTag );
1008 if ( !firstCharFound && c !=
'<' && !
IsWhiteSpace( c ) )
1010 firstCharFound =
true;
1039 const char* tagloc = tag->c_str() + tagIndex;
1067 data->
Stamp( p, encoding );
1080 const char* pErr =
p;
1115 else if ( *p ==
'>' )
1130 if (
StringEqual( p, endTag.c_str(),
false, encoding ) )
1132 p += endTag.length();
1153 p = attrib->
Parse( p, data, encoding );
1163 #ifdef TIXML_USE_STL
1187 const char* pWithWhiteSpace =
p;
1205 p = textNode->
Parse( p, data, encoding );
1211 p = textNode->
Parse( pWithWhiteSpace, data, encoding );
1214 if ( !textNode->
Blank() )
1233 p = node->
Parse( p, data, encoding );
1242 pWithWhiteSpace =
p;
1254 #ifdef TIXML_USE_STL
1257 while ( in->good() )
1286 data->
Stamp( p, encoding );
1289 if ( !p || !*p || *p !=
'<' )
1297 while ( p && *p && *p !=
'>' )
1312 #ifdef TIXML_USE_STL
1315 while ( in->good() )
1329 && tag->at( tag->length() - 2 ) ==
'-'
1330 && tag->at( tag->length() - 3 ) ==
'-' )
1349 data->
Stamp( p, encoding );
1352 const char* startTag =
"<!--";
1353 const char* endTag =
"-->";
1355 if ( !
StringEqual( p, startTag,
false, encoding ) )
1360 p += strlen( startTag );
1382 while ( p && *p && !
StringEqual( p, endTag,
false, encoding ) )
1384 value.append( p, 1 );
1388 p += strlen( endTag );
1397 if ( !p || !*p )
return 0;
1405 data->
Stamp( p, encoding );
1409 const char* pErr =
p;
1417 if ( !p || !*p || *p !=
'=' )
1432 const char SINGLE_QUOTE =
'\'';
1433 const char DOUBLE_QUOTE =
'\"';
1435 if ( *p == SINGLE_QUOTE )
1441 else if ( *p == DOUBLE_QUOTE )
1455 && *p !=
'/' && *p !=
'>' )
1457 if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
1471 #ifdef TIXML_USE_STL
1474 while ( in->good() )
1477 if ( !
cdata && (c ==
'<' ) )
1492 if (
cdata && c ==
'>' && tag->size() >= 3 ) {
1493 size_t len = tag->size();
1494 if ( (*tag)[len-2] ==
']' && (*tag)[len-3] ==
']' ) {
1510 data->
Stamp( p, encoding );
1514 const char*
const startTag =
"<![CDATA[";
1515 const char*
const endTag =
"]]>";
1521 if ( !
StringEqual( p, startTag,
false, encoding ) )
1526 p += strlen( startTag );
1538 p =
ReadText( p, &dummy,
false, endTag,
false, encoding );
1543 bool ignoreWhite =
true;
1545 const char*
end =
"<";
1546 p =
ReadText( p, &
value, ignoreWhite, end,
false, encoding );
1553 #ifdef TIXML_USE_STL
1556 while ( in->good() )
1583 if ( !p || !*p || !
StringEqual( p,
"<?xml",
true, _encoding ) )
1590 data->
Stamp( p, _encoding );
1608 if (
StringEqual( p,
"version",
true, _encoding ) )
1611 p = attrib.
Parse( p, data, _encoding );
1614 else if (
StringEqual( p,
"encoding",
true, _encoding ) )
1617 p = attrib.
Parse( p, data, _encoding );
1620 else if (
StringEqual( p,
"standalone",
true, _encoding ) )
1623 p = attrib.
Parse( p, data, _encoding );
1638 for (
unsigned i=0;
i<
value.length();
i++ )
static const int utf8ByteTable[256]
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
const unsigned char TIXML_UTF_LEAD_2
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
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)
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
const char * Value() const
Return the value of this attribute.
const TiXmlCursor & Cursor()
static const char * errorString[TIXML_ERROR_STRING_COUNT]
const unsigned char TIXML_UTF_LEAD_0
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.
const unsigned char TIXML_UTF_LEAD_1
static bool IsWhiteSpace(char c)
TiXmlAttributeSet attributeSet
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)
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 TiXmlAttribute * Find(const char *_name) const
static Entity entity[NUM_ENTITY]
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
friend class TiXmlElement
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
static bool StreamTo(std::istream *in, int character, TIXML_STRING *tag)
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)
void Add(TiXmlAttribute *attribute)
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)
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
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)
void SetValue(const char *_value)
Set the value.
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
static bool StreamWhiteSpace(std::istream *in, TIXML_STRING *tag)
TiXmlCursor errorLocation