Commit 95680f93 authored by hybrid's avatar hybrid

Replace raw xml char implementation with template struct in order to decouple...

Replace raw xml char implementation with template struct in order to decouple the type from POD types. May also help for 64bit problems or changes needed there.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3256 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5d154682
...@@ -958,7 +958,7 @@ public: ...@@ -958,7 +958,7 @@ public:
//! Appends a string representation of a number to this string //! Appends a string representation of a number to this string
/** \param i Number to append. */ /** \param i Number to append. */
string<T,TAlloc>& operator += (const unsigned long& i) string<T,TAlloc>& operator += (const unsigned long i)
{ {
append(string<T,TAlloc>(i)); append(string<T,TAlloc>(i));
return *this; return *this;
......
...@@ -366,15 +366,29 @@ namespace io ...@@ -366,15 +366,29 @@ namespace io
}; };
template <typename T>
struct xmlChar
{
T c;
xmlChar<T>() {}
xmlChar<T>(char in) : c(static_cast<T>(in)) {}
xmlChar<T>(wchar_t in) : c(static_cast<T>(in)) {}
explicit xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
explicit xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
explicit xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
operator T() const { return c; }
void operator=(int t) { c=static_cast<T>(t); }
};
//! defines the utf-16 type. //! defines the utf-16 type.
/** Not using wchar_t for this because /** Not using wchar_t for this because
wchar_t has 16 bit on windows and 32 bit on other operating systems. */ wchar_t has 16 bit on windows and 32 bit on other operating systems. */
typedef unsigned short char16; typedef xmlChar<unsigned short> char16;
//! defines the utf-32 type. //! defines the utf-32 type.
/** Not using wchar_t for this because /** Not using wchar_t for this because
wchar_t has 16 bit on windows and 32 bit on other operating systems. */ wchar_t has 16 bit on windows and 32 bit on other operating systems. */
typedef unsigned long char32; typedef xmlChar<unsigned int> char32;
//! A UTF-8 or ASCII character xml parser. //! A UTF-8 or ASCII character xml parser.
/** This means that all character data will be returned in 8 bit ASCII or UTF-8 by this parser. /** This means that all character data will be returned in 8 bit ASCII or UTF-8 by this parser.
......
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
virtual bool read() virtual bool read()
{ {
// if not end reached, parse the node // if not end reached, parse the node
if (P && (unsigned int)(P - TextBegin) < TextSize - 1 && *P != 0) if (P && ((unsigned int)(P - TextBegin) < TextSize - 1) && (*P != 0))
{ {
return parseCurrentNode(); return parseCurrentNode();
} }
...@@ -577,21 +577,21 @@ private: ...@@ -577,21 +577,21 @@ private:
// based on the byte order mark. // based on the byte order mark.
const unsigned char UTF8[] = {0xEF, 0xBB, 0xBF}; // 0xEFBBBF; const unsigned char UTF8[] = {0xEF, 0xBB, 0xBF}; // 0xEFBBBF;
const int UTF16_BE = 0xFFFE; const u16 UTF16_BE = 0xFFFE;
const int UTF16_LE = 0xFEFF; const u16 UTF16_LE = 0xFEFF;
const int UTF32_BE = 0xFFFE0000; const u32 UTF32_BE = 0xFFFE0000;
const int UTF32_LE = 0x0000FEFF; const u32 UTF32_LE = 0x0000FEFF;
// check source for all utf versions and convert to target data format // check source for all utf versions and convert to target data format
if (size >= 4 && data32[0] == (char32)UTF32_BE) if (size >= 4 && data32[0] == static_cast<char32>(UTF32_BE))
{ {
// UTF-32, big endian // UTF-32, big endian
SourceFormat = ETF_UTF32_BE; SourceFormat = ETF_UTF32_BE;
convertTextData(data32+1, data8, (size/4)-1); // data32+1 because we need to skip the header convertTextData(data32+1, data8, (size/4)-1); // data32+1 because we need to skip the header
} }
else else
if (size >= 4 && data32[0] == (char32)UTF32_LE) if (size >= 4 && data32[0] == static_cast<char32>(UTF32_LE))
{ {
// UTF-32, little endian // UTF-32, little endian
SourceFormat = ETF_UTF32_LE; SourceFormat = ETF_UTF32_LE;
...@@ -630,10 +630,11 @@ private: ...@@ -630,10 +630,11 @@ private:
//! converts the text file into the desired format. //! converts the text file into the desired format.
//! \param source: begin of the text (without byte order mark) /** \param source: begin of the text (without byte order mark)
//! \param pointerToStore: pointer to text data block which can be \param pointerToStore: pointer to text data block which can be
//! stored or deleted based on the nesessary conversion. stored or deleted based on the nesessary conversion.
//! \param sizeWithoutHeader: Text size in characters without header \param sizeWithoutHeader: Text size in characters without header
*/
template<class src_char_type> template<class src_char_type>
void convertTextData(src_char_type* source, char* pointerToStore, int sizeWithoutHeader) void convertTextData(src_char_type* source, char* pointerToStore, int sizeWithoutHeader)
{ {
...@@ -660,7 +661,7 @@ private: ...@@ -660,7 +661,7 @@ private:
TextData = new char_type[sizeWithoutHeader]; TextData = new char_type[sizeWithoutHeader];
for (int i=0; i<sizeWithoutHeader; ++i) for (int i=0; i<sizeWithoutHeader; ++i)
TextData[i] = (char_type)source[i]; TextData[i] = static_cast<char_type>(source[i]);
TextBegin = TextData; TextBegin = TextData;
TextSize = sizeWithoutHeader; TextSize = sizeWithoutHeader;
......
...@@ -159,8 +159,8 @@ IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file) ...@@ -159,8 +159,8 @@ IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file)
//! Creates an instance of an UTF-32 xml parser. //! Creates an instance of an UTF-32 xml parser.
IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(IFileReadCallBack* callback, IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(
bool deleteCallback) IFileReadCallBack* callback, bool deleteCallback)
{ {
if (callback && (callback->getSize() >= 0)) if (callback && (callback->getSize() >= 0))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment