diff --git a/kiwano/common/String.hpp b/kiwano/common/String.hpp index bb1d42ca..abde17f2 100644 --- a/kiwano/common/String.hpp +++ b/kiwano/common/String.hpp @@ -43,8 +43,11 @@ namespace kiwano namespace kiwano { // - // basic_string - // Lightweight std::wstring<>-like class + // basic_string<> + // Lightweight std::basic_string<>-like class + // When using basic_string<> with a c-style string (char* or wchar_t*), constructor and operator=() just hold + // a pointer to the character array but don't copy its content, considering performance issues. + // Use assign() and basic_string<>::cstr() to work fine with c-style strings. // template class basic_string @@ -174,7 +177,7 @@ namespace kiwano basic_string& assign(size_type count, const char_type ch); basic_string& assign(const char_type* cstr, size_type count); - inline basic_string& assign(const char_type* cstr, bool const_str = true) { basic_string(cstr, const_str).swap(*this); return *this; } + inline basic_string& assign(const char_type* cstr) { basic_string(cstr, false).swap(*this); return *this; } inline basic_string& assign(basic_string const& rhs) { basic_string{ rhs }.swap(*this); return *this; } inline basic_string& assign(std::basic_string const& rhs) { basic_string{ rhs }.swap(*this); return *this; } basic_string& assign(basic_string const& rhs, size_type pos, size_type count = npos); @@ -218,6 +221,8 @@ namespace kiwano template static basic_string format(const char_type* fmt, _Args&&... args); + static inline basic_string cstr(const char_type* cstr) { return basic_string(cstr, false); } + public: inline iterator begin() { check_operability(); return iterator(str_); } inline const_iterator begin() const { return const_iterator(const_str_); } @@ -237,7 +242,7 @@ namespace kiwano inline const_reference back() const { if (empty()) throw std::out_of_range("back() called on empty string"); return const_str_[size_ - 1]; } public: - inline char_type operator[](size_type off) const { if(off >= size_) throw std::out_of_range("string subscript out of range"); return const_str_[off]; } + inline char_type operator[](size_type off) const { if (off >= size_) throw std::out_of_range("string subscript out of range"); return const_str_[off]; } inline char_type& operator[](size_type off) { if (off >= size_) throw std::out_of_range("string subscript out of range"); check_operability(); return str_[off]; } public: diff --git a/kiwano/third-party/tinyxml2/tinyxml2.cpp b/kiwano/third-party/tinyxml2/tinyxml2.cpp index 55876c1b..812ee718 100644 --- a/kiwano/third-party/tinyxml2/tinyxml2.cpp +++ b/kiwano/third-party/tinyxml2/tinyxml2.cpp @@ -35,13 +35,24 @@ distribution. #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) // Microsoft Visual Studio, version 2005 and higher. Not WinCE. /*int _snprintf_s( - char *buffer, + wchar_t *buffer, size_t sizeOfBuffer, size_t count, - const char *format [, + const wchar_t *format [, argument] ... );*/ - static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) + + #define vsnprintf_s _vsnwprintf_s + #define _vsnprintf _vsnwprintf + #define strlen wcslen + #define strncmp wcsncmp + #define strchr wcschr + #define fopen_s _wfopen_s + #define vfprintf vfwprintf + #define TIXML_VSCPRINTF _vscwprintf + #define TIXML_SSCANF swscanf_s + + static inline int TIXML_SNPRINTF( wchar_t* buffer, size_t size, const wchar_t* format, ... ) { va_list va; va_start( va, format ); @@ -50,14 +61,12 @@ distribution. return result; } - static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va ) + static inline int TIXML_VSNPRINTF( wchar_t* buffer, size_t size, const wchar_t* format, va_list va ) { const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); return result; } - #define TIXML_VSCPRINTF _vscprintf - #define TIXML_SSCANF sscanf_s #elif defined _MSC_VER // Microsoft Visual Studio 2003 and earlier or WinCE #define TIXML_SNPRINTF _snprintf @@ -68,12 +77,12 @@ distribution. #define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have. #else // Microsoft Visual Studio 2003 and earlier or WinCE. - static inline int TIXML_VSCPRINTF( const char* format, va_list va ) + static inline int TIXML_VSCPRINTF( const wchar_t* format, va_list va ) { int len = 512; for (;;) { len = len*2; - char* str = new char[len](); + wchar_t* str = new wchar_t[len](); const int required = _vsnprintf(str, len, format, va); delete[] str; if ( required != -1 ) { @@ -88,10 +97,10 @@ distribution. #endif #else // GCC version 3 and higher - //#warning( "Using sn* functions." ) + //#warning( TINYXML2_STR("Using sn* functions.") ) #define TIXML_SNPRINTF snprintf #define TIXML_VSNPRINTF vsnprintf - static inline int TIXML_VSCPRINTF( const char* format, va_list va ) + static inline int TIXML_VSCPRINTF( const wchar_t* format, va_list va ) { int len = vsnprintf( 0, 0, format, va ); TIXMLASSERT( len >= 0 ); @@ -101,37 +110,37 @@ distribution. #endif -static const char LINE_FEED = (char)0x0a; // all line endings are normalized to LF -static const char LF = LINE_FEED; -static const char CARRIAGE_RETURN = (char)0x0d; // CR gets filtered out -static const char CR = CARRIAGE_RETURN; -static const char SINGLE_QUOTE = '\''; -static const char DOUBLE_QUOTE = '\"'; +static const wchar_t LINE_FEED = (wchar_t)0x0a; // all line endings are normalized to LF +static const wchar_t LF = LINE_FEED; +static const wchar_t CARRIAGE_RETURN = (wchar_t)0x0d; // CR gets filtered out +static const wchar_t CR = CARRIAGE_RETURN; +static const wchar_t SINGLE_QUOTE = TINYXML2_CHAR('\''); +static const wchar_t DOUBLE_QUOTE = TINYXML2_CHAR('\"'); // Bunch of unicode info at: // http://www.unicode.org/faq/utf_bom.html -// ef bb bf (Microsoft "lead bytes") - designates UTF-8 +// ef bb bf (Microsoft TINYXML2_STR("lead bytes")) - designates UTF-8 -static const unsigned char TIXML_UTF_LEAD_0 = 0xefU; -static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; -static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; +static const TINYXML2_UNSIGNED_CHAR TIXML_UTF_LEAD_0 = 0xefU; +static const TINYXML2_UNSIGNED_CHAR TIXML_UTF_LEAD_1 = 0xbbU; +static const TINYXML2_UNSIGNED_CHAR TIXML_UTF_LEAD_2 = 0xbfU; namespace tinyxml2 { struct Entity { - const char* pattern; + const wchar_t* pattern; int length; - char value; + wchar_t value; }; static const int NUM_ENTITIES = 5; static const Entity entities[NUM_ENTITIES] = { - { "quot", 4, DOUBLE_QUOTE }, - { "amp", 3, '&' }, - { "apos", 4, SINGLE_QUOTE }, - { "lt", 2, '<' }, - { "gt", 2, '>' } + { TINYXML2_STR("quot"), 4, DOUBLE_QUOTE }, + { TINYXML2_STR("amp"), 3, TINYXML2_CHAR('&') }, + { TINYXML2_STR("apos"), 4, SINGLE_QUOTE }, + { TINYXML2_STR("lt"), 2, TINYXML2_CHAR('<') }, + { TINYXML2_STR("gt"), 2, TINYXML2_CHAR('>') } }; @@ -146,7 +155,7 @@ void StrPair::TransferTo( StrPair* other ) if ( this == other ) { return; } - // This in effect implements the assignment operator by "moving" + // This in effect implements the assignment operator by TINYXML2_STR("moving") // ownership (as in auto_ptr). TIXMLASSERT( other != 0 ); @@ -177,27 +186,27 @@ void StrPair::Reset() } -void StrPair::SetStr( const char* str, int flags ) +void StrPair::SetStr( const wchar_t* str, int flags ) { TIXMLASSERT( str ); Reset(); size_t len = strlen( str ); TIXMLASSERT( _start == 0 ); - _start = new char[ len+1 ]; - memcpy( _start, str, len+1 ); + _start = new wchar_t[ len+1 ]; + memcpy( _start, str, (len+1) * sizeof(wchar_t)); _end = _start + len; _flags = flags | NEEDS_DELETE; } -char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLineNumPtr ) +wchar_t* StrPair::ParseText( wchar_t* p, const wchar_t* endTag, int strFlags, int* curLineNumPtr ) { TIXMLASSERT( p ); TIXMLASSERT( endTag && *endTag ); TIXMLASSERT(curLineNumPtr); - char* start = p; - const char endChar = *endTag; + wchar_t* start = p; + const wchar_t endChar = *endTag; size_t length = strlen( endTag ); // Inner loop of text parsing. @@ -205,7 +214,7 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLin if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) { Set( start, p, strFlags ); return p + length; - } else if (*p == '\n') { + } else if (*p == TINYXML2_CHAR('\n')) { ++(*curLineNumPtr); } ++p; @@ -215,7 +224,7 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLin } -char* StrPair::ParseName( char* p ) +wchar_t* StrPair::ParseName( wchar_t* p ) { if ( !p || !(*p) ) { return 0; @@ -224,7 +233,7 @@ char* StrPair::ParseName( char* p ) return 0; } - char* const start = p; + wchar_t* const start = p; ++p; while ( *p && XMLUtil::IsNameChar( *p ) ) { ++p; @@ -243,8 +252,8 @@ void StrPair::CollapseWhitespace() _start = XMLUtil::SkipWhiteSpace( _start, 0 ); if ( *_start ) { - const char* p = _start; // the read pointer - char* q = _start; // the write pointer + const wchar_t* p = _start; // the read pointer + wchar_t* q = _start; // the write pointer while( *p ) { if ( XMLUtil::IsWhiteSpace( *p )) { @@ -252,7 +261,7 @@ void StrPair::CollapseWhitespace() if ( *p == 0 ) { break; // don't write to q; this trims the trailing space. } - *q = ' '; + *q = TINYXML2_CHAR(' '); ++q; } *q = *p; @@ -264,7 +273,7 @@ void StrPair::CollapseWhitespace() } -const char* StrPair::GetStr() +const wchar_t* StrPair::GetStr() { TIXMLASSERT( _start ); TIXMLASSERT( _end ); @@ -273,8 +282,8 @@ const char* StrPair::GetStr() _flags ^= NEEDS_FLUSH; if ( _flags ) { - const char* p = _start; // the read pointer - char* q = _start; // the write pointer + const wchar_t* p = _start; // the read pointer + wchar_t* q = _start; // the write pointer while( p < _end ) { if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) { @@ -300,17 +309,17 @@ const char* StrPair::GetStr() *q = LF; ++q; } - else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) { + else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == TINYXML2_CHAR('&') ) { // Entities handled by tinyXML2: // - special entities in the entity table [in/out] - // - numeric character reference [in] + // - numeric wchar_tacter reference [in] // 中 or 中 - if ( *(p+1) == '#' ) { + if ( *(p+1) == TINYXML2_CHAR('#') ) { const int buflen = 10; - char buf[buflen] = { 0 }; + wchar_t buf[buflen] = { 0 }; int len = 0; - const char* adjusted = const_cast( XMLUtil::GetCharacterRef( p, buf, &len ) ); + const wchar_t* adjusted = const_cast( XMLUtil::GetCharacterRef( p, buf, &len ) ); if ( adjusted == 0 ) { *q = *p; ++p; @@ -320,7 +329,7 @@ const char* StrPair::GetStr() TIXMLASSERT( 0 <= len && len <= buflen ); TIXMLASSERT( q + len <= adjusted ); p = adjusted; - memcpy( q, buf, len ); + memcpy( q, buf, len * sizeof(wchar_t)); q += len; } } @@ -329,7 +338,7 @@ const char* StrPair::GetStr() for( int i = 0; i < NUM_ENTITIES; ++i ) { const Entity& entity = entities[i]; if ( strncmp( p + 1, entity.pattern, entity.length ) == 0 - && *( p + entity.length + 1 ) == ';' ) { + && *( p + entity.length + 1 ) == TINYXML2_CHAR(';') ) { // Found an entity - convert. *q = entity.value; ++q; @@ -369,25 +378,25 @@ const char* StrPair::GetStr() // --------- XMLUtil ----------- // -const char* XMLUtil::writeBoolTrue = "true"; -const char* XMLUtil::writeBoolFalse = "false"; +const wchar_t* XMLUtil::writeBoolTrue = TINYXML2_STR("true"); +const wchar_t* XMLUtil::writeBoolFalse = TINYXML2_STR("false"); -void XMLUtil::SetBoolSerialization(const char* writeTrue, const char* writeFalse) +void XMLUtil::SetBoolSerialization(const wchar_t* writeTrue, const wchar_t* writeFalse) { - static const char* defTrue = "true"; - static const char* defFalse = "false"; + static const wchar_t* defTrue = TINYXML2_STR("true"); + static const wchar_t* defFalse = TINYXML2_STR("false"); writeBoolTrue = (writeTrue) ? writeTrue : defTrue; writeBoolFalse = (writeFalse) ? writeFalse : defFalse; } -const char* XMLUtil::ReadBOM( const char* p, bool* bom ) +const wchar_t* XMLUtil::ReadBOM( const wchar_t* p, bool* bom ) { TIXMLASSERT( p ); TIXMLASSERT( bom ); *bom = false; - const unsigned char* pu = reinterpret_cast(p); + const TINYXML2_UNSIGNED_CHAR* pu = reinterpret_cast(p); // Check for BOM: if ( *(pu+0) == TIXML_UTF_LEAD_0 && *(pu+1) == TIXML_UTF_LEAD_1 @@ -400,7 +409,7 @@ const char* XMLUtil::ReadBOM( const char* p, bool* bom ) } -void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) +void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, wchar_t* output, int* length ) { const unsigned long BYTE_MASK = 0xBF; const unsigned long BYTE_MARK = 0x80; @@ -430,22 +439,22 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length switch (*length) { case 4: --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); + *output = (wchar_t)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; //fall through case 3: --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); + *output = (wchar_t)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; //fall through case 2: --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); + *output = (wchar_t)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; //fall through case 1: --output; - *output = (char)(input | FIRST_BYTE_MARK[*length]); + *output = (wchar_t)(input | FIRST_BYTE_MARK[*length]); break; default: TIXMLASSERT( false ); @@ -453,21 +462,21 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length } -const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) +const wchar_t* XMLUtil::GetCharacterRef( const wchar_t* p, wchar_t* value, int* length ) { // Presume an entity, and pull it out. *length = 0; - if ( *(p+1) == '#' && *(p+2) ) { + if ( *(p+1) == TINYXML2_CHAR('#') && *(p+2) ) { unsigned long ucs = 0; TIXMLASSERT( sizeof( ucs ) >= 4 ); ptrdiff_t delta = 0; unsigned mult = 1; - static const char SEMICOLON = ';'; + static const wchar_t SEMICOLON = TINYXML2_CHAR(';'); - if ( *(p+2) == 'x' ) { + if ( *(p+2) == TINYXML2_CHAR('x') ) { // Hexadecimal. - const char* q = p+3; + const wchar_t* q = p+3; if ( !(*q) ) { return 0; } @@ -482,17 +491,17 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) delta = q-p; --q; - while ( *q != 'x' ) { + while ( *q != TINYXML2_CHAR('x') ) { unsigned int digit = 0; - if ( *q >= '0' && *q <= '9' ) { - digit = *q - '0'; + if ( *q >= TINYXML2_CHAR('0') && *q <= TINYXML2_CHAR('9') ) { + digit = *q - TINYXML2_CHAR('0'); } - else if ( *q >= 'a' && *q <= 'f' ) { - digit = *q - 'a' + 10; + else if ( *q >= TINYXML2_CHAR('a') && *q <= TINYXML2_CHAR('f') ) { + digit = *q - TINYXML2_CHAR('a') + 10; } - else if ( *q >= 'A' && *q <= 'F' ) { - digit = *q - 'A' + 10; + else if ( *q >= TINYXML2_CHAR('A') && *q <= TINYXML2_CHAR('F') ) { + digit = *q - TINYXML2_CHAR('A') + 10; } else { return 0; @@ -509,7 +518,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) } else { // Decimal. - const char* q = p+2; + const wchar_t* q = p+2; if ( !(*q) ) { return 0; } @@ -524,9 +533,9 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) delta = q-p; --q; - while ( *q != '#' ) { - if ( *q >= '0' && *q <= '9' ) { - const unsigned int digit = *q - '0'; + while ( *q != TINYXML2_CHAR('#') ) { + if ( *q >= TINYXML2_CHAR('0') && *q <= TINYXML2_CHAR('9') ) { + const unsigned int digit = *q - TINYXML2_CHAR('0'); TIXMLASSERT( digit < 10 ); TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit ); const unsigned int digitScaled = mult * digit; @@ -549,74 +558,74 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) } -void XMLUtil::ToStr( int v, char* buffer, int bufferSize ) +void XMLUtil::ToStr( int v, wchar_t* buffer, int bufferSize ) { - TIXML_SNPRINTF( buffer, bufferSize, "%d", v ); + TIXML_SNPRINTF( buffer, bufferSize, TINYXML2_STR("%d"), v ); } -void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize ) +void XMLUtil::ToStr( unsigned v, wchar_t* buffer, int bufferSize ) { - TIXML_SNPRINTF( buffer, bufferSize, "%u", v ); + TIXML_SNPRINTF( buffer, bufferSize, TINYXML2_STR("%u"), v ); } -void XMLUtil::ToStr( bool v, char* buffer, int bufferSize ) +void XMLUtil::ToStr( bool v, wchar_t* buffer, int bufferSize ) { - TIXML_SNPRINTF( buffer, bufferSize, "%s", v ? writeBoolTrue : writeBoolFalse); + TIXML_SNPRINTF( buffer, bufferSize, TINYXML2_STR("%s"), v ? writeBoolTrue : writeBoolFalse); } /* ToStr() of a number is a very tricky topic. https://github.com/leethomason/tinyxml2/issues/106 */ -void XMLUtil::ToStr( float v, char* buffer, int bufferSize ) +void XMLUtil::ToStr( float v, wchar_t* buffer, int bufferSize ) { - TIXML_SNPRINTF( buffer, bufferSize, "%.8g", v ); + TIXML_SNPRINTF( buffer, bufferSize, TINYXML2_STR("%.8g"), v ); } -void XMLUtil::ToStr( double v, char* buffer, int bufferSize ) +void XMLUtil::ToStr( double v, wchar_t* buffer, int bufferSize ) { - TIXML_SNPRINTF( buffer, bufferSize, "%.17g", v ); + TIXML_SNPRINTF( buffer, bufferSize, TINYXML2_STR("%.17g"), v ); } -void XMLUtil::ToStr(int64_t v, char* buffer, int bufferSize) +void XMLUtil::ToStr(int64_t v, wchar_t* buffer, int bufferSize) { // horrible syntax trick to make the compiler happy about %lld - TIXML_SNPRINTF(buffer, bufferSize, "%lld", (long long)v); + TIXML_SNPRINTF(buffer, bufferSize, TINYXML2_STR("%lld"), (long long)v); } -bool XMLUtil::ToInt( const char* str, int* value ) +bool XMLUtil::ToInt( const wchar_t* str, int* value ) { - if ( TIXML_SSCANF( str, "%d", value ) == 1 ) { + if ( TIXML_SSCANF( str, TINYXML2_STR("%d"), value ) == 1 ) { return true; } return false; } -bool XMLUtil::ToUnsigned( const char* str, unsigned *value ) +bool XMLUtil::ToUnsigned( const wchar_t* str, unsigned *value ) { - if ( TIXML_SSCANF( str, "%u", value ) == 1 ) { + if ( TIXML_SSCANF( str, TINYXML2_STR("%u"), value ) == 1 ) { return true; } return false; } -bool XMLUtil::ToBool( const char* str, bool* value ) +bool XMLUtil::ToBool( const wchar_t* str, bool* value ) { int ival = 0; if ( ToInt( str, &ival )) { *value = (ival==0) ? false : true; return true; } - if ( StringEqual( str, "true" ) ) { + if ( StringEqual( str, TINYXML2_STR("true") ) ) { *value = true; return true; } - else if ( StringEqual( str, "false" ) ) { + else if ( StringEqual( str, TINYXML2_STR("false") ) ) { *value = false; return true; } @@ -624,28 +633,28 @@ bool XMLUtil::ToBool( const char* str, bool* value ) } -bool XMLUtil::ToFloat( const char* str, float* value ) +bool XMLUtil::ToFloat( const wchar_t* str, float* value ) { - if ( TIXML_SSCANF( str, "%f", value ) == 1 ) { + if ( TIXML_SSCANF( str, TINYXML2_STR("%f"), value ) == 1 ) { return true; } return false; } -bool XMLUtil::ToDouble( const char* str, double* value ) +bool XMLUtil::ToDouble( const wchar_t* str, double* value ) { - if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) { + if ( TIXML_SSCANF( str, TINYXML2_STR("%lf"), value ) == 1 ) { return true; } return false; } -bool XMLUtil::ToInt64(const char* str, int64_t* value) +bool XMLUtil::ToInt64(const wchar_t* str, int64_t* value) { long long v = 0; // horrible syntax trick to make the compiler happy about %lld - if (TIXML_SSCANF(str, "%lld", &v) == 1) { + if (TIXML_SSCANF(str, TINYXML2_STR("%lld"), &v) == 1) { *value = (int64_t)v; return true; } @@ -653,11 +662,11 @@ bool XMLUtil::ToInt64(const char* str, int64_t* value) } -char* XMLDocument::Identify( char* p, XMLNode** node ) +wchar_t* XMLDocument::Identify( wchar_t* p, XMLNode** node ) { TIXMLASSERT( node ); TIXMLASSERT( p ); - char* const start = p; + wchar_t* const start = p; int const startLine = _parseCurLineNum; p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); if( !*p ) { @@ -667,11 +676,11 @@ char* XMLDocument::Identify( char* p, XMLNode** node ) } // These strings define the matching patterns: - static const char* xmlHeader = { "( _textPool ); - returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character + returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace wchar_tacter p = start; // Back it up, all the text counts. _parseCurLineNum = startLine; } @@ -760,7 +769,7 @@ XMLNode::~XMLNode() } } -const char* XMLNode::Value() const +const wchar_t* XMLNode::Value() const { // Edge case: XMLDocuments don't have a Value. Return null. if ( this->ToDocument() ) @@ -768,7 +777,7 @@ const char* XMLNode::Value() const return _value.GetStr(); } -void XMLNode::SetValue( const char* str, bool staticMem ) +void XMLNode::SetValue( const wchar_t* str, bool staticMem ) { if ( staticMem ) { _value.SetInternedStr( str ); @@ -937,7 +946,7 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) -const XMLElement* XMLNode::FirstChildElement( const char* name ) const +const XMLElement* XMLNode::FirstChildElement( const wchar_t* name ) const { for( const XMLNode* node = _firstChild; node; node = node->_next ) { const XMLElement* element = node->ToElementWithName( name ); @@ -949,7 +958,7 @@ const XMLElement* XMLNode::FirstChildElement( const char* name ) const } -const XMLElement* XMLNode::LastChildElement( const char* name ) const +const XMLElement* XMLNode::LastChildElement( const wchar_t* name ) const { for( const XMLNode* node = _lastChild; node; node = node->_prev ) { const XMLElement* element = node->ToElementWithName( name ); @@ -961,7 +970,7 @@ const XMLElement* XMLNode::LastChildElement( const char* name ) const } -const XMLElement* XMLNode::NextSiblingElement( const char* name ) const +const XMLElement* XMLNode::NextSiblingElement( const wchar_t* name ) const { for( const XMLNode* node = _next; node; node = node->_next ) { const XMLElement* element = node->ToElementWithName( name ); @@ -973,7 +982,7 @@ const XMLElement* XMLNode::NextSiblingElement( const char* name ) const } -const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const +const XMLElement* XMLNode::PreviousSiblingElement( const wchar_t* name ) const { for( const XMLNode* node = _prev; node; node = node->_prev ) { const XMLElement* element = node->ToElementWithName( name ); @@ -985,9 +994,9 @@ const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const } -char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) +wchar_t* XMLNode::ParseDeep( wchar_t* p, StrPair* parentEndTag, int* curLineNumPtr ) { - // This is a recursive method, but thinking about it "at the current level" + // This is a recursive method, but thinking about it TINYXML2_STR("at the current level") // it is a pretty simple flat list: // // @@ -1054,7 +1063,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) } } if ( !wellLocated ) { - _document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value()); + _document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, TINYXML2_STR("XMLDeclaration value=%s"), decl->Value()); DeleteNode( node ); break; } @@ -1089,7 +1098,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) } } if ( mismatch ) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name()); + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, TINYXML2_STR("XMLElement name=%s"), ele->Name()); DeleteNode( node ); break; } @@ -1128,7 +1137,7 @@ void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const } } -const XMLElement* XMLNode::ToElementWithName( const char* name ) const +const XMLElement* XMLNode::ToElementWithName( const wchar_t* name ) const { const XMLElement* element = this->ToElement(); if ( element == 0 ) { @@ -1144,10 +1153,10 @@ const XMLElement* XMLNode::ToElementWithName( const char* name ) const } // --------- XMLText ---------- // -char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) +wchar_t* XMLText::ParseDeep( wchar_t* p, StrPair*, int* curLineNumPtr ) { if ( this->CData() ) { - p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); + p = _value.ParseText( p, TINYXML2_STR("]]>"), StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { _document->SetError( XML_ERROR_PARSING_CDATA, _parseLineNum, 0 ); } @@ -1159,7 +1168,7 @@ char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING; } - p = _value.ParseText( p, "<", flags, curLineNumPtr ); + p = _value.ParseText( p, TINYXML2_STR("<"), flags, curLineNumPtr ); if ( p && *p ) { return p-1; } @@ -1209,10 +1218,10 @@ XMLComment::~XMLComment() } -char* XMLComment::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) +wchar_t* XMLComment::ParseDeep( wchar_t* p, StrPair*, int* curLineNumPtr ) { // Comment parses as text. - p = _value.ParseText( p, "-->", StrPair::COMMENT, curLineNumPtr ); + p = _value.ParseText( p, TINYXML2_STR("-->"), StrPair::COMMENT, curLineNumPtr ); if ( p == 0 ) { _document->SetError( XML_ERROR_PARSING_COMMENT, _parseLineNum, 0 ); } @@ -1254,14 +1263,14 @@ XMLDeclaration::XMLDeclaration( XMLDocument* doc ) : XMLNode( doc ) XMLDeclaration::~XMLDeclaration() { - //printf( "~XMLDeclaration\n" ); + //printf( TINYXML2_STR("~XMLDeclaration\n") ); } -char* XMLDeclaration::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) +wchar_t* XMLDeclaration::ParseDeep( wchar_t* p, StrPair*, int* curLineNumPtr ) { // Declaration parses as text. - p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); + p = _value.ParseText( p, TINYXML2_STR("?>"), StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( p == 0 ) { _document->SetError( XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0 ); } @@ -1306,10 +1315,10 @@ XMLUnknown::~XMLUnknown() } -char* XMLUnknown::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) +wchar_t* XMLUnknown::ParseDeep( wchar_t* p, StrPair*, int* curLineNumPtr ) { // Unknown parses as text. - p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); + p = _value.ParseText( p, TINYXML2_STR(">"), StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { _document->SetError( XML_ERROR_PARSING_UNKNOWN, _parseLineNum, 0 ); } @@ -1343,17 +1352,17 @@ bool XMLUnknown::Accept( XMLVisitor* visitor ) const // --------- XMLAttribute ---------- // -const char* XMLAttribute::Name() const +const wchar_t* XMLAttribute::Name() const { return _name.GetStr(); } -const char* XMLAttribute::Value() const +const wchar_t* XMLAttribute::Value() const { return _value.GetStr(); } -char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr ) +wchar_t* XMLAttribute::ParseDeep( wchar_t* p, bool processEntities, int* curLineNumPtr ) { // Parse using the name rules: bug fix, was using ParseText before p = _name.ParseName( p ); @@ -1363,17 +1372,17 @@ char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr // Skip white space before = p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); - if ( *p != '=' ) { + if ( *p != TINYXML2_CHAR('=') ) { return 0; } ++p; // move up to opening quote p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); - if ( *p != '\"' && *p != '\'' ) { + if ( *p != TINYXML2_CHAR('\"') && *p != TINYXML2_CHAR('\'') ) { return 0; } - const char endTag[2] = { *p, 0 }; + const wchar_t endTag[2] = { *p, 0 }; ++p; // move past opening quote p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES, curLineNumPtr ); @@ -1381,7 +1390,7 @@ char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr } -void XMLAttribute::SetName( const char* n ) +void XMLAttribute::SetName( const wchar_t* n ) { _name.SetStr( n ); } @@ -1441,7 +1450,7 @@ XMLError XMLAttribute::QueryDoubleValue( double* value ) const } -void XMLAttribute::SetAttribute( const char* v ) +void XMLAttribute::SetAttribute( const wchar_t* v ) { _value.SetStr( v ); } @@ -1449,7 +1458,7 @@ void XMLAttribute::SetAttribute( const char* v ) void XMLAttribute::SetAttribute( int v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } @@ -1457,7 +1466,7 @@ void XMLAttribute::SetAttribute( int v ) void XMLAttribute::SetAttribute( unsigned v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } @@ -1465,7 +1474,7 @@ void XMLAttribute::SetAttribute( unsigned v ) void XMLAttribute::SetAttribute(int64_t v) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } @@ -1474,21 +1483,21 @@ void XMLAttribute::SetAttribute(int64_t v) void XMLAttribute::SetAttribute( bool v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } void XMLAttribute::SetAttribute( double v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } void XMLAttribute::SetAttribute( float v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } @@ -1512,7 +1521,7 @@ XMLElement::~XMLElement() } -const XMLAttribute* XMLElement::FindAttribute( const char* name ) const +const XMLAttribute* XMLElement::FindAttribute( const wchar_t* name ) const { for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) { if ( XMLUtil::StringEqual( a->Name(), name ) ) { @@ -1523,7 +1532,7 @@ const XMLAttribute* XMLElement::FindAttribute( const char* name ) const } -const char* XMLElement::Attribute( const char* name, const char* value ) const +const wchar_t* XMLElement::Attribute( const wchar_t* name, const wchar_t* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { @@ -1535,49 +1544,49 @@ const char* XMLElement::Attribute( const char* name, const char* value ) const return 0; } -int XMLElement::IntAttribute(const char* name, int defaultValue) const +int XMLElement::IntAttribute(const wchar_t* name, int defaultValue) const { int i = defaultValue; QueryIntAttribute(name, &i); return i; } -unsigned XMLElement::UnsignedAttribute(const char* name, unsigned defaultValue) const +unsigned XMLElement::UnsignedAttribute(const wchar_t* name, unsigned defaultValue) const { unsigned i = defaultValue; QueryUnsignedAttribute(name, &i); return i; } -int64_t XMLElement::Int64Attribute(const char* name, int64_t defaultValue) const +int64_t XMLElement::Int64Attribute(const wchar_t* name, int64_t defaultValue) const { int64_t i = defaultValue; QueryInt64Attribute(name, &i); return i; } -bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const +bool XMLElement::BoolAttribute(const wchar_t* name, bool defaultValue) const { bool b = defaultValue; QueryBoolAttribute(name, &b); return b; } -double XMLElement::DoubleAttribute(const char* name, double defaultValue) const +double XMLElement::DoubleAttribute(const wchar_t* name, double defaultValue) const { double d = defaultValue; QueryDoubleAttribute(name, &d); return d; } -float XMLElement::FloatAttribute(const char* name, float defaultValue) const +float XMLElement::FloatAttribute(const wchar_t* name, float defaultValue) const { float f = defaultValue; QueryFloatAttribute(name, &f); return f; } -const char* XMLElement::GetText() const +const wchar_t* XMLElement::GetText() const { if ( FirstChild() && FirstChild()->ToText() ) { return FirstChild()->Value(); @@ -1586,7 +1595,7 @@ const char* XMLElement::GetText() const } -void XMLElement::SetText( const char* inText ) +void XMLElement::SetText( const wchar_t* inText ) { if ( FirstChild() && FirstChild()->ToText() ) FirstChild()->SetValue( inText ); @@ -1599,7 +1608,7 @@ void XMLElement::SetText( const char* inText ) void XMLElement::SetText( int v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } @@ -1607,7 +1616,7 @@ void XMLElement::SetText( int v ) void XMLElement::SetText( unsigned v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } @@ -1615,7 +1624,7 @@ void XMLElement::SetText( unsigned v ) void XMLElement::SetText(int64_t v) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } @@ -1623,7 +1632,7 @@ void XMLElement::SetText(int64_t v) void XMLElement::SetText( bool v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } @@ -1631,7 +1640,7 @@ void XMLElement::SetText( bool v ) void XMLElement::SetText( float v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } @@ -1639,7 +1648,7 @@ void XMLElement::SetText( float v ) void XMLElement::SetText( double v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } @@ -1648,7 +1657,7 @@ void XMLElement::SetText( double v ) XMLError XMLElement::QueryIntText( int* ival ) const { if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->Value(); + const wchar_t* t = FirstChild()->Value(); if ( XMLUtil::ToInt( t, ival ) ) { return XML_SUCCESS; } @@ -1661,7 +1670,7 @@ XMLError XMLElement::QueryIntText( int* ival ) const XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const { if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->Value(); + const wchar_t* t = FirstChild()->Value(); if ( XMLUtil::ToUnsigned( t, uval ) ) { return XML_SUCCESS; } @@ -1674,7 +1683,7 @@ XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const XMLError XMLElement::QueryInt64Text(int64_t* ival) const { if (FirstChild() && FirstChild()->ToText()) { - const char* t = FirstChild()->Value(); + const wchar_t* t = FirstChild()->Value(); if (XMLUtil::ToInt64(t, ival)) { return XML_SUCCESS; } @@ -1687,7 +1696,7 @@ XMLError XMLElement::QueryInt64Text(int64_t* ival) const XMLError XMLElement::QueryBoolText( bool* bval ) const { if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->Value(); + const wchar_t* t = FirstChild()->Value(); if ( XMLUtil::ToBool( t, bval ) ) { return XML_SUCCESS; } @@ -1700,7 +1709,7 @@ XMLError XMLElement::QueryBoolText( bool* bval ) const XMLError XMLElement::QueryDoubleText( double* dval ) const { if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->Value(); + const wchar_t* t = FirstChild()->Value(); if ( XMLUtil::ToDouble( t, dval ) ) { return XML_SUCCESS; } @@ -1713,7 +1722,7 @@ XMLError XMLElement::QueryDoubleText( double* dval ) const XMLError XMLElement::QueryFloatText( float* fval ) const { if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->Value(); + const wchar_t* t = FirstChild()->Value(); if ( XMLUtil::ToFloat( t, fval ) ) { return XML_SUCCESS; } @@ -1765,7 +1774,7 @@ float XMLElement::FloatText(float defaultValue) const } -XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) +XMLAttribute* XMLElement::FindOrCreateAttribute( const wchar_t* name ) { XMLAttribute* last = 0; XMLAttribute* attrib = 0; @@ -1793,7 +1802,7 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) } -void XMLElement::DeleteAttribute( const char* name ) +void XMLElement::DeleteAttribute( const wchar_t* name ) { XMLAttribute* prev = 0; for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) { @@ -1812,7 +1821,7 @@ void XMLElement::DeleteAttribute( const char* name ) } -char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) +wchar_t* XMLElement::ParseAttributes( wchar_t* p, int* curLineNumPtr ) { XMLAttribute* prevAttribute = 0; @@ -1820,7 +1829,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) while( p ) { p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( !(*p) ) { - _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "XMLElement name=%s", Name() ); + _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, TINYXML2_STR("XMLElement name=%s"), Name() ); return 0; } @@ -1835,7 +1844,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr ); if ( !p || Attribute( attrib->Name() ) ) { DeleteAttribute( attrib ); - _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name() ); + _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, TINYXML2_STR("XMLElement name=%s"), Name() ); return 0; } // There is a minor bug here: if the attribute in the source xml @@ -1854,12 +1863,12 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) prevAttribute = attrib; } // end of the tag - else if ( *p == '>' ) { + else if ( *p == TINYXML2_CHAR('>') ) { ++p; break; } // end of the tag - else if ( *p == '/' && *(p+1) == '>' ) { + else if ( *p == TINYXML2_CHAR('/') && *(p+1) == TINYXML2_CHAR('>') ) { _closingType = CLOSED; return p+2; // done; sealed element. } @@ -1895,7 +1904,7 @@ XMLAttribute* XMLElement::CreateAttribute() // // foobar // -char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) +wchar_t* XMLElement::ParseDeep( wchar_t* p, StrPair* parentEndTag, int* curLineNumPtr ) { // Read the element name. p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); @@ -1903,7 +1912,7 @@ char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr // The closing element is the form. It is // parsed just like a regular element then deleted from // the DOM. - if ( *p == '/' ) { + if ( *p == TINYXML2_CHAR('/') ) { _closingType = CLOSING; ++p; } @@ -1980,26 +1989,26 @@ bool XMLElement::Accept( XMLVisitor* visitor ) const // --------- XMLDocument ----------- // // Warning: List must match 'enum XMLError' -const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = { - "XML_SUCCESS", - "XML_NO_ATTRIBUTE", - "XML_WRONG_ATTRIBUTE_TYPE", - "XML_ERROR_FILE_NOT_FOUND", - "XML_ERROR_FILE_COULD_NOT_BE_OPENED", - "XML_ERROR_FILE_READ_ERROR", - "XML_ERROR_PARSING_ELEMENT", - "XML_ERROR_PARSING_ATTRIBUTE", - "XML_ERROR_PARSING_TEXT", - "XML_ERROR_PARSING_CDATA", - "XML_ERROR_PARSING_COMMENT", - "XML_ERROR_PARSING_DECLARATION", - "XML_ERROR_PARSING_UNKNOWN", - "XML_ERROR_EMPTY_DOCUMENT", - "XML_ERROR_MISMATCHED_ELEMENT", - "XML_ERROR_PARSING", - "XML_CAN_NOT_CONVERT_TEXT", - "XML_NO_TEXT_NODE", - "XML_ELEMENT_DEPTH_EXCEEDED" +const wchar_t* XMLDocument::_errorNames[XML_ERROR_COUNT] = { + TINYXML2_STR("XML_SUCCESS"), + TINYXML2_STR("XML_NO_ATTRIBUTE"), + TINYXML2_STR("XML_WRONG_ATTRIBUTE_TYPE"), + TINYXML2_STR("XML_ERROR_FILE_NOT_FOUND"), + TINYXML2_STR("XML_ERROR_FILE_COULD_NOT_BE_OPENED"), + TINYXML2_STR("XML_ERROR_FILE_READ_ERROR"), + TINYXML2_STR("XML_ERROR_PARSING_ELEMENT"), + TINYXML2_STR("XML_ERROR_PARSING_ATTRIBUTE"), + TINYXML2_STR("XML_ERROR_PARSING_TEXT"), + TINYXML2_STR("XML_ERROR_PARSING_CDATA"), + TINYXML2_STR("XML_ERROR_PARSING_COMMENT"), + TINYXML2_STR("XML_ERROR_PARSING_DECLARATION"), + TINYXML2_STR("XML_ERROR_PARSING_UNKNOWN"), + TINYXML2_STR("XML_ERROR_EMPTY_DOCUMENT"), + TINYXML2_STR("XML_ERROR_MISMATCHED_ELEMENT"), + TINYXML2_STR("XML_ERROR_PARSING"), + TINYXML2_STR("XML_CAN_NOT_CONVERT_TEXT"), + TINYXML2_STR("XML_NO_TEXT_NODE"), + TINYXML2_STR("XML_ELEMENT_DEPTH_EXCEEDED") }; @@ -2011,7 +2020,7 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) : _whitespaceMode( whitespaceMode ), _errorStr(), _errorLineNum( 0 ), - _charBuffer( 0 ), + _wcharBuffer( 0 ), _parseCurLineNum( 0 ), _parsingDepth(0), _unlinked(), @@ -2056,15 +2065,15 @@ void XMLDocument::Clear() #endif ClearError(); - delete [] _charBuffer; - _charBuffer = 0; + delete [] _wcharBuffer; + _wcharBuffer = 0; _parsingDepth = 0; #if 0 - _textPool.Trace( "text" ); - _elementPool.Trace( "element" ); - _commentPool.Trace( "comment" ); - _attributePool.Trace( "attribute" ); + _textPool.Trace( TINYXML2_STR("text") ); + _elementPool.Trace( TINYXML2_STR("element") ); + _commentPool.Trace( TINYXML2_STR("comment") ); + _attributePool.Trace( TINYXML2_STR("attribute") ); #endif #ifdef TINYXML2_DEBUG @@ -2091,7 +2100,7 @@ void XMLDocument::DeepCopy(XMLDocument* target) const } } -XMLElement* XMLDocument::NewElement( const char* name ) +XMLElement* XMLDocument::NewElement( const wchar_t* name ) { XMLElement* ele = CreateUnlinkedNode( _elementPool ); ele->SetName( name ); @@ -2099,7 +2108,7 @@ XMLElement* XMLDocument::NewElement( const char* name ) } -XMLComment* XMLDocument::NewComment( const char* str ) +XMLComment* XMLDocument::NewComment( const wchar_t* str ) { XMLComment* comment = CreateUnlinkedNode( _commentPool ); comment->SetValue( str ); @@ -2107,7 +2116,7 @@ XMLComment* XMLDocument::NewComment( const char* str ) } -XMLText* XMLDocument::NewText( const char* str ) +XMLText* XMLDocument::NewText( const wchar_t* str ) { XMLText* text = CreateUnlinkedNode( _textPool ); text->SetValue( str ); @@ -2115,22 +2124,22 @@ XMLText* XMLDocument::NewText( const char* str ) } -XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) +XMLDeclaration* XMLDocument::NewDeclaration( const wchar_t* str ) { XMLDeclaration* dec = CreateUnlinkedNode( _commentPool ); - dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" ); + dec->SetValue( str ? str : TINYXML2_STR("xml version=\"1.0\" encoding=\"UTF-8\"") ); return dec; } -XMLUnknown* XMLDocument::NewUnknown( const char* str ) +XMLUnknown* XMLDocument::NewUnknown( const wchar_t* str ) { XMLUnknown* unk = CreateUnlinkedNode( _commentPool ); unk->SetValue( str ); return unk; } -static FILE* callfopen( const char* filepath, const char* mode ) +static FILE* callfopen( const wchar_t* filepath, const wchar_t* mode ) { TIXMLASSERT( filepath ); TIXMLASSERT( mode ); @@ -2164,18 +2173,18 @@ void XMLDocument::DeleteNode( XMLNode* node ) { } -XMLError XMLDocument::LoadFile( const char* filename ) +XMLError XMLDocument::LoadFile( const wchar_t* filename ) { if ( !filename ) { TIXMLASSERT( false ); - SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=" ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, TINYXML2_STR("filename=") ); return _errorID; } Clear(); - FILE* fp = callfopen( filename, "rb" ); + FILE* fp = callfopen( filename, TINYXML2_STR("rb") ); if ( !fp ) { - SetError( XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename ); + SetError( XML_ERROR_FILE_NOT_FOUND, 0, TINYXML2_STR("filename=%s"), filename ); return _errorID; } LoadFile( fp ); @@ -2211,7 +2220,7 @@ XMLError XMLDocument::LoadFile( FILE* fp ) Clear(); fseek( fp, 0, SEEK_SET ); - if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) { + if (fgetc( fp ) == EOF && ferror( fp ) != 0 ) { SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } @@ -2237,32 +2246,32 @@ XMLError XMLDocument::LoadFile( FILE* fp ) } const size_t size = filelength; - TIXMLASSERT( _charBuffer == 0 ); - _charBuffer = new char[size+1]; - const size_t read = fread( _charBuffer, 1, size, fp ); + TIXMLASSERT( _wcharBuffer == 0 ); + _wcharBuffer = new wchar_t[size + 1]; + const size_t read = fread( _wcharBuffer, 1, size*sizeof(wchar_t), fp ); if ( read != size ) { SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } - _charBuffer[size] = 0; + _wcharBuffer[size] = 0; Parse(); return _errorID; } -XMLError XMLDocument::SaveFile( const char* filename, bool compact ) +XMLError XMLDocument::SaveFile( const wchar_t* filename, bool compact ) { if ( !filename ) { TIXMLASSERT( false ); - SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=" ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, TINYXML2_STR("filename=") ); return _errorID; } - FILE* fp = callfopen( filename, "w" ); + FILE* fp = callfopen( filename, TINYXML2_STR("w") ); if ( !fp ) { - SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, TINYXML2_STR("filename=%s"), filename ); return _errorID; } SaveFile(fp, compact); @@ -2282,7 +2291,7 @@ XMLError XMLDocument::SaveFile( FILE* fp, bool compact ) } -XMLError XMLDocument::Parse( const char* p, size_t len ) +XMLError XMLDocument::Parse( const wchar_t* p, size_t len ) { Clear(); @@ -2293,10 +2302,10 @@ XMLError XMLDocument::Parse( const char* p, size_t len ) if ( len == (size_t)(-1) ) { len = strlen( p ); } - TIXMLASSERT( _charBuffer == 0 ); - _charBuffer = new char[ len+1 ]; - memcpy( _charBuffer, p, len ); - _charBuffer[len] = 0; + TIXMLASSERT( _wcharBuffer == 0 ); + _wcharBuffer = new wchar_t[ len+1 ]; + memcpy( _wcharBuffer, p, len * sizeof(wchar_t)); + _wcharBuffer[len] = 0; Parse(); if ( Error() ) { @@ -2325,7 +2334,7 @@ void XMLDocument::Print( XMLPrinter* streamer ) const } -void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... ) +void XMLDocument::SetError( XMLError error, int lineNum, const wchar_t* format, ... ) { TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT ); _errorID = error; @@ -2333,14 +2342,14 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... _errorStr.Reset(); const size_t BUFFER_SIZE = 1000; - char* buffer = new char[BUFFER_SIZE]; + wchar_t* buffer = new wchar_t[BUFFER_SIZE]; TIXMLASSERT(sizeof(error) <= sizeof(int)); - TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", ErrorIDToName(error), int(error), int(error), lineNum); + TIXML_SNPRINTF(buffer, BUFFER_SIZE, TINYXML2_STR("Error=%s ErrorID=%d (0x%x) Line number=%d"), ErrorIDToName(error), int(error), int(error), lineNum); if (format) { size_t len = strlen(buffer); - TIXML_SNPRINTF(buffer + len, BUFFER_SIZE - len, ": "); + TIXML_SNPRINTF(buffer + len, BUFFER_SIZE - len, TINYXML2_STR(": ")); len = strlen(buffer); va_list va; @@ -2353,26 +2362,20 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... } -/*static*/ const char* XMLDocument::ErrorIDToName(XMLError errorID) +/*static*/ const wchar_t* XMLDocument::ErrorIDToName(XMLError errorID) { TIXMLASSERT( errorID >= 0 && errorID < XML_ERROR_COUNT ); - const char* errorName = _errorNames[errorID]; + const wchar_t* errorName = _errorNames[errorID]; TIXMLASSERT( errorName && errorName[0] ); return errorName; } -const char* XMLDocument::ErrorStr() const +const wchar_t* XMLDocument::ErrorStr() const { - return _errorStr.Empty() ? "" : _errorStr.GetStr(); + return _errorStr.Empty() ? TINYXML2_STR("") : _errorStr.GetStr(); } - -void XMLDocument::PrintError() const -{ - printf("%s\n", ErrorStr()); -} - -const char* XMLDocument::ErrorName() const +const wchar_t* XMLDocument::ErrorName() const { return ErrorIDToName(_errorID); } @@ -2380,12 +2383,12 @@ const char* XMLDocument::ErrorName() const void XMLDocument::Parse() { TIXMLASSERT( NoChildren() ); // Clear() must have been called previously - TIXMLASSERT( _charBuffer ); + TIXMLASSERT( _wcharBuffer ); _parseCurLineNum = 1; _parseLineNum = 1; - char* p = _charBuffer; + wchar_t* p = _wcharBuffer; p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); - p = const_cast( XMLUtil::ReadBOM( p, &_writeBOM ) ); + p = const_cast( XMLUtil::ReadBOM( p, &_writeBOM ) ); if ( !*p ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return; @@ -2397,7 +2400,7 @@ void XMLDocument::PushDepth() { _parsingDepth++; if (_parsingDepth == TINYXML2_MAX_ELEMENT_DEPTH) { - SetError(XML_ELEMENT_DEPTH_EXCEEDED, _parseCurLineNum, "Element nesting is too deep." ); + SetError(XML_ELEMENT_DEPTH_EXCEEDED, _parseCurLineNum, TINYXML2_STR("Element nesting is too deep.") ); } } @@ -2423,19 +2426,19 @@ XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : _restrictedEntityFlag[i] = false; } for( int i=0; i'] = true; // not required, but consistency is nice + _restrictedEntityFlag[(TINYXML2_UNSIGNED_CHAR)TINYXML2_CHAR('&')] = true; + _restrictedEntityFlag[(TINYXML2_UNSIGNED_CHAR)TINYXML2_CHAR('<')] = true; + _restrictedEntityFlag[(TINYXML2_UNSIGNED_CHAR)TINYXML2_CHAR('>')] = true; // not required, but consistency is nice _buffer.Push( 0 ); } -void XMLPrinter::Print( const char* format, ... ) +void XMLPrinter::Print( const wchar_t* format, ... ) { va_list va; va_start( va, format ); @@ -2450,33 +2453,33 @@ void XMLPrinter::Print( const char* format, ... ) TIXMLASSERT( len >= 0 ); va_start( va, format ); TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 ); - char* p = _buffer.PushArr( len ) - 1; // back up over the null terminator. + wchar_t* p = _buffer.PushArr( len ) - 1; // back up over the null terminator. TIXML_VSNPRINTF( p, len+1, format, va ); } va_end( va ); } -void XMLPrinter::Write( const char* data, size_t size ) +void XMLPrinter::Write( const wchar_t* data, size_t size ) { if ( _fp ) { - fwrite ( data , sizeof(char), size, _fp); + fwrite ( data , sizeof(wchar_t), size, _fp); } else { - char* p = _buffer.PushArr( static_cast(size) ) - 1; // back up over the null terminator. - memcpy( p, data, size ); + wchar_t* p = _buffer.PushArr( static_cast(size) ) - 1; // back up over the null terminator. + memcpy( p, data, size * sizeof(wchar_t)); p[size] = 0; } } -void XMLPrinter::Putc( char ch ) +void XMLPrinter::Putc( wchar_t ch ) { if ( _fp ) { fputc ( ch, _fp); } else { - char* p = _buffer.PushArr( sizeof(char) ) - 1; // back up over the null terminator. + wchar_t* p = _buffer.PushArr( sizeof(wchar_t) ) - 1; // back up over the null terminator. p[0] = ch; p[1] = 0; } @@ -2486,26 +2489,26 @@ void XMLPrinter::Putc( char ch ) void XMLPrinter::PrintSpace( int depth ) { for( int i=0; i 0 && *q < ENTITY_RANGE ) { // Check for entities. If one is found, flush // the stream up until the entity, write the // entity, and keep looking. - if ( flag[(unsigned char)(*q)] ) { + if ( flag[(TINYXML2_UNSIGNED_CHAR)(*q)] ) { while ( p < q ) { const size_t delta = q - p; const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta; @@ -2515,9 +2518,9 @@ void XMLPrinter::PrintString( const char* p, bool restricted ) bool entityPatternPrinted = false; for( int i=0; i( bom ) ); + static const TINYXML2_UNSIGNED_CHAR bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 }; + Write( reinterpret_cast< const wchar_t* >( bom ) ); } if ( writeDec ) { - PushDeclaration( "xml version=\"1.0\"" ); + PushDeclaration( TINYXML2_STR("xml version=\"1.0\"") ); } } -void XMLPrinter::OpenElement( const char* name, bool compactMode ) +void XMLPrinter::OpenElement( const wchar_t* name, bool compactMode ) { SealElementIfJustOpened(); _stack.Push( name ); if ( _textDepth < 0 && !_firstElement && !compactMode ) { - Putc( '\n' ); + Putc( TINYXML2_CHAR('\n') ); } if ( !compactMode ) { PrintSpace( _depth ); } - Write ( "<" ); + Write ( TINYXML2_STR("<") ); Write ( name ); _elementJustOpened = true; @@ -2579,52 +2582,52 @@ void XMLPrinter::OpenElement( const char* name, bool compactMode ) } -void XMLPrinter::PushAttribute( const char* name, const char* value ) +void XMLPrinter::PushAttribute( const wchar_t* name, const wchar_t* value ) { TIXMLASSERT( _elementJustOpened ); - Putc ( ' ' ); + Putc ( TINYXML2_CHAR(' ') ); Write( name ); - Write( "=\"" ); + Write( TINYXML2_STR("=\"") ); PrintString( value, false ); - Putc ( '\"' ); + Putc ( TINYXML2_CHAR('\"') ); } -void XMLPrinter::PushAttribute( const char* name, int v ) +void XMLPrinter::PushAttribute( const wchar_t* name, int v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); PushAttribute( name, buf ); } -void XMLPrinter::PushAttribute( const char* name, unsigned v ) +void XMLPrinter::PushAttribute( const wchar_t* name, unsigned v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); PushAttribute( name, buf ); } -void XMLPrinter::PushAttribute(const char* name, int64_t v) +void XMLPrinter::PushAttribute(const wchar_t* name, int64_t v) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); PushAttribute(name, buf); } -void XMLPrinter::PushAttribute( const char* name, bool v ) +void XMLPrinter::PushAttribute( const wchar_t* name, bool v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); PushAttribute( name, buf ); } -void XMLPrinter::PushAttribute( const char* name, double v ) +void XMLPrinter::PushAttribute( const wchar_t* name, double v ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); PushAttribute( name, buf ); } @@ -2633,26 +2636,26 @@ void XMLPrinter::PushAttribute( const char* name, double v ) void XMLPrinter::CloseElement( bool compactMode ) { --_depth; - const char* name = _stack.Pop(); + const wchar_t* name = _stack.Pop(); if ( _elementJustOpened ) { - Write( "/>" ); + Write( TINYXML2_STR("/>") ); } else { if ( _textDepth < 0 && !compactMode) { - Putc( '\n' ); + Putc( TINYXML2_CHAR('\n') ); PrintSpace( _depth ); } - Write ( "" ); + Write ( TINYXML2_STR(">") ); } if ( _textDepth == _depth ) { _textDepth = -1; } if ( _depth == 0 && !compactMode) { - Putc( '\n' ); + Putc( TINYXML2_CHAR('\n') ); } _elementJustOpened = false; } @@ -2664,19 +2667,19 @@ void XMLPrinter::SealElementIfJustOpened() return; } _elementJustOpened = false; - Putc( '>' ); + Putc( TINYXML2_CHAR('>') ); } -void XMLPrinter::PushText( const char* text, bool cdata ) +void XMLPrinter::PushText( const wchar_t* text, bool cdata ) { _textDepth = _depth-1; SealElementIfJustOpened(); if ( cdata ) { - Write( "" ); + Write( TINYXML2_STR("]]>") ); } else { PrintString( text, true ); @@ -2685,14 +2688,14 @@ void XMLPrinter::PushText( const char* text, bool cdata ) void XMLPrinter::PushText( int64_t value ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } void XMLPrinter::PushText( int value ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } @@ -2700,7 +2703,7 @@ void XMLPrinter::PushText( int value ) void XMLPrinter::PushText( unsigned value ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } @@ -2708,7 +2711,7 @@ void XMLPrinter::PushText( unsigned value ) void XMLPrinter::PushText( bool value ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } @@ -2716,7 +2719,7 @@ void XMLPrinter::PushText( bool value ) void XMLPrinter::PushText( float value ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } @@ -2724,54 +2727,54 @@ void XMLPrinter::PushText( float value ) void XMLPrinter::PushText( double value ) { - char buf[BUF_SIZE]; + wchar_t buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } -void XMLPrinter::PushComment( const char* comment ) +void XMLPrinter::PushComment( const wchar_t* comment ) { SealElementIfJustOpened(); if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Putc( '\n' ); + Putc( TINYXML2_CHAR('\n') ); PrintSpace( _depth ); } _firstElement = false; - Write( "" ); + Write( TINYXML2_STR("-->") ); } -void XMLPrinter::PushDeclaration( const char* value ) +void XMLPrinter::PushDeclaration( const wchar_t* value ) { SealElementIfJustOpened(); if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Putc( '\n' ); + Putc( TINYXML2_CHAR('\n') ); PrintSpace( _depth ); } _firstElement = false; - Write( "" ); + Write( TINYXML2_STR("?>") ); } -void XMLPrinter::PushUnknown( const char* value ) +void XMLPrinter::PushUnknown( const wchar_t* value ) { SealElementIfJustOpened(); if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Putc( '\n' ); + Putc( TINYXML2_CHAR('\n') ); PrintSpace( _depth ); } _firstElement = false; - Write( "' ); + Putc( TINYXML2_CHAR('>') ); } diff --git a/kiwano/third-party/tinyxml2/tinyxml2.h b/kiwano/third-party/tinyxml2/tinyxml2.h index 4715ae99..d9431ab3 100644 --- a/kiwano/third-party/tinyxml2/tinyxml2.h +++ b/kiwano/third-party/tinyxml2/tinyxml2.h @@ -73,7 +73,7 @@ distribution. # define TINYXML2_LIB # endif #elif __GNUC__ >= 4 -# define TINYXML2_LIB __attribute__((visibility("default"))) +# define TINYXML2_LIB __attribute__((visibility(TINYXML2_STR("default")))) #else # define TINYXML2_LIB #endif @@ -85,7 +85,7 @@ distribution. # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); } # elif defined (ANDROID_NDK) # include -# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } +# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( TINYXML2_STR("assert", "grinliz", "ASSERT in TINYXML2_CHAR('%s') at %d."), __FILE__, __LINE__ ); } # else # include # define TIXMLASSERT assert @@ -106,6 +106,12 @@ static const int TIXML2_PATCH_VERSION = 1; #define TINYXML2_MINOR_VERSION 0 #define TINYXML2_PATCH_VERSION 1 +#define TINYXML2_UNSIGNED_CHAR wchar_t +#define TINYXML2_STR(STR) (L##STR) +#define TINYXML2_CHAR(CH) (L##CH) + +#include "../../common/String.hpp" + // A fixed element depth limit is problematic. There needs to be a // limit to avoid a stack overflow. However, that limit varies per // system, and the capacity of the stack. On the other hand, it's a trivial @@ -128,7 +134,7 @@ class XMLPrinter; A class that wraps strings. Normally stores the start and end pointers into the XML file itself, and will apply normalization and entity translation if actually read. Can also store (and memory - manage) a traditional char[] + manage) a traditional wchar_t[] Isn't clear why TINYXML2_LIB is needed; but seems to fix #719 */ @@ -151,7 +157,7 @@ public: StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {} ~StrPair(); - void Set( char* start, char* end, int flags ) { + void Set( wchar_t* start, wchar_t* end, int flags ) { TIXMLASSERT( start ); TIXMLASSERT( end ); Reset(); @@ -160,21 +166,21 @@ public: _flags = flags | NEEDS_FLUSH; } - const char* GetStr(); + const wchar_t* GetStr(); bool Empty() const { return _start == _end; } - void SetInternedStr( const char* str ) { + void SetInternedStr( const wchar_t* str ) { Reset(); - _start = const_cast(str); + _start = const_cast(str); } - void SetStr( const char* str, int flags=0 ); + void SetStr( const wchar_t* str, int flags=0 ); - char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr ); - char* ParseName( char* in ); + wchar_t* ParseText( wchar_t* in, const wchar_t* endTag, int strFlags, int* curLineNumPtr ); + wchar_t* ParseName( wchar_t* in ); void TransferTo( StrPair* other ); void Reset(); @@ -187,9 +193,9 @@ private: NEEDS_DELETE = 0x200 }; - int _flags; - char* _start; - char* _end; + int _flags; + wchar_t* _start; + wchar_t* _end; StrPair( const StrPair& other ); // not supported void operator=( const StrPair& other ); // not supported, use TransferTo() @@ -409,8 +415,8 @@ public: item->next = _root; _root = item; } - void Trace( const char* name ) { - printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n", + void Trace( const wchar_t* name ) { + printf( TINYXML2_STR("Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n"), name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs, ITEM_SIZE, _nAllocs, _blockPtrs.Size() ); } @@ -442,7 +448,7 @@ private: union Item { Item* next; - char itemData[ITEM_SIZE]; + wchar_t itemData[ITEM_SIZE]; }; struct Block { Item items[ITEMS_PER_BLOCK]; @@ -459,7 +465,7 @@ private: /** - Implements the interface to the "Visitor pattern" (see the Accept() method.) + Implements the interface to the TINYXML2_STR("Visitor pattern") (see the Accept() method.) If you call the Accept() method, it requires being passed a XMLVisitor class to handle callbacks. For nodes that contain other nodes (Document, Element) you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs @@ -550,11 +556,11 @@ enum XMLError { class TINYXML2_LIB XMLUtil { public: - static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) { + static const wchar_t* SkipWhiteSpace( const wchar_t* p, int* curLineNumPtr ) { TIXMLASSERT( p ); while( IsWhiteSpace(*p) ) { - if (curLineNumPtr && *p == '\n') { + if (curLineNumPtr && *p == TINYXML2_CHAR('\n')) { ++(*curLineNumPtr); } ++p; @@ -562,17 +568,17 @@ public: TIXMLASSERT( p ); return p; } - static char* SkipWhiteSpace( char* p, int* curLineNumPtr ) { - return const_cast( SkipWhiteSpace( const_cast(p), curLineNumPtr ) ); + static wchar_t* SkipWhiteSpace( wchar_t* p, int* curLineNumPtr ) { + return const_cast( SkipWhiteSpace( const_cast(p), curLineNumPtr ) ); } // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't // correct, but simple, and usually works. - static bool IsWhiteSpace( char p ) { - return !IsUTF8Continuation(p) && isspace( static_cast(p) ); + static bool IsWhiteSpace( wchar_t p ) { + return !IsUTF8Continuation(p) && isspace( static_cast(p) ); } - inline static bool IsNameStartChar( unsigned char ch ) { + inline static bool IsNameStartChar( TINYXML2_UNSIGNED_CHAR ch ) { if ( ch >= 128 ) { // This is a heuristic guess in attempt to not implement Unicode-aware isalpha() return true; @@ -580,62 +586,62 @@ public: if ( isalpha( ch ) ) { return true; } - return ch == ':' || ch == '_'; + return ch == TINYXML2_CHAR(':') || ch == TINYXML2_CHAR('_'); } - inline static bool IsNameChar( unsigned char ch ) { + inline static bool IsNameChar( TINYXML2_UNSIGNED_CHAR ch ) { return IsNameStartChar( ch ) || isdigit( ch ) - || ch == '.' - || ch == '-'; + || ch == TINYXML2_CHAR('.') + || ch == TINYXML2_CHAR('-'); } - inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { + inline static bool StringEqual( const wchar_t* p, const wchar_t* q, int nChar=INT_MAX ) { if ( p == q ) { return true; } TIXMLASSERT( p ); TIXMLASSERT( q ); TIXMLASSERT( nChar >= 0 ); - return strncmp( p, q, nChar ) == 0; + return wcsncmp( p, q, nChar ) == 0; } - inline static bool IsUTF8Continuation( char p ) { + inline static bool IsUTF8Continuation( wchar_t p ) { return ( p & 0x80 ) != 0; } - static const char* ReadBOM( const char* p, bool* hasBOM ); + static const wchar_t* ReadBOM( const wchar_t* p, bool* hasBOM ); // p is the starting location, // the UTF-8 value of the entity will be placed in value, and length filled in. - static const char* GetCharacterRef( const char* p, char* value, int* length ); - static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); + static const wchar_t* GetCharacterRef( const wchar_t* p, wchar_t* value, int* length ); + static void ConvertUTF32ToUTF8( unsigned long input, wchar_t* output, int* length ); // converts primitive types to strings - static void ToStr( int v, char* buffer, int bufferSize ); - static void ToStr( unsigned v, char* buffer, int bufferSize ); - static void ToStr( bool v, char* buffer, int bufferSize ); - static void ToStr( float v, char* buffer, int bufferSize ); - static void ToStr( double v, char* buffer, int bufferSize ); - static void ToStr(int64_t v, char* buffer, int bufferSize); + static void ToStr( int v, wchar_t* buffer, int bufferSize ); + static void ToStr( unsigned v, wchar_t* buffer, int bufferSize ); + static void ToStr( bool v, wchar_t* buffer, int bufferSize ); + static void ToStr( float v, wchar_t* buffer, int bufferSize ); + static void ToStr( double v, wchar_t* buffer, int bufferSize ); + static void ToStr(int64_t v, wchar_t* buffer, int bufferSize); // converts strings to primitive types - static bool ToInt( const char* str, int* value ); - static bool ToUnsigned( const char* str, unsigned* value ); - static bool ToBool( const char* str, bool* value ); - static bool ToFloat( const char* str, float* value ); - static bool ToDouble( const char* str, double* value ); - static bool ToInt64(const char* str, int64_t* value); + static bool ToInt( const wchar_t* str, int* value ); + static bool ToUnsigned( const wchar_t* str, unsigned* value ); + static bool ToBool( const wchar_t* str, bool* value ); + static bool ToFloat( const wchar_t* str, float* value ); + static bool ToDouble( const wchar_t* str, double* value ); + static bool ToInt64(const wchar_t* str, int64_t* value); // Changes what is serialized for a boolean value. - // Default to "true" and "false". Shouldn't be changed + // Default to TINYXML2_STR("true" and "false"). Shouldn't be changed // unless you have a special testing or compatibility need. // Be careful: static, global, & not thread safe. // Be sure to set static const memory as parameters. - static void SetBoolSerialization(const char* writeTrue, const char* writeFalse); + static void SetBoolSerialization(const wchar_t* writeTrue, const wchar_t* writeFalse); private: - static const char* writeBoolTrue; - static const char* writeBoolFalse; + static const wchar_t* writeBoolTrue; + static const wchar_t* writeBoolFalse; }; @@ -734,12 +740,12 @@ public: Text: the text string @endverbatim */ - const char* Value() const; + const wchar_t* Value() const; /** Set the Value of an XML node. @sa Value() */ - void SetValue( const char* val, bool staticMem=false ); + void SetValue( const wchar_t* val, bool staticMem=false ); /// Gets the line number the node is in, if the document was parsed from a file. int GetLineNum() const { return _parseLineNum; } @@ -770,9 +776,9 @@ public: /** Get the first child element, or optionally the first child element with the specified name. */ - const XMLElement* FirstChildElement( const char* name = 0 ) const; + const XMLElement* FirstChildElement( const wchar_t* name = 0 ) const; - XMLElement* FirstChildElement( const char* name = 0 ) { + XMLElement* FirstChildElement( const wchar_t* name = 0 ) { return const_cast(const_cast(this)->FirstChildElement( name )); } @@ -788,9 +794,9 @@ public: /** Get the last child element or optionally the last child element with the specified name. */ - const XMLElement* LastChildElement( const char* name = 0 ) const; + const XMLElement* LastChildElement( const wchar_t* name = 0 ) const; - XMLElement* LastChildElement( const char* name = 0 ) { + XMLElement* LastChildElement( const wchar_t* name = 0 ) { return const_cast(const_cast(this)->LastChildElement(name) ); } @@ -804,9 +810,9 @@ public: } /// Get the previous (left) sibling element of this node, with an optionally supplied name. - const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ; + const XMLElement* PreviousSiblingElement( const wchar_t* name = 0 ) const ; - XMLElement* PreviousSiblingElement( const char* name = 0 ) { + XMLElement* PreviousSiblingElement( const wchar_t* name = 0 ) { return const_cast(const_cast(this)->PreviousSiblingElement( name ) ); } @@ -820,9 +826,9 @@ public: } /// Get the next (right) sibling element of this node, with an optionally supplied name. - const XMLElement* NextSiblingElement( const char* name = 0 ) const; + const XMLElement* NextSiblingElement( const wchar_t* name = 0 ) const; - XMLElement* NextSiblingElement( const char* name = 0 ) { + XMLElement* NextSiblingElement( const wchar_t* name = 0 ) { return const_cast(const_cast(this)->NextSiblingElement( name ) ); } @@ -913,13 +919,13 @@ public: - http://www.saxproject.org/ - http://c2.com/cgi/wiki?HierarchicalVisitorPattern - Which are both good references for "visiting". + Which are both good references for TINYXML2_STR("visiting"). An example of using Accept(): @verbatim XMLPrinter printer; tinyxmlDoc.Accept( &printer ); - const char* xmlcstr = printer.CStr(); + const wchar_t* xmlcstr = printer.CStr(); @endverbatim */ virtual bool Accept( XMLVisitor* visitor ) const = 0; @@ -942,7 +948,7 @@ protected: explicit XMLNode( XMLDocument* ); virtual ~XMLNode(); - virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr); + virtual wchar_t* ParseDeep( wchar_t* p, StrPair* parentEndTag, int* curLineNumPtr); XMLDocument* _document; XMLNode* _parent; @@ -962,7 +968,7 @@ private: void Unlink( XMLNode* child ); static void DeleteNode( XMLNode* node ); void InsertChildPreamble( XMLNode* insertThis ) const; - const XMLElement* ToElementWithName( const char* name ) const; + const XMLElement* ToElementWithName( const wchar_t* name ) const; XMLNode( const XMLNode& ); // not supported XMLNode& operator=( const XMLNode& ); // not supported @@ -976,7 +982,7 @@ private: This is bold @endverbatim - A text node can have 2 ways to output the next. "normal" output + A text node can have 2 ways to output the next. TINYXML2_STR("normal") output and CDATA. It will default to the mode it was parsed from the XML file and you generally want to leave it alone, but you can change the output mode with SetCData() and query it with CData(). @@ -1010,7 +1016,7 @@ protected: explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} virtual ~XMLText() {} - char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); + wchar_t* ParseDeep( wchar_t* p, StrPair* parentEndTag, int* curLineNumPtr ); private: bool _isCData; @@ -1041,7 +1047,7 @@ protected: explicit XMLComment( XMLDocument* doc ); virtual ~XMLComment(); - char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr); + wchar_t* ParseDeep( wchar_t* p, StrPair* parentEndTag, int* curLineNumPtr); private: XMLComment( const XMLComment& ); // not supported @@ -1051,7 +1057,7 @@ private: /** In correct XML the declaration is the first entry in the file. @verbatim - + @endverbatim TinyXML-2 will happily read or write files without a declaration, @@ -1080,7 +1086,7 @@ protected: explicit XMLDeclaration( XMLDocument* doc ); virtual ~XMLDeclaration(); - char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); + wchar_t* ParseDeep( wchar_t* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLDeclaration( const XMLDeclaration& ); // not supported @@ -1115,7 +1121,7 @@ protected: explicit XMLUnknown( XMLDocument* doc ); virtual ~XMLUnknown(); - char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); + wchar_t* ParseDeep( wchar_t* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLUnknown( const XMLUnknown& ); // not supported @@ -1135,10 +1141,10 @@ class TINYXML2_LIB XMLAttribute friend class XMLElement; public: /// The name of the attribute. - const char* Name() const; + const wchar_t* Name() const; /// The value of the attribute. - const char* Value() const; + const wchar_t* Value() const; /// Gets the line number the attribute is in, if the document was parsed from a file. int GetLineNum() const { return _parseLineNum; } @@ -1206,7 +1212,7 @@ public: XMLError QueryFloatValue( float* value ) const; /// Set the attribute to a string value. - void SetAttribute( const char* value ); + void SetAttribute( const wchar_t* value ); /// Set the attribute to value. void SetAttribute( int value ); /// Set the attribute to value. @@ -1228,9 +1234,9 @@ private: XMLAttribute( const XMLAttribute& ); // not supported void operator=( const XMLAttribute& ); // not supported - void SetName( const char* name ); + void SetName( const wchar_t* name ); - char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr ); + wchar_t* ParseDeep( wchar_t* p, bool processEntities, int* curLineNumPtr ); mutable StrPair _name; mutable StrPair _value; @@ -1249,11 +1255,11 @@ class TINYXML2_LIB XMLElement : public XMLNode friend class XMLDocument; public: /// Get the name of an element (which is the Value() of the node.) - const char* Name() const { + const wchar_t* Name() const { return Value(); } /// Set the name of the element. - void SetName( const char* str, bool staticMem=false ) { + void SetName( const wchar_t* str, bool staticMem=false ) { SetValue( str, staticMem ); } @@ -1270,7 +1276,7 @@ public: exists. For example: @verbatim - const char* value = ele->Attribute( "foo" ); + const wchar_t* value = ele->Attribute( TINYXML2_STR("foo") ); @endverbatim The 'value' parameter is normally null. However, if specified, @@ -1278,17 +1284,17 @@ public: match. This allow you to write code: @verbatim - if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar(); + if ( ele->Attribute( TINYXML2_STR("foo", "bar") ) ) callFooIsBar(); @endverbatim rather than: @verbatim - if ( ele->Attribute( "foo" ) ) { - if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar(); + if ( ele->Attribute( TINYXML2_STR("foo") ) ) { + if ( strcmp( ele->Attribute( TINYXML2_STR("foo" ), "bar") ) == 0 ) callFooIsBar(); } @endverbatim */ - const char* Attribute( const char* name, const char* value=0 ) const; + const wchar_t* Attribute( const wchar_t* name, const wchar_t* value=0 ) const; /** Given an attribute name, IntAttribute() returns the value of the attribute interpreted as an integer. The default @@ -1296,17 +1302,17 @@ public: or if there is an error. (For a method with error checking, see QueryIntAttribute()). */ - int IntAttribute(const char* name, int defaultValue = 0) const; + int IntAttribute(const wchar_t* name, int defaultValue = 0) const; /// See IntAttribute() - unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const; + unsigned UnsignedAttribute(const wchar_t* name, unsigned defaultValue = 0) const; /// See IntAttribute() - int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const; + int64_t Int64Attribute(const wchar_t* name, int64_t defaultValue = 0) const; /// See IntAttribute() - bool BoolAttribute(const char* name, bool defaultValue = false) const; + bool BoolAttribute(const wchar_t* name, bool defaultValue = false) const; /// See IntAttribute() - double DoubleAttribute(const char* name, double defaultValue = 0) const; + double DoubleAttribute(const wchar_t* name, double defaultValue = 0) const; /// See IntAttribute() - float FloatAttribute(const char* name, float defaultValue = 0) const; + float FloatAttribute(const wchar_t* name, float defaultValue = 0) const; /** Given an attribute name, QueryIntAttribute() returns XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion @@ -1318,10 +1324,10 @@ public: @verbatim int value = 10; - QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 + QueryIntAttribute( TINYXML2_STR("foo", &value ); // if "foo") isn't found, value will still be 10 @endverbatim */ - XMLError QueryIntAttribute( const char* name, int* value ) const { + XMLError QueryIntAttribute( const wchar_t* name, int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; @@ -1330,7 +1336,7 @@ public: } /// See QueryIntAttribute() - XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const { + XMLError QueryUnsignedAttribute( const wchar_t* name, unsigned int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; @@ -1339,7 +1345,7 @@ public: } /// See QueryIntAttribute() - XMLError QueryInt64Attribute(const char* name, int64_t* value) const { + XMLError QueryInt64Attribute(const wchar_t* name, int64_t* value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; @@ -1348,7 +1354,7 @@ public: } /// See QueryIntAttribute() - XMLError QueryBoolAttribute( const char* name, bool* value ) const { + XMLError QueryBoolAttribute( const wchar_t* name, bool* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; @@ -1356,7 +1362,7 @@ public: return a->QueryBoolValue( value ); } /// See QueryIntAttribute() - XMLError QueryDoubleAttribute( const char* name, double* value ) const { + XMLError QueryDoubleAttribute( const wchar_t* name, double* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; @@ -1364,7 +1370,7 @@ public: return a->QueryDoubleValue( value ); } /// See QueryIntAttribute() - XMLError QueryFloatAttribute( const char* name, float* value ) const { + XMLError QueryFloatAttribute( const wchar_t* name, float* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; @@ -1373,7 +1379,7 @@ public: } /// See QueryIntAttribute() - XMLError QueryStringAttribute(const char* name, const char** value) const { + XMLError QueryStringAttribute(const wchar_t* name, const wchar_t** value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; @@ -1398,67 +1404,67 @@ public: @verbatim int value = 10; - QueryAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 + QueryAttribute( TINYXML2_STR("foo", &value ); // if "foo") isn't found, value will still be 10 @endverbatim */ - XMLError QueryAttribute( const char* name, int* value ) const { + XMLError QueryAttribute( const wchar_t* name, int* value ) const { return QueryIntAttribute( name, value ); } - XMLError QueryAttribute( const char* name, unsigned int* value ) const { + XMLError QueryAttribute( const wchar_t* name, unsigned int* value ) const { return QueryUnsignedAttribute( name, value ); } - XMLError QueryAttribute(const char* name, int64_t* value) const { + XMLError QueryAttribute(const wchar_t* name, int64_t* value) const { return QueryInt64Attribute(name, value); } - XMLError QueryAttribute( const char* name, bool* value ) const { + XMLError QueryAttribute( const wchar_t* name, bool* value ) const { return QueryBoolAttribute( name, value ); } - XMLError QueryAttribute( const char* name, double* value ) const { + XMLError QueryAttribute( const wchar_t* name, double* value ) const { return QueryDoubleAttribute( name, value ); } - XMLError QueryAttribute( const char* name, float* value ) const { + XMLError QueryAttribute( const wchar_t* name, float* value ) const { return QueryFloatAttribute( name, value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, const char* value ) { + void SetAttribute( const wchar_t* name, const wchar_t* value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, int value ) { + void SetAttribute( const wchar_t* name, int value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, unsigned value ) { + void SetAttribute( const wchar_t* name, unsigned value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute(const char* name, int64_t value) { + void SetAttribute(const wchar_t* name, int64_t value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. - void SetAttribute( const char* name, bool value ) { + void SetAttribute( const wchar_t* name, bool value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, double value ) { + void SetAttribute( const wchar_t* name, double value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, float value ) { + void SetAttribute( const wchar_t* name, float value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } @@ -1466,29 +1472,29 @@ public: /** Delete an attribute. */ - void DeleteAttribute( const char* name ); + void DeleteAttribute( const wchar_t* name ); /// Return the first attribute in the list. const XMLAttribute* FirstAttribute() const { return _rootAttribute; } /// Query a specific attribute in the list. - const XMLAttribute* FindAttribute( const char* name ) const; + const XMLAttribute* FindAttribute( const wchar_t* name ) const; /** Convenience function for easy access to the text inside an element. Although easy and concise, GetText() is limited compared to getting the XMLText child and accessing it directly. If the first child of 'this' is a XMLText, the GetText() - returns the character string of the Text node, else null is returned. + returns the wchar_tacter string of the Text node, else null is returned. This is a convenient method for getting the text of simple contained text: @verbatim This is text - const char* str = fooElement->GetText(); + const wchar_t* str = fooElement->GetText(); @endverbatim - 'str' will be a pointer to "This is text". + 'str' will be a pointer to TINYXML2_STR("This is text"). Note that this function can be misleading. If the element foo was created from this XML: @@ -1501,9 +1507,9 @@ public: @verbatim This is text @endverbatim - GetText() will return "This is ". + GetText() will return TINYXML2_STR("This is "). */ - const char* GetText() const; + const wchar_t* GetText() const; /** Convenience function for easy access to the text inside an element. Although easy and concise, SetText() is limited compared to creating an XMLText child @@ -1515,7 +1521,7 @@ public: This is a convenient method for setting the text of simple contained text: @verbatim This is text - fooElement->SetText( "Hullaballoo!" ); + fooElement->SetText( TINYXML2_STR("Hullaballoo!") ); Hullaballoo! @endverbatim @@ -1525,7 +1531,7 @@ public: This is text @endverbatim - then it will not change "This is text", but rather prefix it with a text element: + then it will not change TINYXML2_STR("This is text"), but rather prefix it with a text element: @verbatim Hullaballoo!This is text @endverbatim @@ -1539,7 +1545,7 @@ public: Hullaballoo! @endverbatim */ - void SetText( const char* inText ); + void SetText( const wchar_t* inText ); /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText( int value ); /// Convenience method for setting text inside an element. See SetText() for important limitations. @@ -1564,13 +1570,13 @@ public: @endverbatim The QueryIntText() and similar functions provide a safe and easier way to get to the - "value" of x and y. + TINYXML2_STR("value") of x and y. @verbatim int x = 0; float y = 0; // types of x and y are contrived for example - const XMLElement* xElement = pointElement->FirstChildElement( "x" ); - const XMLElement* yElement = pointElement->FirstChildElement( "y" ); + const XMLElement* xElement = pointElement->FirstChildElement( TINYXML2_STR("x") ); + const XMLElement* yElement = pointElement->FirstChildElement( TINYXML2_STR("y") ); xElement->QueryIntText( &x ); yElement->QueryFloatText( &y ); @endverbatim @@ -1617,7 +1623,7 @@ public: virtual bool ShallowEqual( const XMLNode* compare ) const; protected: - char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); + wchar_t* ParseDeep( wchar_t* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLElement( XMLDocument* doc ); @@ -1625,8 +1631,8 @@ private: XMLElement( const XMLElement& ); // not supported void operator=( const XMLElement& ); // not supported - XMLAttribute* FindOrCreateAttribute( const char* name ); - char* ParseAttributes( char* p, int* curLineNumPtr ); + XMLAttribute* FindOrCreateAttribute( const wchar_t* name ); + wchar_t* ParseAttributes( wchar_t* p, int* curLineNumPtr ); static void DeleteAttribute( XMLAttribute* attribute ); XMLAttribute* CreateAttribute(); @@ -1654,7 +1660,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode { friend class XMLElement; // Gives access to SetError and Push/PopDepth, but over-access for everything else. - // Wishing C++ had "internal" scope. + // Wishing C++ had TINYXML2_STR("internal") scope. friend class XMLNode; friend class XMLText; friend class XMLComment; @@ -1675,7 +1681,7 @@ public: } /** - Parse an XML file from a character string. + Parse an XML file from a wchar_tacter string. Returns XML_SUCCESS (0) on success, or an errorID. @@ -1684,14 +1690,14 @@ public: specified, TinyXML-2 will assume 'xml' points to a null terminated string. */ - XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) ); + XMLError Parse( const wchar_t* xml, size_t nBytes=(size_t)(-1) ); /** Load an XML file from disk. Returns XML_SUCCESS (0) on success, or an errorID. */ - XMLError LoadFile( const char* filename ); + XMLError LoadFile( const wchar_t* filename ); /** Load an XML file from disk. You are responsible @@ -1711,7 +1717,7 @@ public: Returns XML_SUCCESS (0) on success, or an errorID. */ - XMLError SaveFile( const char* filename, bool compact = false ); + XMLError SaveFile( const wchar_t* filename, bool compact = false ); /** Save the XML file to disk. You are responsible @@ -1762,7 +1768,7 @@ public: @verbatim XMLPrinter printer; doc.Print( &printer ); - // printer.CStr() has a const char* to the XML + // printer.CStr() has a const wchar_t* to the XML @endverbatim */ void Print( XMLPrinter* streamer=0 ) const; @@ -1773,19 +1779,19 @@ public: this Document. The memory for the Element is managed by the Document. */ - XMLElement* NewElement( const char* name ); + XMLElement* NewElement( const wchar_t* name ); /** Create a new Comment associated with this Document. The memory for the Comment is managed by the Document. */ - XMLComment* NewComment( const char* comment ); + XMLComment* NewComment( const wchar_t* comment ); /** Create a new Text associated with this Document. The memory for the Text is managed by the Document. */ - XMLText* NewText( const char* text ); + XMLText* NewText( const wchar_t* text ); /** Create a new Declaration associated with this Document. The memory for the object @@ -1794,16 +1800,16 @@ public: If the 'text' param is null, the standard declaration is used.: @verbatim - + @endverbatim */ - XMLDeclaration* NewDeclaration( const char* text=0 ); + XMLDeclaration* NewDeclaration( const wchar_t* text=0 ); /** Create a new Unknown associated with this Document. The memory for the object is managed by the Document. */ - XMLUnknown* NewUnknown( const char* text ); + XMLUnknown* NewUnknown( const wchar_t* text ); /** Delete a node associated with this document. @@ -1823,16 +1829,13 @@ public: XMLError ErrorID() const { return _errorID; } - const char* ErrorName() const; - static const char* ErrorIDToName(XMLError errorID); + const wchar_t* ErrorName() const; + static const wchar_t* ErrorIDToName(XMLError errorID); - /** Returns a "long form" error description. A hopefully helpful + /** Returns a TINYXML2_STR("long form") error description. A hopefully helpful diagnostic with location, line number, and/or additional info. */ - const char* ErrorStr() const; - - /// A (trivial) utility function that prints the ErrorStr() to stdout. - void PrintError() const; + const wchar_t* ErrorStr() const; /// Return the line where the error occurred, or zero if unknown. int ErrorLineNum() const @@ -1853,7 +1856,7 @@ public: void DeepCopy(XMLDocument* target) const; // internal - char* Identify( char* p, XMLNode** node ); + wchar_t* Identify( wchar_t* p, XMLNode** node ); // internal void MarkInUse(XMLNode*); @@ -1875,7 +1878,7 @@ private: Whitespace _whitespaceMode; mutable StrPair _errorStr; int _errorLineNum; - char* _charBuffer; + wchar_t* _wcharBuffer; int _parseCurLineNum; int _parsingDepth; // Memory tracking does add some overhead. @@ -1891,11 +1894,11 @@ private: MemPoolT< sizeof(XMLText) > _textPool; MemPoolT< sizeof(XMLComment) > _commentPool; - static const char* _errorNames[XML_ERROR_COUNT]; + static const wchar_t* _errorNames[XML_ERROR_COUNT]; void Parse(); - void SetError( XMLError error, int lineNum, const char* format, ... ); + void SetError( XMLError error, int lineNum, const wchar_t* format, ... ); // Something of an obvious security hole, once it was discovered. // Either an ill-formed XML or an excessively deep one can overflow @@ -1940,39 +1943,39 @@ inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT& poo Take an example: @verbatim - - - + + + @endverbatim - Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + Assuming you want the value of TINYXML2_STR("attributeB" in the 2nd "Child") element, it's very easy to write a *lot* of code that looks like: @verbatim - XMLElement* root = document.FirstChildElement( "Document" ); + XMLElement* root = document.FirstChildElement( TINYXML2_STR("Document") ); if ( root ) { - XMLElement* element = root->FirstChildElement( "Element" ); + XMLElement* element = root->FirstChildElement( TINYXML2_STR("Element") ); if ( element ) { - XMLElement* child = element->FirstChildElement( "Child" ); + XMLElement* child = element->FirstChildElement( TINYXML2_STR("Child") ); if ( child ) { - XMLElement* child2 = child->NextSiblingElement( "Child" ); + XMLElement* child2 = child->NextSiblingElement( TINYXML2_STR("Child") ); if ( child2 ) { // Finally do something useful. @endverbatim - And that doesn't even cover "else" cases. XMLHandle addresses the verbosity + And that doesn't even cover TINYXML2_STR("else") cases. XMLHandle addresses the verbosity of such code. A XMLHandle checks for null pointers so it is perfectly safe and correct to use: @verbatim XMLHandle docHandle( &document ); - XMLElement* child2 = docHandle.FirstChildElement( "Document" ).FirstChildElement( "Element" ).FirstChildElement().NextSiblingElement(); + XMLElement* child2 = docHandle.FirstChildElement( TINYXML2_STR("Document" ).FirstChildElement( "Element") ).FirstChildElement().NextSiblingElement(); if ( child2 ) { // do something useful @@ -2010,7 +2013,7 @@ public: return XMLHandle( _node ? _node->FirstChild() : 0 ); } /// Get the first child element of this handle. - XMLHandle FirstChildElement( const char* name = 0 ) { + XMLHandle FirstChildElement( const wchar_t* name = 0 ) { return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 ); } /// Get the last child of this handle. @@ -2018,7 +2021,7 @@ public: return XMLHandle( _node ? _node->LastChild() : 0 ); } /// Get the last child element of this handle. - XMLHandle LastChildElement( const char* name = 0 ) { + XMLHandle LastChildElement( const wchar_t* name = 0 ) { return XMLHandle( _node ? _node->LastChildElement( name ) : 0 ); } /// Get the previous sibling of this handle. @@ -2026,7 +2029,7 @@ public: return XMLHandle( _node ? _node->PreviousSibling() : 0 ); } /// Get the previous sibling element of this handle. - XMLHandle PreviousSiblingElement( const char* name = 0 ) { + XMLHandle PreviousSiblingElement( const wchar_t* name = 0 ) { return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 ); } /// Get the next sibling of this handle. @@ -2034,7 +2037,7 @@ public: return XMLHandle( _node ? _node->NextSibling() : 0 ); } /// Get the next sibling element of this handle. - XMLHandle NextSiblingElement( const char* name = 0 ) { + XMLHandle NextSiblingElement( const wchar_t* name = 0 ) { return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 ); } @@ -2086,25 +2089,25 @@ public: const XMLConstHandle FirstChild() const { return XMLConstHandle( _node ? _node->FirstChild() : 0 ); } - const XMLConstHandle FirstChildElement( const char* name = 0 ) const { + const XMLConstHandle FirstChildElement( const wchar_t* name = 0 ) const { return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 ); } const XMLConstHandle LastChild() const { return XMLConstHandle( _node ? _node->LastChild() : 0 ); } - const XMLConstHandle LastChildElement( const char* name = 0 ) const { + const XMLConstHandle LastChildElement( const wchar_t* name = 0 ) const { return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 ); } const XMLConstHandle PreviousSibling() const { return XMLConstHandle( _node ? _node->PreviousSibling() : 0 ); } - const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const { + const XMLConstHandle PreviousSiblingElement( const wchar_t* name = 0 ) const { return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 ); } const XMLConstHandle NextSibling() const { return XMLConstHandle( _node ? _node->NextSibling() : 0 ); } - const XMLConstHandle NextSiblingElement( const char* name = 0 ) const { + const XMLConstHandle NextSiblingElement( const wchar_t* name = 0 ) const { return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 ); } @@ -2167,8 +2170,8 @@ private: @verbatim XMLPrinter printer( fp ); - printer.OpenElement( "foo" ); - printer.PushAttribute( "foo", "bar" ); + printer.OpenElement( TINYXML2_STR("foo") ); + printer.PushAttribute( TINYXML2_STR("foo", "bar") ); printer.CloseElement(); @endverbatim */ @@ -2189,19 +2192,19 @@ public: /** If streaming, start writing an element. The element must be closed with CloseElement() */ - void OpenElement( const char* name, bool compactMode=false ); + void OpenElement( const wchar_t* name, bool compactMode=false ); /// If streaming, add an attribute to an open element. - void PushAttribute( const char* name, const char* value ); - void PushAttribute( const char* name, int value ); - void PushAttribute( const char* name, unsigned value ); - void PushAttribute(const char* name, int64_t value); - void PushAttribute( const char* name, bool value ); - void PushAttribute( const char* name, double value ); + void PushAttribute( const wchar_t* name, const wchar_t* value ); + void PushAttribute( const wchar_t* name, int value ); + void PushAttribute( const wchar_t* name, unsigned value ); + void PushAttribute(const wchar_t* name, int64_t value); + void PushAttribute( const wchar_t* name, bool value ); + void PushAttribute( const wchar_t* name, double value ); /// If streaming, close the Element. virtual void CloseElement( bool compactMode=false ); /// Add a text node. - void PushText( const char* text, bool cdata=false ); + void PushText( const wchar_t* text, bool cdata=false ); /// Add a text node from an integer. void PushText( int value ); /// Add a text node from an unsigned. @@ -2216,10 +2219,10 @@ public: void PushText( double value ); /// Add a comment - void PushComment( const char* comment ); + void PushComment( const wchar_t* comment ); - void PushDeclaration( const char* value ); - void PushUnknown( const char* value ); + void PushDeclaration( const wchar_t* value ); + void PushUnknown( const wchar_t* value ); virtual bool VisitEnter( const XMLDocument& /*doc*/ ); virtual bool VisitExit( const XMLDocument& /*doc*/ ) { @@ -2238,7 +2241,7 @@ public: If in print to memory mode, return a pointer to the XML file in memory. */ - const char* CStr() const { + const wchar_t* CStr() const { return _buffer.Mem(); } /** @@ -2266,17 +2269,17 @@ protected: the space and tabs used. A PrintSpace() override should call Print(). */ virtual void PrintSpace( int depth ); - void Print( const char* format, ... ); - void Write( const char* data, size_t size ); - inline void Write( const char* data ) { Write( data, strlen( data ) ); } - void Putc( char ch ); + void Print( const wchar_t* format, ... ); + void Write( const wchar_t* data, size_t size ); + inline void Write( const wchar_t* data ) { Write( data, wcslen( data ) ); } + void Putc( wchar_t ch ); void SealElementIfJustOpened(); bool _elementJustOpened; - DynArray< const char*, 10 > _stack; + DynArray< const wchar_t*, 10 > _stack; private: - void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities. + void PrintString( const wchar_t*, bool restrictedEntitySet ); // prints out, after detecting entities. bool _firstElement; FILE* _fp; @@ -2292,7 +2295,7 @@ private: bool _entityFlag[ENTITY_RANGE]; bool _restrictedEntityFlag[ENTITY_RANGE]; - DynArray< char, 20 > _buffer; + DynArray< wchar_t, 20 > _buffer; // Prohibit cloning, intentionally not implemented XMLPrinter( const XMLPrinter& ); diff --git a/kiwano/utils/ResLoader.cpp b/kiwano/utils/ResLoader.cpp index 9cb2cb7a..edc6bd61 100644 --- a/kiwano/utils/ResLoader.cpp +++ b/kiwano/utils/ResLoader.cpp @@ -36,7 +36,7 @@ namespace kiwano }; bool LoadImagesFromData(ResLoader* loader, GlobalData* gdata, const String* id, const String* type, - const String* file, const Array* files, int rows, int cols) + const String* file, const Array* files, int rows, int cols) { if (!gdata || !id) return false; @@ -104,11 +104,11 @@ namespace kiwano if (image.count(L"files")) { - Array files; + Array files; files.reserve(image[L"files"].size()); for (const auto& file : image[L"files"]) { - files.push_back(file.as_string()); + files.push_back(file.as_string().c_str()); } if (!LoadImagesFromData(loader, &global_data, id, type, file, &files, rows, cols)) return false; @@ -126,32 +126,32 @@ namespace kiwano bool LoadXmlData(ResLoader* loader, tinyxml2::XMLElement* elem) { GlobalData global_data; - if (auto path = elem->FirstChildElement("path")) + if (auto path = elem->FirstChildElement(L"path")) { - global_data.path = string_to_wide(path->GetText()); + global_data.path = path->GetText(); } - if (auto images = elem->FirstChildElement("images")) + if (auto images = elem->FirstChildElement(L"images")) { for (auto image = images->FirstChildElement(); image; image = image->NextSiblingElement()) { String id, type, file; int rows = 0, cols = 0; - if (auto attr = image->Attribute("id")) id = string_to_wide(attr); - if (auto attr = image->Attribute("type")) type = string_to_wide(attr); - if (auto attr = image->Attribute("file")) file = string_to_wide(attr); - if (auto attr = image->IntAttribute("rows")) rows = attr; - if (auto attr = image->IntAttribute("cols")) cols = attr; + if (auto attr = image->Attribute(L"id")) id.assign(attr); // assign() copies attr content + if (auto attr = image->Attribute(L"type")) type = attr; // operator=() just holds attr pointer + if (auto attr = image->Attribute(L"file")) file = attr; + if (auto attr = image->IntAttribute(L"rows")) rows = attr; + if (auto attr = image->IntAttribute(L"cols")) cols = attr; if (file.empty() && !image->NoChildren()) { - Array files_arr; + Array files_arr; for (auto file = image->FirstChildElement(); file; file = file->NextSiblingElement()) { - if (auto path = file->Attribute("path")) + if (auto path = file->Attribute(L"path")) { - files_arr.push_back(string_to_wide(path)); + files_arr.push_back(path); } } if (!LoadImagesFromData(loader, &global_data, &id, &type, &file, &files_arr, rows, cols)) @@ -237,12 +237,30 @@ namespace kiwano bool ResLoader::LoadFromXmlFile(String const& file_path) { tinyxml2::XMLDocument doc; - if (tinyxml2::XML_SUCCESS != doc.LoadFile(kiwano::wide_to_string(file_path).c_str())) + + std::wifstream ifs; + ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit); + + try { - KGE_WARNING_LOG(L"ResLoader::LoadFromXmlFile failed: %s", - string_to_wide(tinyxml2::XMLDocument::ErrorIDToName(doc.ErrorID())).c_str()); + ifs.open(file_path.c_str()); + + std::wstringstream ss; + ss << ifs.rdbuf(); + + if (tinyxml2::XML_SUCCESS != doc.Parse(ss.str().c_str())) + { + KGE_WARNING_LOG(L"ResLoader::LoadFromXmlFile failed: %s (%s)", + tinyxml2::XMLDocument::ErrorIDToName(doc.ErrorID()), doc.ErrorStr()); + return false; + } + } + catch (std::wifstream::failure& e) + { + KGE_WARNING_LOG(L"ResLoader::LoadFromXmlFile failed: Cannot open file. (%s)", string_to_wide(e.what()).c_str()); return false; } + return LoadFromXml(&doc); } @@ -252,21 +270,19 @@ namespace kiwano { try { - auto root = doc->FirstChildElement("resources"); - KGE_ASSERT(root); - - if (root) + if (auto root = doc->FirstChildElement(L"resources")) { - kiwano::string version = root->FirstChildElement("version")->GetText(); + kiwano::wstring version; + if (auto ver = root->FirstChildElement(L"version")) version = ver->GetText(); - auto load = load_xml_funcs.find(string_to_wide(version)); + auto load = load_xml_funcs.find(version); if (load != load_xml_funcs.end()) { - load->second(this, root); + return load->second(this, root); } else if (version.empty()) { - load_xml_funcs[L"latest"](this, root); + return load_xml_funcs[L"latest"](this, root); } else {