diff --git a/src/lib/base/Unicode.cpp b/src/lib/base/Unicode.cpp index e644d599c..2567f36d7 100644 --- a/src/lib/base/Unicode.cpp +++ b/src/lib/base/Unicode.cpp @@ -227,16 +227,6 @@ std::string Unicode::UTF16ToUTF8(const std::string_view &src, bool *errors) return doUTF16ToUTF8(reinterpret_cast(src.data()), n, errors); } -std::string Unicode::UTF32ToUTF8(const std::string_view &src, bool *errors) -{ - // default to success - resetError(errors); - - // convert - uint32_t n = (uint32_t)src.size() >> 2; - return doUTF32ToUTF8(reinterpret_cast(src.data()), n, errors); -} - std::string Unicode::doUCS2ToUTF8(const uint8_t *data, uint32_t n, bool *errors) { // make some space @@ -368,48 +358,6 @@ std::string Unicode::doUTF16ToUTF8(const uint8_t *data, uint32_t n, bool *errors return dst; } -std::string Unicode::doUTF32ToUTF8(const uint8_t *data, uint32_t n, bool *errors) -{ - // make some space - std::string dst; - dst.reserve(n); - - // check if first character is 0xfffe or 0xfeff - bool byteSwapped = false; - if (n >= 1) { - switch (decode32(data, false)) { - case 0x0000feff: - data += 4; - --n; - break; - - case 0x0000fffe: - byteSwapped = true; - data += 4; - --n; - break; - - default: - break; - } - } -#ifdef WORDS_BIGENDIAN - byteSwapped = !byteSwapped; -#endif - // convert each character - for (; n > 0; --n) { - auto c = decode32(data, byteSwapped); - if (c >= 0x00110000) { - setError(errors); - c = s_replacement; - } - toUTF8(dst, c, errors); - data += 4; - } - - return dst; -} - uint32_t Unicode::fromUTF8(const uint8_t *&data, uint32_t &n) { assert(data != nullptr); diff --git a/src/lib/base/Unicode.h b/src/lib/base/Unicode.h index a095f8b8f..a35e147a0 100644 --- a/src/lib/base/Unicode.h +++ b/src/lib/base/Unicode.h @@ -81,13 +81,6 @@ public: */ static std::string UTF16ToUTF8(const std::string_view &, bool *errors = nullptr); - //! Convert from UTF-32 to UTF-8 - /*! - Convert from UTF-32 to UTF-8. If errors is not nullptr then *errors is - set to true iff any character could not be decoded. - */ - static std::string UTF32ToUTF8(const std::string_view &, bool *errors = nullptr); - //@} private: @@ -95,7 +88,6 @@ private: static std::string doUCS2ToUTF8(const uint8_t *src, uint32_t n, bool *errors); static std::string doUCS4ToUTF8(const uint8_t *src, uint32_t n, bool *errors); static std::string doUTF16ToUTF8(const uint8_t *src, uint32_t n, bool *errors); - static std::string doUTF32ToUTF8(const uint8_t *src, uint32_t n, bool *errors); // convert characters to/from UTF8 static uint32_t fromUTF8(const uint8_t *&src, uint32_t &size); diff --git a/src/unittests/base/UnicodeTests.cpp b/src/unittests/base/UnicodeTests.cpp index 20fd8547c..b3854075d 100644 --- a/src/unittests/base/UnicodeTests.cpp +++ b/src/unittests/base/UnicodeTests.cpp @@ -14,15 +14,6 @@ void UnicodeTests::initTestCase() m_log.setFilter(LogLevel::Debug2); } -void UnicodeTests::UTF32ToUTF8() -{ - bool errors; - auto result = Unicode::UTF32ToUTF8(std::string("h\0\0\0e\0\0\0l\0\0\0l\0\0\0o\0\0\0", 20), &errors); - - QVERIFY(!errors); - QCOMPARE(result.c_str(), "hello"); -} - void UnicodeTests::UTF16ToUTF8() { bool errors; diff --git a/src/unittests/base/UnicodeTests.h b/src/unittests/base/UnicodeTests.h index bd3190864..349bfa4b5 100644 --- a/src/unittests/base/UnicodeTests.h +++ b/src/unittests/base/UnicodeTests.h @@ -13,7 +13,6 @@ class UnicodeTests : public QObject Q_OBJECT private Q_SLOTS: void initTestCase(); - void UTF32ToUTF8(); void UTF16ToUTF8(); private: