27 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
35 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
47 va_start( va, format );
48 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
55 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
59 #define TIXML_VSCPRINTF _vscprintf
60 #define TIXML_SSCANF sscanf_s
61 #elif defined _MSC_VER
63 #define TIXML_SNPRINTF _snprintf
64 #define TIXML_VSNPRINTF _vsnprintf
65 #define TIXML_SSCANF sscanf
66 #if (_MSC_VER < 1400 ) && (!defined WINCE)
68 #define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have.
76 char*
str =
new char[len]();
77 const int required = _vsnprintf(str, len, format, va);
79 if ( required != -1 ) {
92 #define TIXML_SNPRINTF snprintf
93 #define TIXML_VSNPRINTF vsnprintf
96 int len = vsnprintf( 0, 0, format, va );
100 #define TIXML_SSCANF sscanf
130 {
"quot", 4, DOUBLE_QUOTE },
132 {
"apos", 4, SINGLE_QUOTE },
146 if (
this == other ) {
183 size_t len = strlen( str );
185 _start =
new char[ len+1 ];
186 memcpy(
_start, str, len+1 );
198 char endChar = *endTag;
199 size_t length = strlen( endTag );
203 if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
204 Set( start, p, strFlags );
280 if ( *(p+1) == LF ) {
289 else if ( (
_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
290 if ( *(p+1) == CR ) {
305 if ( *(p+1) ==
'#' ) {
306 const int buflen = 10;
307 char buf[buflen] = { 0 };
310 if ( adjusted == 0 ) {
319 memcpy( q, buf, len );
324 bool entityFound =
false;
328 && *( p + entity.
length + 1 ) ==
';' ) {
337 if ( !entityFound ) {
373 const unsigned char* pu =
reinterpret_cast<const unsigned char*
>(
p);
375 if ( *(pu+0) == TIXML_UTF_LEAD_0
376 && *(pu+1) == TIXML_UTF_LEAD_1
388 const unsigned long BYTE_MASK = 0xBF;
389 const unsigned long BYTE_MARK = 0x80;
390 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
395 else if ( input < 0x800 ) {
398 else if ( input < 0x10000 ) {
401 else if ( input < 0x200000 ) {
415 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
419 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
423 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
427 *output = (char)(input | FIRST_BYTE_MARK[*length]);
440 if ( *(p+1) ==
'#' && *(p+2) ) {
441 unsigned long ucs = 0;
445 static const char SEMICOLON =
';';
447 if ( *(p+2) ==
'x' ) {
454 q = strchr( q, SEMICOLON );
464 while ( *q !=
'x' ) {
465 unsigned int digit = 0;
467 if ( *q >=
'0' && *q <=
'9' ) {
470 else if ( *q >=
'a' && *q <=
'f' ) {
471 digit = *q -
'a' + 10;
473 else if ( *q >=
'A' && *q <=
'F' ) {
474 digit = *q -
'A' + 10;
480 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
481 const unsigned int digitScaled = mult * digit;
496 q = strchr( q, SEMICOLON );
506 while ( *q !=
'#' ) {
507 if ( *q >=
'0' && *q <=
'9' ) {
508 const unsigned int digit = *q -
'0';
510 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
511 const unsigned int digitScaled = mult * digit;
525 return p + delta + 1;
590 if (
ToInt( str, &ival )) {
591 *value = (ival==0) ?
false :
true;
648 static const char* xmlHeader = {
"<?" };
649 static const char* commentHeader = {
"<!--" };
650 static const char* cdataHeader = {
"<![CDATA[" };
651 static const char* dtdHeader = {
"<!" };
652 static const char* elementHeader = {
"<" };
654 static const int xmlHeaderLen = 2;
655 static const int commentHeaderLen = 4;
656 static const int cdataHeaderLen = 9;
657 static const int dtdHeaderLen = 2;
658 static const int elementHeaderLen = 1;
673 p += commentHeaderLen;
681 text->SetCData(
true );
693 p += elementHeaderLen;
714 if ( !
node->Accept( visitor ) ) {
728 _firstChild( 0 ), _lastChild( 0 ),
729 _prev( 0 ), _next( 0 ),
785 if ( child->
_prev ) {
788 if ( child->
_next ) {
876 if ( afterThis->
_parent !=
this ) {
881 if ( afterThis->
_next == 0 ) {
886 addThis->
_prev = afterThis;
889 afterThis->
_next = addThis;
991 if ( !existingNode->ToDeclaration() ) {
997 if ( !wellLocated ) {
1018 bool mismatch =
false;
1019 if ( endTag.
Empty() ) {
1067 if ( element == 0 ) {
1083 if ( this->
CData() ) {
1129 return visitor->
Visit( *
this );
1178 return visitor->
Visit( *
this );
1229 return visitor->
Visit( *
this );
1278 return visitor->
Visit( *
this );
1309 if ( *p !=
'\"' && *p !=
'\'' ) {
1313 char endTag[2] = { *
p, 0 };
1477 int i = defaultValue;
1484 unsigned i = defaultValue;
1491 int64_t
i = defaultValue;
1498 bool b = defaultValue;
1505 double d = defaultValue;
1512 float f = defaultValue;
1664 int i = defaultValue;
1671 unsigned i = defaultValue;
1678 int64_t
i = defaultValue;
1685 bool b = defaultValue;
1692 double d = defaultValue;
1699 float f = defaultValue;
1711 last = attrib, attrib = attrib->
_next ) {
1720 last->
_next = attrib;
1779 if ( prevAttribute ) {
1780 prevAttribute->
_next = attrib;
1785 prevAttribute = attrib;
1788 else if ( *p ==
'>' ) {
1793 else if ( *p ==
'/' && *(p+1) ==
'>' ) {
1807 if ( attribute == 0 ) {
1812 pool->
Free( attribute );
1901 if ( !
node->Accept( visitor ) ) {
1916 "XML_WRONG_ATTRIBUTE_TYPE",
1917 "XML_ERROR_FILE_NOT_FOUND",
1918 "XML_ERROR_FILE_COULD_NOT_BE_OPENED",
1919 "XML_ERROR_FILE_READ_ERROR",
1920 "XML_ERROR_ELEMENT_MISMATCH",
1921 "XML_ERROR_PARSING_ELEMENT",
1922 "XML_ERROR_PARSING_ATTRIBUTE",
1923 "XML_ERROR_IDENTIFYING_TAG",
1924 "XML_ERROR_PARSING_TEXT",
1925 "XML_ERROR_PARSING_CDATA",
1926 "XML_ERROR_PARSING_COMMENT",
1927 "XML_ERROR_PARSING_DECLARATION",
1928 "XML_ERROR_PARSING_UNKNOWN",
1929 "XML_ERROR_EMPTY_DOCUMENT",
1930 "XML_ERROR_MISMATCHED_ELEMENT",
1931 "XML_ERROR_PARSING",
1932 "XML_CAN_NOT_CONVERT_TEXT",
1940 _processEntities( processEntities ),
1942 _whitespace( whitespace ),
1961 const bool hadError =
Error();
1991 ele->SetName( name );
2001 comment->SetValue( str );
2011 text->SetValue( str );
2021 dec->SetValue( str ? str :
"xml version=\"1.0\" encoding=\"UTF-8\"" );
2031 unk->SetValue( str );
2039 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
2041 errno_t
err = fopen_s( &fp, filepath, mode );
2046 FILE* fp = fopen( filepath, mode );
2089 <
bool = (
sizeof(
unsigned long) >=
sizeof(
size_t))>
2093 return value < (size_t)-1;
2099 static bool Fits(
unsigned long )
2109 fseek( fp, 0, SEEK_SET );
2110 if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) {
2115 fseek( fp, 0, SEEK_END );
2116 const long filelength = ftell( fp );
2117 fseek( fp, 0, SEEK_SET );
2118 if ( filelength == -1
L ) {
2130 if ( filelength == 0 ) {
2135 const size_t size = filelength;
2139 if ( read != size ) {
2179 if ( len == 0 || !p || !*p ) {
2183 if ( len == (
size_t)(-1) ) {
2213 Accept( &stdoutStreamer );
2243 static const int LEN = 20;
2244 char buf1[LEN] = { 0 };
2245 char buf2[LEN] = { 0 };
2257 printf(
"XMLDocument error id=%d '%s' str1=%s str2=%s\n",
2277 _elementJustOpened(
false ),
2278 _firstElement(
true ),
2282 _processEntities(
true ),
2283 _compactMode( compact )
2291 TIXMLASSERT( ((
unsigned char)entityValue) < ENTITY_RANGE );
2304 va_start( va, format );
2307 vfprintf(
_fp, format, va );
2314 va_start( va, format );
2345 if ( flag[(
unsigned char)(*q)] ) {
2347 const size_t delta = q -
p;
2349 const int toPrint = ( INT_MAX <
delta ) ? INT_MAX : (
int)
delta;
2350 Print(
"%.*s", toPrint, p );
2353 bool entityPatternPrinted =
false;
2357 entityPatternPrinted =
true;
2361 if ( !entityPatternPrinted ) {
2401 if ( !compactMode ) {
2405 Print(
"<%s", name );
2415 Print(
" %s=\"", name );
2474 Print(
"</%s>", name );
2480 if (
_depth == 0 && !compactMode) {
2503 Print(
"<![CDATA[%s]]>", text );
2565 Print(
"<!--%s-->", comment );
2577 Print(
"<?%s?>", value );
2589 Print(
"<!%s>", value );
2606 if ( element.
Parent() ) {
2611 while ( attribute ) {
2613 attribute = attribute->
Next();