From a842220fe6f3211d046b7718c8aba7e0b0f23acf Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 18 Mar 2013 06:08:05 +0900 Subject: [PATCH] Revert "Use the standard library to convert between UTF-8 and UTF-16 where possible" This reverts commit 19ce4d0dfa8c13255f56342f8c179c6a601d9b2d. --- taglib/toolkit/tstring.cpp | 88 ++------------------------------------ 1 file changed, 4 insertions(+), 84 deletions(-) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 530a9c6f..e88b70f7 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -31,24 +31,6 @@ #include #include -// Determine if the compiler supports codecvt. - -#ifndef __has_include -# define __has_include(x) 0 -#endif - -#if (((defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__)) /* GCC with -std=c++0x option */ \ - || (defined(_MSC_VER) && _MSC_VER >= 1600))) /* VC++2010 or later */ \ - || (defined(__has_include) && __has_include()) /* Clang has */ - -# define TAGLIB_USE_CODECVT -#endif - -#ifdef TAGLIB_USE_CODECVT -# include - typedef std::codecvt_utf8_utf16 utf8_utf16_t; -#endif - using namespace TagLib; namespace { @@ -233,20 +215,6 @@ std::string String::to8Bit(bool unicode) const else { s.resize(d->data.size() * 4 + 1); -#ifdef TAGLIB_USE_CODECVT - - std::mbstate_t st = 0; - const wchar_t *source; - char *target; - utf8_utf16_t::result result = utf8_utf16_t().out( - st, &d->data[0], &d->data[d->data.size()], source, &s[0], &s[s.size()], target); - - if(result != utf8_utf16_t::ok) { - debug("String::copyFromUTF8() - Unicode conversion error."); - } - -#else - const Unicode::UTF16 *source = &d->data[0]; Unicode::UTF8 *target = reinterpret_cast(&s[0]); @@ -259,8 +227,6 @@ std::string String::to8Bit(bool unicode) const debug("String::to8Bit() - Unicode conversion error."); } -#endif - s.resize(::strlen(s.c_str())); } @@ -413,38 +379,8 @@ ByteVector String::data(Type t) const } case UTF8: { - v.resize(d->data.size() * 4 + 1); - -#ifdef TAGLIB_USE_CODECVT - - std::mbstate_t st = 0; - const wchar_t *source; - char *target; - utf8_utf16_t::result result = utf8_utf16_t().out( - st, &d->data[0], &d->data[d->data.size()], source, v.data(), v.data() + v.size(), target); - - if(result != utf8_utf16_t::ok) { - debug("String::copyFromUTF8() - Unicode conversion error."); - } - -#else - - const Unicode::UTF16 *source = &d->data[0]; - Unicode::UTF8 *target = reinterpret_cast(v.data()); - - Unicode::ConversionResult result = Unicode::ConvertUTF16toUTF8( - &source, source + d->data.size(), - &target, target + v.size(), - Unicode::lenientConversion); - - if(result != Unicode::conversionOK) { - debug("String::to8Bit() - Unicode conversion error."); - } - -#endif - - v.resize(::strlen(v.data()) + 1); - + std::string s = to8Bit(true); + v.setData(s.c_str(), static_cast(s.length())); break; } case UTF16: @@ -794,20 +730,6 @@ void String::copyFromUTF8(const char *s, size_t length) { d->data.resize(length); -#ifdef TAGLIB_USE_CODECVT - - std::mbstate_t st = 0; - const char *source; - wchar_t *target; - utf8_utf16_t::result result = utf8_utf16_t().in( - st, s, s + length, source, &d->data[0], &d->data[d->data.size()], target); - - if(result != utf8_utf16_t::ok) { - debug("String::copyFromUTF8() - Unicode conversion error."); - } - -#else - const Unicode::UTF8 *source = reinterpret_cast(s); Unicode::UTF16 *target = &d->data[0]; @@ -816,13 +738,11 @@ void String::copyFromUTF8(const char *s, size_t length) &target, target + length, Unicode::lenientConversion); + d->data.resize(::wcslen(d->data.c_str())); + if(result != Unicode::conversionOK) { debug("String::copyFromUTF8() - Unicode conversion error."); } - -#endif - - d->data.resize(::wcslen(d->data.c_str())); } void String::copyFromUTF16(const wchar_t *s, size_t length, Type t)