From 04bc02fc223cf1a6a92906a996c058d2b3243894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Wed, 28 Apr 2021 10:12:29 +0200 Subject: [PATCH] Cleanup C++0x support in irrUString.h (#33) --- include/irrUString.h | 190 +------------------------------------------ 1 file changed, 4 insertions(+), 186 deletions(-) diff --git a/include/irrUString.h b/include/irrUString.h index 09172ee6..c1c7925e 100644 --- a/include/irrUString.h +++ b/include/irrUString.h @@ -30,13 +30,6 @@ #pragma once -#if (__cplusplus > 199711L) || (_MSC_VER >= 1600) || defined(__GXX_EXPERIMENTAL_CXX0X__) -# define USTRING_CPP0X -# if defined(__GXX_EXPERIMENTAL_CXX0X__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))) -# define USTRING_CPP0X_NEWLITERALS -# endif -#endif - #include #include #include @@ -54,15 +47,11 @@ #include #endif -#ifdef USTRING_CPP0X -# include -#endif +#include -#ifndef USTRING_NO_STL -# include -# include -# include -#endif +#include +#include +#include #include "irrTypes.h" #include "irrAllocator.h" @@ -85,15 +74,9 @@ namespace irr { // Define our character types. -#ifdef USTRING_CPP0X_NEWLITERALS // C++0x typedef char32_t uchar32_t; typedef char16_t uchar16_t; typedef char uchar8_t; -#else - typedef u32 uchar32_t; - typedef u16 uchar16_t; - typedef u8 uchar8_t; -#endif namespace core { @@ -448,7 +431,6 @@ public: //! Iterator to iterate through a UTF-16 string. -#ifndef USTRING_NO_STL class _ustring16_const_iterator : public std::iterator< std::bidirectional_iterator_tag, // iterator_category access, // value_type @@ -456,9 +438,6 @@ public: const access, // pointer const access // reference > -#else - class _ustring16_const_iterator -#endif { public: typedef _ustring16_const_iterator _Iter; @@ -466,19 +445,11 @@ public: typedef const access const_pointer; typedef const access const_reference; -#ifndef USTRING_NO_STL typedef typename _Base::value_type value_type; typedef typename _Base::difference_type difference_type; typedef typename _Base::difference_type distance_type; typedef typename _Base::pointer pointer; typedef const_reference reference; -#else - typedef access value_type; - typedef u32 difference_type; - typedef u32 distance_type; - typedef const_pointer pointer; - typedef const_reference reference; -#endif //! Constructors. _ustring16_const_iterator(const _Iter& i) : ref(i.ref), pos(i.pos) {} @@ -854,8 +825,6 @@ public: *this = other; } - -#ifndef USTRING_NO_STL //! Constructor from std::string template ustring16(const std::basic_string& other) @@ -886,39 +855,6 @@ public: for (; first != last; ++first) append((uchar32_t)*first); } -#endif - - -#ifndef USTRING_CPP0X_NEWLITERALS - //! Constructor for copying a character string from a pointer. - ustring16(const char* const c) - : array(0), allocated(0), used(0) - { -#if __BYTE_ORDER == __BIG_ENDIAN - encoding = unicode::EUTFE_UTF16_BE; -#else - encoding = unicode::EUTFE_UTF16_LE; -#endif - - loadDataStream(c, strlen(c)); - //append((uchar8_t*)c); - } - - - //! Constructor for copying a character string from a pointer with a given length. - ustring16(const char* const c, u32 length) - : array(0), allocated(0), used(0) - { -#if __BYTE_ORDER == __BIG_ENDIAN - encoding = unicode::EUTFE_UTF16_BE; -#else - encoding = unicode::EUTFE_UTF16_LE; -#endif - - loadDataStream(c, length); - } -#endif - //! Constructor for copying a UTF-8 string from a pointer. ustring16(const uchar8_t* const c) @@ -1056,7 +992,6 @@ public: } -#ifdef USTRING_CPP0X //! Constructor for moving a ustring16 ustring16(ustring16&& other) : array(other.array), encoding(other.encoding), allocated(other.allocated), used(other.used) @@ -1066,8 +1001,6 @@ public: other.allocated = 0; other.used = 0; } -#endif - //! Destructor ~ustring16() @@ -1102,8 +1035,6 @@ public: return *this; } - -#ifdef USTRING_CPP0X //! Move assignment operator ustring16& operator=(ustring16&& other) { @@ -1121,8 +1052,6 @@ public: } return *this; } -#endif - //! Assignment operator for other string types template @@ -2091,7 +2020,6 @@ public: } -#ifdef USTRING_CPP0X_NEWLITERALS //! Appends a number to this ustring16. //! \param c Number to append. //! \return A reference to our current string. @@ -2110,7 +2038,6 @@ public: append(core::stringc(c)); return *this; } -#endif //! Appends a number to this ustring16. @@ -2899,47 +2826,6 @@ public: } -#ifdef USTRING_CPP0X_NEWLITERALS // C++0x - //! Converts the string to a UTF-16 encoded string. - //! \param endian The desired endianness of the string. - //! \param addBOM If true, the proper unicode byte-order mark will be prefixed to the string. - //! \return A string containing the UTF-16 encoded string. - core::string toUTF16_s(const unicode::EUTF_ENDIAN endian = unicode::EUTFEE_NATIVE, const bool addBOM = false) const - { - core::string ret; - ret.reserve(used + (addBOM ? unicode::BOM_UTF16_LEN : 0) + 1); - - // Add the BOM if specified. - if (addBOM) - { - if (endian == unicode::EUTFEE_NATIVE) - ret[0] = unicode::BOM; - else if (endian == unicode::EUTFEE_LITTLE) - { - uchar8_t* ptr8 = reinterpret_cast(&ret[0]); - *ptr8++ = unicode::BOM_ENCODE_UTF16_LE[0]; - *ptr8 = unicode::BOM_ENCODE_UTF16_LE[1]; - } - else - { - uchar8_t* ptr8 = reinterpret_cast(&ret[0]); - *ptr8++ = unicode::BOM_ENCODE_UTF16_BE[0]; - *ptr8 = unicode::BOM_ENCODE_UTF16_BE[1]; - } - } - - ret.append(array); - if (endian != unicode::EUTFEE_NATIVE && getEndianness() != endian) - { - char16_t* ptr = ret.c_str(); - for (u32 i = 0; i < ret.size(); ++i) - *ptr++ = unicode::swapEndian16(*ptr); - } - return ret; - } -#endif - - //! Converts the string to a UTF-16 encoded string array. //! Unfortunately, no toUTF16_s() version exists due to limitations with Irrlicht's string class. //! \param endian The desired endianness of the string. @@ -2982,61 +2868,6 @@ public: } -#ifdef USTRING_CPP0X_NEWLITERALS // C++0x - //! Converts the string to a UTF-32 encoded string. - //! \param endian The desired endianness of the string. - //! \param addBOM If true, the proper unicode byte-order mark will be prefixed to the string. - //! \return A string containing the UTF-32 encoded string. - core::string toUTF32_s(const unicode::EUTF_ENDIAN endian = unicode::EUTFEE_NATIVE, const bool addBOM = false) const - { - core::string ret; - ret.reserve(size() + 1 + (addBOM ? unicode::BOM_UTF32_LEN : 0)); - const_iterator iter(*this, 0); - - // Add the BOM if specified. - if (addBOM) - { - if (endian == unicode::EUTFEE_NATIVE) - ret.append(unicode::BOM); - else - { - union - { - uchar32_t full; - u8 chunk[4]; - } t; - - if (endian == unicode::EUTFEE_LITTLE) - { - t.chunk[0] = unicode::BOM_ENCODE_UTF32_LE[0]; - t.chunk[1] = unicode::BOM_ENCODE_UTF32_LE[1]; - t.chunk[2] = unicode::BOM_ENCODE_UTF32_LE[2]; - t.chunk[3] = unicode::BOM_ENCODE_UTF32_LE[3]; - } - else - { - t.chunk[0] = unicode::BOM_ENCODE_UTF32_BE[0]; - t.chunk[1] = unicode::BOM_ENCODE_UTF32_BE[1]; - t.chunk[2] = unicode::BOM_ENCODE_UTF32_BE[2]; - t.chunk[3] = unicode::BOM_ENCODE_UTF32_BE[3]; - } - ret.append(t.full); - } - } - - while (!iter.atEnd()) - { - uchar32_t c = *iter; - if (endian != unicode::EUTFEE_NATIVE && getEndianness() != endian) - c = unicode::swapEndian32(c); - ret.append(c); - ++iter; - } - return ret; - } -#endif - - //! Converts the string to a UTF-32 encoded string array. //! Unfortunately, no toUTF32_s() version exists due to limitations with Irrlicht's string class. //! \param endian The desired endianness of the string. @@ -3371,7 +3202,6 @@ inline ustring16 operator+(const char left, const ustring16& rig } -#ifdef USTRING_CPP0X_NEWLITERALS //! Appends a ustring16 and a uchar32_t. template inline ustring16 operator+(const ustring16& left, const uchar32_t right) @@ -3390,7 +3220,6 @@ inline ustring16 operator+(const uchar32_t left, const ustring16 ret += right; return ret; } -#endif //! Appends a ustring16 and a short. @@ -3553,7 +3382,6 @@ inline ustring16 operator+(const double left, const ustring16& r } -#ifdef USTRING_CPP0X //! Appends two ustring16s. template inline ustring16&& operator+(const ustring16& left, ustring16&& right) @@ -3671,7 +3499,6 @@ inline ustring16 operator+(const char left, ustring16&& right) } -#ifdef USTRING_CPP0X_NEWLITERALS //! Appends a ustring16 and a uchar32_t. template inline ustring16 operator+(ustring16&& left, const uchar32_t right) @@ -3688,7 +3515,6 @@ inline ustring16 operator+(const uchar32_t left, ustring16&& rig right.insert(left, 0); return std::move(right); } -#endif //! Appends a ustring16 and a short. @@ -3833,10 +3659,8 @@ inline ustring16 operator+(const double left, ustring16&& right) right.insert(core::stringc(left), 0); return std::move(right); } -#endif -#ifndef USTRING_NO_STL //! Writes a ustring16 to an ostream. template inline std::ostream& operator<<(std::ostream& out, const ustring16& in) @@ -3852,10 +3676,6 @@ inline std::wostream& operator<<(std::wostream& out, const ustring16& in out << in.toWCHAR_s().c_str(); return out; } -#endif - - -#ifndef USTRING_NO_STL namespace unicode { @@ -3885,7 +3705,5 @@ class hash : public std::unary_function } // end namespace unicode -#endif - } // end namespace core } // end namespace irr