From 41f926e7a8adf92e73a810227e049ec83ab104bf Mon Sep 17 00:00:00 2001 From: László Németh Date: Wed, 17 Jun 2020 21:35:39 +0200 Subject: tdf#133589 Numbertext: fix Hung encoding on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Workaround to fix non-BMP Unicode characters in the case of Hung (Old Hungarian) module, resulted by std::wstring limitation on Windows. Change-Id: I4f6a72ad0e3d4f70ef7e35910bb4147aedb0e4ae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96562 Tested-by: Jenkins Reviewed-by: László Németh --- lingucomponent/source/numbertext/numbertext.cxx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'lingucomponent') diff --git a/lingucomponent/source/numbertext/numbertext.cxx b/lingucomponent/source/numbertext/numbertext.cxx index 70324c7027b2..89f5432624bf 100644 --- a/lingucomponent/source/numbertext/numbertext.cxx +++ b/lingucomponent/source/numbertext/numbertext.cxx @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -132,11 +133,27 @@ OUString SAL_CALL NumberText_Impl::getNumberText(const OUString& rText, const Lo aCode += "-" + aCountry; OString aLangCode(OUStringToOString(aCode, RTL_TEXTENCODING_ASCII_US)); OString aInput(OUStringToOString(rText, RTL_TEXTENCODING_UTF8)); - std::wstring aResult = Numbertext::string2wstring(aInput.getStr()); - bool result = m_aNumberText.numbertext(aResult, aLangCode.getStr()); + std::wstring sResult = Numbertext::string2wstring(aInput.getStr()); + bool result = m_aNumberText.numbertext(sResult, aLangCode.getStr()); DBG_ASSERT(result, "numbertext: false"); - OString aResult2(Numbertext::wstring2string(aResult).c_str()); - return OUString::fromUtf8(aResult2); + OUString aResult = OUString::fromUtf8(Numbertext::wstring2string(sResult).c_str()); +#if defined(_WIN32) + // workaround to fix non-BMP Unicode characters resulted by wstring limitation + if (!aScript.isEmpty() && aScript == "Hung") + { + OUStringBuffer aFix; + for (int i = 0; i < aResult.getLength(); ++i) + { + sal_Unicode c = aResult[i]; + if (0x0C80 <= c && c <= 0x0CFF) + aFix.append(sal_Unicode(0xD803)).append(sal_Unicode(c + 0xD000)); + else + aFix.append(c); + } + aResult = aFix.makeStringAndClear(); + } +#endif + return aResult; } uno::Sequence SAL_CALL NumberText_Impl::getAvailableLanguages() -- cgit