35 #if defined( DEBUG_PARSER )
36 # if defined( DEBUG ) && defined( _MSC_VER )
38 # define TIXML_LOG OutputDebugString
40 # define TIXML_LOG printf
56 {
""", 6,
'\"' },
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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
89 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
90 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
91 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
92 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
98 const unsigned long BYTE_MASK = 0xBF;
99 const unsigned long BYTE_MARK = 0x80;
100 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
104 else if ( input < 0x800 )
106 else if ( input < 0x10000 )
108 else if ( input < 0x200000 )
111 { *length = 0;
return; }
120 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
124 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
128 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
132 *output = (char)(input | FIRST_BYTE_MARK[*length]);
147 return isalpha( anyByte );
168 return isalnum( anyByte );
217 const char* p =
stamp;
223 const unsigned char* pU = (
const unsigned char*)p;
272 if ( *(p+1) && *(p+2) )
278 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU )
280 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU )
332 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 ==
'_' ) )
427 const char* start = 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 );
818 if ( pError && data )
820 data->
Stamp( pError, encoding );
831 if( !p || !*p || *p !=
'<' )
851 const char* xmlHeader = {
"<?xml" };
852 const char* commentHeader = {
"<!--" };
853 const char* dtdHeader = {
"<!" };
854 const char* cdataHeader = {
"<![CDATA[" };
859 TIXML_LOG(
"XML parsing Declaration\n" );
863 else if (
StringEqual( p, commentHeader,
false, encoding ) )
866 TIXML_LOG(
"XML parsing Comment\n" );
870 else if (
StringEqual( p, cdataHeader,
false, encoding ) )
873 TIXML_LOG(
"XML parsing CDATA\n" );
879 else if (
StringEqual( p, dtdHeader,
false, encoding ) )
882 TIXML_LOG(
"XML parsing Unknown(1)\n" );
886 else if (
IsAlpha( *(p+1), encoding )
890 TIXML_LOG(
"XML parsing Element\n" );
897 TIXML_LOG(
"XML parsing Unknown(2)\n" );
905 returnNode->
parent =
this;
937 if ( tag->length() < 3 )
return;
942 if ( tag->at( tag->length() - 1 ) ==
'>'
943 && tag->at( tag->length() - 2 ) ==
'/' )
948 else if ( tag->at( tag->length() - 1 ) ==
'>' )
960 if ( in->
good() && in->
peek() !=
'<' )
964 text.StreamIn( in, tag );
973 if ( !in->
good() )
return;
974 assert( in->
peek() ==
'<' );
975 int tagIndex = (int) tag->length();
977 bool closingTag =
false;
978 bool firstCharFound =
false;
1001 if ( c ==
'[' && tag->size() >= 9 )
1003 size_t len = tag->size();
1004 const char* start = tag->c_str() + len - 9;
1005 if (
strcmp( start,
"<![CDATA[" ) == 0 ) {
1006 assert( !closingTag );
1011 if ( !firstCharFound && c !=
'<' && !
IsWhiteSpace( c ) )
1013 firstCharFound =
true;
1042 const char* tagloc = tag->c_str() + tagIndex;
1070 data->
Stamp( p, encoding );
1083 const char* pErr = p;
1118 else if ( *p ==
'>' )
1129 if (
StringEqual( p, endTag.c_str(),
false, encoding ) )
1131 p += endTag.length();
1152 p = attrib->
Parse( p, data, encoding );
1162 #ifdef TIXML_USE_STL
1186 const char* pWithWhiteSpace = p;
1204 p = textNode->
Parse( p, data, encoding );
1210 p = textNode->
Parse( pWithWhiteSpace, data, encoding );
1213 if ( !textNode->
Blank() )
1232 p = node->
Parse( p, data, encoding );
1241 pWithWhiteSpace = p;
1253 #ifdef TIXML_USE_STL
1256 while ( in->
good() )
1285 data->
Stamp( p, encoding );
1288 if ( !p || !*p || *p !=
'<' )
1296 while ( p && *p && *p !=
'>' )
1311 #ifdef TIXML_USE_STL
1314 while ( in->
good() )
1328 && tag->at( tag->length() - 2 ) ==
'-'
1329 && tag->at( tag->length() - 3 ) ==
'-' )
1348 data->
Stamp( p, encoding );
1351 const char* startTag =
"<!--";
1352 const char* endTag =
"-->";
1354 if ( !
StringEqual( p, startTag,
false, encoding ) )
1359 p += strlen( startTag );
1368 if ( !p || !*p )
return 0;
1376 data->
Stamp( p, encoding );
1380 const char* pErr = p;
1388 if ( !p || !*p || *p !=
'=' )
1403 const char SINGLE_QUOTE =
'\'';
1404 const char DOUBLE_QUOTE =
'\"';
1406 if ( *p == SINGLE_QUOTE )
1412 else if ( *p == DOUBLE_QUOTE )
1426 && *p !=
'/' && *p !=
'>' )
1428 if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
1442 #ifdef TIXML_USE_STL
1445 while ( in->
good() )
1448 if ( !
cdata && (c ==
'<' ) )
1463 if (
cdata && c ==
'>' && tag->size() >= 3 ) {
1464 size_t len = tag->size();
1465 if ( (*tag)[len-2] ==
']' && (*tag)[len-3] ==
']' ) {
1481 data->
Stamp( p, encoding );
1485 const char*
const startTag =
"<![CDATA[";
1486 const char*
const endTag =
"]]>";
1492 if ( !
StringEqual( p, startTag,
false, encoding ) )
1497 p += strlen( startTag );
1509 p =
ReadText( p, &dummy,
false, endTag,
false, encoding );
1514 bool ignoreWhite =
true;
1516 const char* end =
"<";
1517 p =
ReadText( p, &
value, ignoreWhite, end,
false, encoding );
1524 #ifdef TIXML_USE_STL
1527 while ( in->
good() )
1554 if ( !p || !*p || !
StringEqual( p,
"<?xml",
true, _encoding ) )
1561 data->
Stamp( p, _encoding );
1579 if (
StringEqual( p,
"version",
true, _encoding ) )
1582 p = attrib.
Parse( p, data, _encoding );
1585 else if (
StringEqual( p,
"encoding",
true, _encoding ) )
1588 p = attrib.
Parse( p, data, _encoding );
1591 else if (
StringEqual( p,
"standalone",
true, _encoding ) )
1594 p = attrib.
Parse( p, data, _encoding );
1609 for (
unsigned i=0; i<
value.length(); i++ )
static const int utf8ByteTable[256]
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
An attribute is a name-value pair.
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
const unsigned char TIXML_UTF_LEAD_2
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
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)
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
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)
void ClearError()
If you have handled the error, it can be reset with this call.
const char * Value() const
Return the value of this attribute.
const TiXmlCursor & Cursor()
static bool StreamTo(std::istream *in, int character, TIXML_STRING *tag)
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 void StreamIn(std::istream *in, TIXML_STRING *tag)
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)
Add a new node related to this.
const char * Name() const
Return the name of this attribute.
const unsigned char TIXML_UTF_LEAD_1
In correct XML the declaration is the first entry in the file.
static bool IsWhiteSpace(char c)
TiXmlAttributeSet attributeSet
Any tag that tinyXml doesn't recognize is saved as an unknown.
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.
Always the top level node.
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 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
Return a pointer to the Document this node lives in.
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)
Parse the given null terminated block of xml data.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
The parent class for everything in the Document Object Model.
void Stamp(const char *now, TiXmlEncoding encoding)
static bool StreamWhiteSpace(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)
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
TiXmlCursor errorLocation