31 #if defined( DEBUG_PARSER ) 32 #define TIXML_LOG printf 43 {
""", 6,
'\"' },
64 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
65 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
66 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
67 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
68 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
77 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
78 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
79 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
85 const unsigned long BYTE_MASK = 0xBF;
86 const unsigned long BYTE_MARK = 0x80;
87 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
91 else if ( input < 0x800 )
93 else if ( input < 0x10000 )
95 else if ( input < 0x200000 )
98 { *length = 0;
return; }
107 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
112 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
117 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
122 *output = (char)(input | FIRST_BYTE_MARK[*length]);
137 return isalpha( anyByte );
158 return isalnum( anyByte );
205 int row = cursor.row;
206 int col = cursor.col;
207 const char* p = stamp;
213 const unsigned char* pU = (
const unsigned char*)p;
262 if ( *(p+1) && *(p+2) )
268 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU )
270 else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU )
305 assert( cursor.row >= -1 );
306 assert( cursor.col >= -1 );
322 const unsigned char* pU = (
const unsigned char*)p;
367 if ( !in->good() )
return false;
374 *tag += (char) in->get();
384 if ( c == character )
415 && (
IsAlpha( (
unsigned char) *p, encoding ) || *p ==
'_' ) )
417 const char*
start = p;
419 && (
IsAlphaNum( (
unsigned char ) *p, encoding )
429 name->assign( start, p-start );
443 if ( *(p+1) && *(p+1) ==
'#' && *(p+2) )
445 unsigned long ucs = 0;
452 if ( !*(p+3) )
return 0;
455 q = strchr( q,
';' );
457 if ( !q || !*q )
return 0;
464 if ( *q >=
'0' && *q <=
'9' )
465 ucs += mult * (*q -
'0');
466 else if ( *q >=
'a' && *q <=
'f' )
467 ucs += mult * (*q -
'a' + 10);
468 else if ( *q >=
'A' && *q <=
'F' )
469 ucs += mult * (*q -
'A' + 10 );
479 if ( !*(p+2) )
return 0;
482 q = strchr( q,
';' );
484 if ( !q || !*q )
return 0;
491 if ( *q >=
'0' && *q <=
'9' )
492 ucs += mult * (*q -
'0');
509 return p + delta + 1;
515 if ( strncmp(
entity[i].str, p,
entity[i].strLength ) == 0 )
517 assert( strlen(
entity[i].str ) ==
entity[i].strLength );
520 return ( p +
entity[i].strLength );
549 while ( *q && *tag &&
ToLower( *q, encoding ) ==
ToLower( *tag, encoding ) )
560 while ( *q && *tag && *q == *tag )
576 bool caseInsensitive,
585 && !
StringEqual( p, endTag, caseInsensitive, encoding )
589 char cArr[4] = { 0, 0, 0, 0 };
590 p =
GetChar( p, cArr, &len, encoding );
591 text->append( cArr, len );
596 bool whitespace =
false;
601 && !
StringEqual( p, endTag, caseInsensitive, encoding ) )
603 if ( *p ==
'\r' || *p ==
'\n' )
623 char cArr[4] = { 0, 0, 0, 0 };
624 p =
GetChar( p, cArr, &len, encoding );
628 text->append( cArr, len );
633 p += strlen( endTag );
634 return ( p && *p ) ? p : 0;
656 int tagIndex = (int) tag->length();
657 while ( in->good() && in->peek() !=
'>' )
735 const unsigned char* pU = (
const unsigned char*)p;
757 p = node->
Parse( p, &data, encoding );
808 if ( pError && data )
810 data->
Stamp( pError, encoding );
821 if( !p || !*p || *p !=
'<' )
840 const char* xmlHeader = {
"<?xml" };
841 const char* commentHeader = {
"<!--" };
842 const char* dtdHeader = {
"<!" };
843 const char* cdataHeader = {
"<![CDATA[" };
848 TIXML_LOG(
"XML parsing Declaration\n" );
852 else if (
StringEqual( p, commentHeader,
false, encoding ) )
855 TIXML_LOG(
"XML parsing Comment\n" );
859 else if (
StringEqual( p, cdataHeader,
false, encoding ) )
862 TIXML_LOG(
"XML parsing CDATA\n" );
868 else if (
StringEqual( p, dtdHeader,
false, encoding ) )
871 TIXML_LOG(
"XML parsing Unknown(1)\n" );
875 else if (
IsAlpha( *(p+1), encoding )
879 TIXML_LOG(
"XML parsing Element\n" );
886 TIXML_LOG(
"XML parsing Unknown(2)\n" );
894 returnNode->
parent =
this;
921 if ( tag->length() < 3 )
return;
926 if ( tag->at( tag->length() - 1 ) ==
'>' 927 && tag->at( tag->length() - 2 ) ==
'/' )
932 else if ( tag->at( tag->length() - 1 ) ==
'>' )
944 if ( in->good() && in->peek() !=
'<' )
957 if ( !in->good() )
return;
958 assert( in->peek() ==
'<' );
959 int tagIndex = (int) tag->length();
961 bool closingTag =
false;
962 bool firstCharFound =
false;
985 if ( c ==
'[' && tag->size() >= 9 )
987 size_t len = tag->size();
988 const char*
start = tag->c_str() + len - 9;
989 if ( strcmp( start,
"<![CDATA[" ) == 0 ) {
990 assert( !closingTag );
995 if ( !firstCharFound && c !=
'<' && !
IsWhiteSpace( c ) )
997 firstCharFound =
true;
1026 const char* tagloc = tag->c_str() + tagIndex;
1054 data->
Stamp( p, encoding );
1067 const char* pErr = p;
1101 else if ( *p ==
'>' )
1107 p = ReadValue( p, data, encoding );
1120 if (
StringEqual( p, endTag.c_str(),
false, encoding ) )
1122 p += endTag.length();
1124 if ( p && *p && *p ==
'>' ) {
1148 p = attrib->
Parse( p, data, encoding );
1158 #ifdef TIXML_USE_STL 1170 attributeSet.Add( attrib );
1182 const char* pWithWhiteSpace = p;
1199 p = textNode->
Parse( p, data, encoding );
1205 p = textNode->
Parse( pWithWhiteSpace, data, encoding );
1208 if ( !textNode->
Blank() )
1227 p = node->
Parse( p, data, encoding );
1236 pWithWhiteSpace = p;
1248 #ifdef TIXML_USE_STL 1251 while ( in->good() )
1280 data->
Stamp( p, encoding );
1283 if ( !p || !*p || *p !=
'<' )
1291 while ( p && *p && *p !=
'>' )
1302 if ( p && *p ==
'>' )
1307 #ifdef TIXML_USE_STL 1310 while ( in->good() )
1324 && tag->at( tag->length() - 2 ) ==
'-' 1325 && tag->at( tag->length() - 3 ) ==
'-' )
1344 data->
Stamp( p, encoding );
1347 const char* startTag =
"<!--";
1348 const char* endTag =
"-->";
1350 if ( !
StringEqual( p, startTag,
false, encoding ) )
1356 p += strlen( startTag );
1378 while ( p && *p && !
StringEqual( p, endTag,
false, encoding ) )
1380 value.append( p, 1 );
1384 p += strlen( endTag );
1393 if ( !p || !*p )
return 0;
1397 data->
Stamp( p, encoding );
1401 const char* pErr = p;
1409 if ( !p || !*p || *p !=
'=' )
1424 const char SINGLE_QUOTE =
'\'';
1425 const char DOUBLE_QUOTE =
'\"';
1427 if ( *p == SINGLE_QUOTE )
1433 else if ( *p == DOUBLE_QUOTE )
1447 && *p !=
'/' && *p !=
'>' )
1449 if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
1463 #ifdef TIXML_USE_STL 1466 while ( in->good() )
1469 if ( !cdata && (c ==
'<' ) )
1484 if ( cdata && c ==
'>' && tag->size() >= 3 ) {
1485 size_t len = tag->size();
1486 if ( (*tag)[len-2] ==
']' && (*tag)[len-3] ==
']' ) {
1502 data->
Stamp( p, encoding );
1506 const char*
const startTag =
"<![CDATA[";
1507 const char*
const endTag =
"]]>";
1509 if ( cdata ||
StringEqual( p, startTag,
false, encoding ) )
1513 if ( !
StringEqual( p, startTag,
false, encoding ) )
1519 p += strlen( startTag );
1531 p =
ReadText( p, &dummy,
false, endTag,
false, encoding );
1536 bool ignoreWhite =
true;
1538 const char*
end =
"<";
1539 p =
ReadText( p, &
value, ignoreWhite, end,
false, encoding );
1546 #ifdef TIXML_USE_STL 1549 while ( in->good() )
1576 if ( !p || !*p || !
StringEqual( p,
"<?xml",
true, _encoding ) )
1583 data->
Stamp( p, _encoding );
1601 if (
StringEqual( p,
"version",
true, _encoding ) )
1604 p = attrib.
Parse( p, data, _encoding );
1605 version = attrib.
Value();
1607 else if (
StringEqual( p,
"encoding",
true, _encoding ) )
1610 p = attrib.
Parse( p, data, _encoding );
1611 encoding = attrib.
Value();
1613 else if (
StringEqual( p,
"standalone",
true, _encoding ) )
1616 p = attrib.
Parse( p, data, _encoding );
1617 standalone = attrib.
Value();
1631 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)
friend class TiXmlElement
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
const char * Name() const
Return the name of this attribute.
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)
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlCursor & Cursor() const
GeneratorWrapper< T > value(T &&value)
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
const unsigned char TIXML_UTF_LEAD_2
const TIXML_STRING & NameTStr() const
static const char * errorString[TIXML_ERROR_STRING_COUNT]
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
static bool condenseWhiteSpace
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
const char * Encoding() const
Encoding. Will return an empty string if none was found.
const char * Value() const
Return the value 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 void StreamIn(std::istream *in, TIXML_STRING *tag)
static bool StreamTo(std::istream *in, int character, TIXML_STRING *tag)
const char * ReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
const TiXmlDocument * GetDocument() const
USBInterfaceDescriptor data
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)
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
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)
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
static bool StreamWhiteSpace(std::istream *in, TIXML_STRING *tag)
TiXmlCursor errorLocation