27 #if defined(ANDROID_NDK) || defined(__QNXNTO__) 75 if (
this == other ) {
98 if ( _flags & NEEDS_DELETE ) {
110 size_t len = strlen( str );
111 _start =
new char[ len+1 ];
112 memcpy( _start, str, len+1 );
114 _flags = flags | NEEDS_DELETE;
123 char endChar = *endTag;
124 size_t length = strlen( endTag );
128 if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
129 Set( start, p, strFlags );
147 char*
const start = p;
191 if ( _flags & NEEDS_FLUSH ) {
193 _flags ^= NEEDS_FLUSH;
200 if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p ==
CR ) {
204 if ( *(p+1) ==
LF ) {
212 else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p ==
LF ) {
213 if ( *(p+1) ==
CR ) {
221 else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p ==
'&' ) {
227 if ( *(p+1) ==
'#' ) {
228 const int buflen = 10;
229 char buf[buflen] = { 0 };
232 if ( adjusted == 0 ) {
241 memcpy( q, buf, len );
248 const Entity& entity = entities[i];
250 && *( p + entity.
length + 1 ) ==
';' ) {
258 if ( i == NUM_ENTITIES ) {
276 CollapseWhitespace();
278 _flags = (_flags & NEEDS_DELETE);
294 const unsigned char* pu =
reinterpret_cast<const unsigned char*
>(p);
309 const unsigned long BYTE_MASK = 0xBF;
310 const unsigned long BYTE_MARK = 0x80;
311 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
316 else if ( input < 0x800 ) {
319 else if ( input < 0x10000 ) {
322 else if ( input < 0x200000 ) {
336 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
340 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
344 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
348 *output = (char)(input | FIRST_BYTE_MARK[*length]);
361 if ( *(p+1) ==
'#' && *(p+2) ) {
362 unsigned long ucs = 0;
366 static const char SEMICOLON =
';';
368 if ( *(p+2) ==
'x' ) {
375 q = strchr( q, SEMICOLON );
385 while ( *q !=
'x' ) {
386 unsigned int digit = 0;
388 if ( *q >=
'0' && *q <=
'9' ) {
391 else if ( *q >=
'a' && *q <=
'f' ) {
392 digit = *q -
'a' + 10;
394 else if ( *q >=
'A' && *q <=
'F' ) {
395 digit = *q -
'A' + 10;
400 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
402 const unsigned int digitScaled = mult * digit;
417 q = strchr( q, SEMICOLON );
427 while ( *q !=
'#' ) {
428 if ( *q >=
'0' && *q <=
'9' ) {
429 const unsigned int digit = *q -
'0';
430 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
431 const unsigned int digitScaled = mult * digit;
444 ConvertUTF32ToUTF8( ucs, value, length );
445 return p + delta + 1;
503 if ( ToInt( str, &ival )) {
504 *value = (ival==0) ?
false :
true;
507 if ( StringEqual( str,
"true" ) ) {
511 else if ( StringEqual( str,
"false" ) ) {
540 char*
const start = p;
550 static const char* xmlHeader = {
"<?" };
551 static const char* commentHeader = {
"<!--" };
552 static const char* dtdHeader = {
"<!" };
553 static const char* cdataHeader = {
"<![CDATA[" };
554 static const char* elementHeader = {
"<" };
556 static const int xmlHeaderLen = 2;
557 static const int commentHeaderLen = 4;
558 static const int dtdHeaderLen = 2;
559 static const int cdataHeaderLen = 9;
560 static const int elementHeaderLen = 1;
568 returnNode->_memPool = &_commentPool;
573 returnNode =
new (_commentPool.Alloc())
XMLComment(
this );
574 returnNode->_memPool = &_commentPool;
575 p += commentHeaderLen;
583 text->SetCData(
true );
587 returnNode =
new (_commentPool.Alloc())
XMLUnknown(
this );
588 returnNode->_memPool = &_commentPool;
593 returnNode =
new (_elementPool.Alloc())
XMLElement(
this );
594 returnNode->_memPool = &_elementPool;
595 p += elementHeaderLen;
599 returnNode =
new (_textPool.Alloc())
XMLText(
this );
600 returnNode->_memPool = &_textPool;
616 if ( !node->Accept( visitor ) ) {
630 _firstChild( 0 ), _lastChild( 0 ),
631 _prev( 0 ), _next( 0 ),
685 if ( child->
_prev ) {
688 if ( child->
_next ) {
775 if ( afterThis->
_parent !=
this ) {
780 if ( afterThis->
_next == 0 ) {
785 addThis->
_prev = afterThis;
788 afterThis->
_next = addThis;
901 bool mismatch =
false;
902 if ( endTag.
Empty() ) {
950 const char*
start = p;
951 if ( this->CData() ) {
997 return visitor->
Visit( *
this );
1016 const char*
start = p;
1046 return visitor->
Visit( *
this );
1066 const char*
start = p;
1097 return visitor->
Visit( *
this );
1115 const char*
start = p;
1146 return visitor->
Visit( *
this );
1153 return _name.GetStr();
1164 p = _name.ParseName( p );
1177 if ( *p !=
'\"' && *p !=
'\'' ) {
1181 char endTag[2] = { *p, 0 };
1458 last = attrib, attrib = attrib->
_next ) {
1468 last->
_next = attrib;
1474 attrib->_memPool->SetTracked();
1501 const char*
start = p;
1517 attrib->_memPool->SetTracked();
1520 if ( !p ||
Attribute( attrib->Name() ) ) {
1530 if ( prevAttribute ) {
1531 prevAttribute->
_next = attrib;
1536 prevAttribute = attrib;
1539 else if ( *p ==
'/' && *(p+1) ==
'>' ) {
1544 else if ( *p ==
'>' ) {
1558 if ( attribute == 0 ) {
1563 pool->
Free( attribute );
1643 if ( !node->Accept( visitor ) ) {
1658 "XML_WRONG_ATTRIBUTE_TYPE",
1659 "XML_ERROR_FILE_NOT_FOUND",
1660 "XML_ERROR_FILE_COULD_NOT_BE_OPENED",
1661 "XML_ERROR_FILE_READ_ERROR",
1662 "XML_ERROR_ELEMENT_MISMATCH",
1663 "XML_ERROR_PARSING_ELEMENT",
1664 "XML_ERROR_PARSING_ATTRIBUTE",
1665 "XML_ERROR_IDENTIFYING_TAG",
1666 "XML_ERROR_PARSING_TEXT",
1667 "XML_ERROR_PARSING_CDATA",
1668 "XML_ERROR_PARSING_COMMENT",
1669 "XML_ERROR_PARSING_DECLARATION",
1670 "XML_ERROR_PARSING_UNKNOWN",
1671 "XML_ERROR_EMPTY_DOCUMENT",
1672 "XML_ERROR_MISMATCHED_ELEMENT",
1673 "XML_ERROR_PARSING",
1674 "XML_CAN_NOT_CONVERT_TEXT",
1682 _processEntities( processEntities ),
1684 _whitespace( whitespace ),
1704 const bool hadError =
Error();
1736 ele->SetName( name );
1746 comment->SetValue( str );
1756 text->SetValue( str );
1766 dec->SetValue( str ? str :
"xml version=\"1.0\" encoding=\"UTF-8\"" );
1776 unk->SetValue( str );
1780 static FILE*
callfopen(
const char* filepath,
const char* mode )
1784 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) 1786 errno_t err = fopen_s( &fp, filepath, mode );
1791 FILE* fp = fopen( filepath, mode );
1832 fseek( fp, 0, SEEK_SET );
1833 if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) {
1838 fseek( fp, 0, SEEK_END );
1839 const long filelength = ftell( fp );
1840 fseek( fp, 0, SEEK_SET );
1841 if ( filelength == -1L ) {
1846 const size_t size = filelength;
1854 if ( read != size ) {
1891 if ( len == 0 || !p || !*p ) {
1895 if ( len == (
size_t)(-1) ) {
1921 streamer = &stdStreamer;
1944 static const int LEN = 20;
1945 char buf1[LEN] = { 0 };
1946 char buf2[LEN] = { 0 };
1955 printf(
"XMLDocument error id=%d '%s' str1=%s str2=%s\n",
1975 _elementJustOpened( false ),
1976 _firstElement( true ),
1981 _compactMode( compact )
1988 const char entityValue = entities[i].
value;
1989 TIXMLASSERT( 0 <= entityValue && entityValue < ENTITY_RANGE );
2002 va_start( va, format );
2005 vfprintf(
_fp, format, va );
2008 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) 2013 char* str =
new char[len]();
2014 len = _vsnprintf(str, len, format, va);
2018 int len = _vscprintf( format, va );
2021 int len = vsnprintf( 0, 0, format, va );
2025 va_start( va, format );
2028 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) 2030 _vsnprintf( p, len+1, format, va );
2032 vsnprintf_s( p, len+1, _TRUNCATE, format, va );
2035 vsnprintf( p, len+1, format, va );
2044 for(
int i=0; i<depth; ++i ) {
2063 if ( flag[(
unsigned char)(*q)] ) {
2069 if ( entities[i].value == *q ) {
2070 Print(
"&%s;", entities[i].pattern );
2108 if ( !compactMode ) {
2112 Print(
"<%s", name );
2122 Print(
" %s=\"", name );
2173 Print(
"</%s>", name );
2179 if (
_depth == 0 && !compactMode) {
2202 Print(
"<![CDATA[" );
2203 Print(
"%s", text );
2259 Print(
"<!--%s-->", comment );
2271 Print(
"<?%s?>", value );
2283 Print(
"<!%s>", value );
2302 while ( attribute ) {
2304 attribute = attribute->
Next();
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
XMLText * NewText(const char *text)
virtual bool Visit(const XMLText &text)
Visit a text node.
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
virtual bool Accept(XMLVisitor *visitor) const
void SetError(XMLError error, const char *str1, const char *str2)
virtual bool ShallowEqual(const XMLNode *compare) const
void CollapseWhitespace()
static const char LINE_FEED
void SetText(const char *inText)
void SealElementIfJustOpened()
void InsertChildPreamble(XMLNode *insertThis) const
static void ToStr(int v, char *buffer, int bufferSize)
XMLAttribute * FindOrCreateAttribute(const char *name)
virtual bool Accept(XMLVisitor *visitor) const
const char * Name() const
Get the name of an element (which is the Value() of the node.)
static const char * GetCharacterRef(const char *p, char *value, int *length)
static const unsigned char TIXML_UTF_LEAD_0
XMLError LoadFile(const char *filename)
void PushComment(const char *comment)
Add a comment.
char * ParseDeep(char *p, StrPair *endTag)
static const Entity entities[NUM_ENTITIES]
XMLAttribute * _rootAttribute
MemPoolT< sizeof(XMLAttribute) > _attributePool
static const char * SkipWhiteSpace(const char *p)
static bool ToFloat(const char *str, float *value)
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
char * ParseDeep(char *, StrPair *endTag)
void PushHeader(bool writeBOM, bool writeDeclaration)
bool Error() const
Return true if there was an error parsing the document.
void Unlink(XMLNode *child)
void PushDeclaration(const char *value)
virtual void Free(void *)=0
Whitespace WhitespaceMode() const
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
static bool IsNameChar(unsigned char ch)
static bool IsWhiteSpace(char p)
void Print(XMLPrinter *streamer=0) const
static const char * ReadBOM(const char *p, bool *hasBOM)
void TransferTo(StrPair *other)
char * ParseDeep(char *p, bool processEntities)
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
static const char DOUBLE_QUOTE
virtual bool Accept(XMLVisitor *visitor) const
static const char * _errorNames[XML_ERROR_COUNT]
static bool ToBool(const char *str, bool *value)
virtual bool VisitExit(const XMLDocument &)
Visit a document.
char * ParseName(char *in)
void SetAttribute(const char *value)
Set the attribute to a string value.
XMLError QueryFloatText(float *fval) const
See QueryIntText()
void Print(const char *format,...)
XMLPrinter(FILE *file=0, bool compact=false, int depth=0)
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an optionally supplied name...
void Clear()
Clear the document, resetting it to the initial state.
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
virtual char * ParseDeep(char *, StrPair *)
const XMLNode * Parent() const
Get the parent of this node on the DOM.
XMLElement * NewElement(const char *name)
DynArray< char, 20 > _buffer
static const unsigned char TIXML_UTF_LEAD_2
char * ParseDeep(char *, StrPair *endTag)
static bool ToInt(const char *str, int *value)
void SetName(const char *name)
XMLError SaveFile(const char *filename, bool compact=false)
XMLError QueryDoubleText(double *dval) const
See QueryIntText()
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
static bool ToUnsigned(const char *str, unsigned *value)
const char * GetText() const
void PushText(const char *text, bool cdata=false)
Add a text node.
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
static const char CARRIAGE_RETURN
void PrintError() const
If there is an error, print it to stdout.
XMLComment * NewComment(const char *comment)
virtual void CloseElement(bool compactMode=false)
If streaming, close the Element.
virtual bool ShallowEqual(const XMLNode *compare) const
virtual XMLNode * ShallowClone(XMLDocument *document) const
const char * Name() const
The name of the attribute.
void DeleteNode(XMLNode *node)
virtual void SetTracked()=0
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
static bool ToDouble(const char *str, double *value)
MemPoolT< sizeof(XMLComment) > _commentPool
const char * Value() const
The value of the attribute.
virtual bool Accept(XMLVisitor *visitor) const
static const char SINGLE_QUOTE
virtual bool ShallowEqual(const XMLNode *compare) const
virtual bool VisitExit(const XMLDocument &)
Visit a document.
virtual ~XMLDeclaration()
void OpenElement(const char *name, bool compactMode=false)
void SetStr(const char *str, int flags=0)
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
XMLDeclaration(XMLDocument *doc)
XMLNode * InsertFirstChild(XMLNode *addThis)
virtual XMLNode * ShallowClone(XMLDocument *document) const
XMLError QueryUnsignedText(unsigned *uval) const
See QueryIntText()
XMLElement(XMLDocument *doc)
const char * ErrorName() const
char * ParseAttributes(char *p)
XMLError QueryIntValue(int *value) const
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
XMLDocument(bool processEntities=true, Whitespace=PRESERVE_WHITESPACE)
constructor
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
char * Identify(char *p, XMLNode **node)
XMLError QueryBoolText(bool *bval) const
See QueryIntText()
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
static void DeleteNode(XMLNode *node)
const char * Attribute(const char *name, const char *value=0) const
void SetValue(const char *val, bool staticMem=false)
const XMLElement * FirstChildElement(const char *value=0) const
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
const XMLAttribute * Next() const
The next attribute in the list.
static const int NUM_ENTITIES
void PushUnknown(const char *value)
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
DynArray< const char *, 10 > _stack
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
void DeleteAttribute(const char *name)
const XMLElement * LastChildElement(const char *value=0) const
void PrintString(const char *, bool restrictedEntitySet)
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual XMLNode * ShallowClone(XMLDocument *document) const
XMLUnknown(XMLDocument *doc)
static bool IsNameStartChar(unsigned char ch)
void DeleteChild(XMLNode *node)
virtual bool ShallowEqual(const XMLNode *compare) const
virtual XMLText * ToText()
Safely cast to Text, or null.
bool CData() const
Returns true if this is a CDATA text element.
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
virtual void PrintSpace(int depth)
XMLUnknown * NewUnknown(const char *text)
virtual bool CompactMode(const XMLElement &)
MemPoolT< sizeof(XMLText) > _textPool
char * ParseDeep(char *, StrPair *endTag)
XMLDeclaration * NewDeclaration(const char *text=0)
MemPoolT< sizeof(XMLElement) > _elementPool
const char * Value() const
bool NoChildren() const
Returns true if this node has no children.
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
bool _restrictedEntityFlag[ENTITY_RANGE]
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
XMLError QueryIntText(int *ival) const
char * ParseText(char *in, const char *endTag, int strFlags)
bool ProcessEntities() const
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
static const unsigned char TIXML_UTF_LEAD_1
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
static FILE * callfopen(const char *filepath, const char *mode)
XMLNode * InsertEndChild(XMLNode *addThis)
bool _entityFlag[ENTITY_RANGE]
virtual bool Accept(XMLVisitor *visitor) const
void SetInternedStr(const char *str)