summaryrefslogtreecommitdiff
path: root/lingucomponent/source
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2020-06-17 21:35:39 +0200
committerLászló Németh <nemeth@numbertext.org>2020-06-18 11:17:08 +0200
commit41f926e7a8adf92e73a810227e049ec83ab104bf (patch)
tree570f4a9aa85a281d931d523da218118c72545a35 /lingucomponent/source
parent241d8e47e708e1912e036f1026f1c43ee1bf84a1 (diff)
tdf#133589 Numbertext: fix Hung encoding on Windows
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 <nemeth@numbertext.org>
Diffstat (limited to 'lingucomponent/source')
-rw-r--r--lingucomponent/source/numbertext/numbertext.cxx25
1 files changed, 21 insertions, 4 deletions
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 <osl/file.hxx>
#include <tools/debug.hxx>
+#include <rtl/ustrbuf.hxx>
#include <sal/config.h>
#include <cppuhelper/factory.hxx>
@@ -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<Locale> SAL_CALL NumberText_Impl::getAvailableLanguages()