From 7a42e8e2ed6306e4e1e8e3167911c5bc3aa41a19 Mon Sep 17 00:00:00 2001 From: cnjinhao Date: Sat, 13 Dec 2014 01:01:13 +0800 Subject: [PATCH] hotfix for 0.9 Fixed a charset issue, wchar_t is string character as encoded in UCS2 in MinGW. --- source/charset.cpp | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/source/charset.cpp b/source/charset.cpp index 6a28b774..f73a5161 100644 --- a/source/charset.cpp +++ b/source/charset.cpp @@ -799,16 +799,31 @@ namespace nana switch(utf_x_) { case unicode::utf8: +#if defined(NANA_MINGW) + strbuf = detail::utf8_to_utf16(data_, true); + detail::put_utf16char(strbuf, 0, true); +#else strbuf = detail::utf8_to_utf32(data_, true); detail::put_utf32char(strbuf, 0, true); +#endif break; case unicode::utf16: +#if defined(NANA_MINGW) + strbuf = data_; + detail::put_utf16char(strbuf, 0, true); +#else strbuf = detail::utf16_to_utf32(data_); detail::put_utf32char(strbuf, 0, true); +#endif break; case unicode::utf32: +#if defined(NANA_MINGW) + strbuf = detail::utf32_to_utf16(data_); + detail::put_utf16char(strbuf, 0, true); +#else strbuf = data_; detail::put_utf32char(strbuf, 0, true); +#endif break; } @@ -892,13 +907,25 @@ namespace nana switch(utf_x_) { case unicode::utf8: +#if defined(NANA_MINGW) + bytes = detail::utf8_to_utf16(data_, true); +#else bytes = detail::utf8_to_utf32(data_, true); +#endif break; case unicode::utf16: +#if defined(NANA_MINGW) + bytes = data_; +#else bytes = detail::utf16_to_utf32(data_); +#endif break; case unicode::utf32: +#if defined(NANA_MINGW) + bytes = detail::utf32_to_utf16(data_); +#else bytes = data_; +#endif break; } return std::wstring(reinterpret_cast(bytes.c_str()), bytes.size() / sizeof(wchar_t)); @@ -957,11 +984,23 @@ namespace nana switch(encoding) { case unicode::utf8: +#if defined(NANA_MINGW) + return detail::utf16_to_utf8(std::string(reinterpret_cast(data_.c_str()), data_.size() * sizeof(wchar_t))); +#else return detail::utf32_to_utf8(std::string(reinterpret_cast(data_.c_str()), data_.size() * sizeof(wchar_t))); +#endif case unicode::utf16: - return detail::utf32_to_utf16(std::string(reinterpret_cast(data_.c_str()), data_.size() * sizeof(wchar_t))); - case unicode::utf32: +#if defined(NANA_MINGW) return std::string(reinterpret_cast(data_.c_str()), data_.size() * sizeof(wchar_t)); +#else + return detail::utf32_to_utf16(std::string(reinterpret_cast(data_.c_str()), data_.size() * sizeof(wchar_t))); +#endif + case unicode::utf32: +#if defined(NANA_MINGW) + return detail::utf16_to_utf32(std::string(reinterpret_cast(data_.c_str()), data_.size() * sizeof(wchar_t))); +#else + return std::string(reinterpret_cast(data_.c_str()), data_.size() * sizeof(wchar_t)); +#endif } return {}; }