38 #if defined( DEBUG_PARSER )
39 # if defined( DEBUG ) && defined( _MSC_VER )
41 # define TIXML_LOG OutputDebugString
43 # define TIXML_LOG printf
55 {
""", 6,
'\"' },
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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
86 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
87 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
88 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
89 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
90 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
91 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
97 const unsigned long BYTE_MASK = 0xBF;
98 const unsigned long BYTE_MARK = 0x80;
99 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
103 else if ( input < 0x800 )
105 else if ( input < 0x10000 )
107 else if ( input < 0x200000 )
110 { *length = 0;
return; }
119 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
123 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
127 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
131 *output = (char)(input | FIRST_BYTE_MARK[*length]);
146 return isalpha( anyByte );
167 return isalnum( anyByte );
222 const unsigned char* pU = (
const unsigned char*)p;
271 if ( *(p+1) && *(p+2) )
277 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU )
279 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU )
331 const unsigned char* pU = (
const unsigned char*)p;
365 while ( ( *p &&
IsWhiteSpace( *p ) ) || *p ==
'\n' || *p ==
'\r' )
377 if ( !in->good() )
return false;
384 *tag += (char) in->get();
394 if ( c == character )
425 && (
IsAlpha( (
unsigned char) *p, encoding ) || *p ==
'_' ) )
429 && (
IsAlphaNum( (
unsigned char ) *p, encoding )
439 name->assign( start, p-start );
453 if ( *(p+1) && *(p+1) ==
'#' && *(p+2) )
455 unsigned long ucs = 0;
462 if ( !*(p+3) )
return 0;
465 q = strchr( q,
';' );
467 if ( !q || !*q )
return 0;
474 if ( *q >=
'0' && *q <=
'9' )
475 ucs += mult * (*q -
'0');
476 else if ( *q >=
'a' && *q <=
'f' )
477 ucs += mult * (*q -
'a' + 10);
478 else if ( *q >=
'A' && *q <=
'F' )
479 ucs += mult * (*q -
'A' + 10 );
489 if ( !*(p+2) )
return 0;
492 q = strchr( q,
';' );
494 if ( !q || !*q )
return 0;
501 if ( *q >=
'0' && *q <=
'9' )
502 ucs += mult * (*q -
'0');
519 return p + delta + 1;
525 if ( strncmp(
entity[i].str, p,
entity[i].strLength ) == 0 )
527 assert( strlen(
entity[i].str ) ==
entity[i].strLength );
530 return ( p +
entity[i].strLength );
559 while ( *q && *tag &&
ToLower( *q, encoding ) ==
ToLower( *tag, encoding ) )
570 while ( *q && *tag && *q == *tag )
586 bool caseInsensitive,
595 && !
StringEqual( p, endTag, caseInsensitive, encoding )
599 char cArr[4] = { 0, 0, 0, 0 };
600 p =
GetChar( p, cArr, &len, encoding );
601 text->append( cArr, len );
606 bool whitespace =
false;
611 && !
StringEqual( p, endTag, caseInsensitive, encoding ) )
613 if ( *p ==
'\r' || *p ==
'\n' )
633 char cArr[4] = { 0, 0, 0, 0 };
634 p =
GetChar( p, cArr, &len, encoding );
638 text->append( cArr, len );
643 p += strlen( endTag );
666 int tagIndex = (int) tag->length();
667 while ( in->good() && in->peek() !=
'>' )
745 const unsigned char* pU = (
const unsigned char*)p;
767 p = node->
Parse( p, &data, encoding );
820 if ( pError && data )
822 data->
Stamp( pError, encoding );
833 if( !p || !*p || *p !=
'<' )
853 const char* xmlHeader = {
"<?xml" };
854 const char* commentHeader = {
"<!--" };
855 const char* dtdHeader = {
"<!" };
856 const char* cdataHeader = {
"<![CDATA[" };
861 TIXML_LOG(
"XML parsing Declaration\n" );
865 else if (
StringEqual( p, commentHeader,
false, encoding ) )
868 TIXML_LOG(
"XML parsing Comment\n" );
872 else if (
StringEqual( p, cdataHeader,
false, encoding ) )
875 TIXML_LOG(
"XML parsing CDATA\n" );
881 else if (
StringEqual( p, dtdHeader,
false, encoding ) )
884 TIXML_LOG(
"XML parsing Unknown(1)\n" );
888 else if (
IsAlpha( *(p+1), encoding )
892 TIXML_LOG(
"XML parsing Element\n" );
899 TIXML_LOG(
"XML parsing Unknown(2)\n" );
907 returnNode->
parent =
this;
939 if ( tag->length() < 3 )
return;
944 if ( tag->at( tag->length() - 1 ) ==
'>'
945 && tag->at( tag->length() - 2 ) ==
'/' )
950 else if ( tag->at( tag->length() - 1 ) ==
'>' )
962 if ( in->good() && in->peek() !=
'<' )
975 if ( !in->good() )
return;
976 assert( in->peek() ==
'<' );
977 int tagIndex = (int) tag->length();
979 bool closingTag =
false;
980 bool firstCharFound =
false;
1003 if ( c ==
'[' && tag->size() >= 9 )
1005 size_t len = tag->size();
1006 const char*
start = tag->c_str() + len - 9;
1007 if ( strcmp( start,
"<![CDATA[" ) == 0 ) {
1008 assert( !closingTag );
1013 if ( !firstCharFound && c !=
'<' && !
IsWhiteSpace( c ) )
1015 firstCharFound =
true;
1044 const char* tagloc = tag->c_str() + tagIndex;
1072 data->
Stamp( p, encoding );
1085 const char* pErr =
p;
1120 else if ( *p ==
'>' )
1135 if (
StringEqual( p, endTag.c_str(),
false, encoding ) )
1137 p += endTag.length();
1158 p = attrib->
Parse( p, data, encoding );
1168 #ifdef TIXML_USE_STL
1192 const char* pWithWhiteSpace =
p;
1210 p = textNode->
Parse( p, data, encoding );
1216 p = textNode->
Parse( pWithWhiteSpace, data, encoding );
1219 if ( !textNode->
Blank() )
1238 p = node->
Parse( p, data, encoding );
1247 pWithWhiteSpace =
p;
1259 #ifdef TIXML_USE_STL
1262 while ( in->good() )
1291 data->
Stamp( p, encoding );
1294 if ( !p || !*p || *p !=
'<' )
1302 while ( p && *p && *p !=
'>' )
1317 #ifdef TIXML_USE_STL
1320 while ( in->good() )
1334 && tag->at( tag->length() - 2 ) ==
'-'
1335 && tag->at( tag->length() - 3 ) ==
'-' )
1354 data->
Stamp( p, encoding );
1357 const char* startTag =
"<!--";
1358 const char* endTag =
"-->";
1360 if ( !
StringEqual( p, startTag,
false, encoding ) )
1365 p += strlen( startTag );
1387 while ( p && *p && !
StringEqual( p, endTag,
false, encoding ) )
1389 value.append( p, 1 );
1393 p += strlen( endTag );
1402 if ( !p || !*p )
return 0;
1410 data->
Stamp( p, encoding );
1414 const char* pErr =
p;
1422 if ( !p || !*p || *p !=
'=' )
1437 const char SINGLE_QUOTE =
'\'';
1438 const char DOUBLE_QUOTE =
'\"';
1440 if ( *p == SINGLE_QUOTE )
1446 else if ( *p == DOUBLE_QUOTE )
1460 && *p !=
'/' && *p !=
'>' )
1462 if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
1476 #ifdef TIXML_USE_STL
1479 while ( in->good() )
1482 if ( !
cdata && (c ==
'<' ) )
1497 if (
cdata && c ==
'>' && tag->size() >= 3 ) {
1498 size_t len = tag->size();
1499 if ( (*tag)[len-2] ==
']' && (*tag)[len-3] ==
']' ) {
1515 data->
Stamp( p, encoding );
1519 const char*
const startTag =
"<![CDATA[";
1520 const char*
const endTag =
"]]>";
1526 if ( !
StringEqual( p, startTag,
false, encoding ) )
1531 p += strlen( startTag );
1543 p =
ReadText( p, &dummy,
false, endTag,
false, encoding );
1548 bool ignoreWhite =
true;
1550 const char*
end =
"<";
1551 p =
ReadText( p, &
value, ignoreWhite, end,
false, encoding );
1558 #ifdef TIXML_USE_STL
1561 while ( in->good() )
1588 if ( !p || !*p || !
StringEqual( p,
"<?xml",
true, _encoding ) )
1595 data->
Stamp( p, _encoding );
1613 if (
StringEqual( p,
"version",
true, _encoding ) )
1616 p = attrib.
Parse( p, data, _encoding );
1619 else if (
StringEqual( p,
"encoding",
true, _encoding ) )
1622 p = attrib.
Parse( p, data, _encoding );
1625 else if (
StringEqual( p,
"standalone",
true, _encoding ) )
1628 p = attrib.
Parse( p, data, _encoding );
1643 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)
char data[epos_bytes_allocation]
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