diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-05-15 14:46:18 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-06-05 17:19:12 +0200 |
commit | 99add140a5e415e392ab909293609dcfd318fd9c (patch) | |
tree | c4812e04c048ff5ca89fa5b70c0896be75cb50d6 /i18npool | |
parent | 400137b1d36e4296e4e297a4c570933e6572b38c (diff) |
NatNum spelling: also spell decimals
Change-Id: I421234e5e74bcdf83d55ed8b0e7a320e37f6a231
Reviewed-on: https://gerrit.libreoffice.org/54375
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
(cherry picked from commit 7b5f5d77d56ee494647d9e7868546b3f2140896e)
Reviewed-on: https://gerrit.libreoffice.org/55332
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/source/nativenumber/nativenumbersupplier.cxx | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx index f075e5324c16..7862edb48f77 100644 --- a/i18npool/source/nativenumber/nativenumbersupplier.cxx +++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx @@ -531,6 +531,32 @@ sal_Int16 getLanguageNumber( const Locale& rLocale) return -1; } +struct Separators +{ + sal_Unicode DecimalSeparator; + sal_Unicode ThousandSeparator; + Separators(const Locale& rLocale) + { + LocaleDataItem aLocaleItem = LocaleDataImpl::get()->getLocaleItem(rLocale); + DecimalSeparator = aLocaleItem.decimalSeparator.toChar(); + ThousandSeparator = aLocaleItem.thousandSeparator.toChar(); + } +}; + +Separators getLocaleSeparators(const Locale& rLocale, const OUString& rLocStr) +{ + // Guard the static variable below. + osl::MutexGuard aGuard(theNatNumMutex::get()); + // Maximum a couple hunderd of pairs with 4-byte structs - so no need for smart managing + static std::unordered_map<OUString, Separators> aLocaleSeparatorsBuf; + auto it = aLocaleSeparatorsBuf.find(rLocStr); + if (it == aLocaleSeparatorsBuf.end()) + { + it = aLocaleSeparatorsBuf.emplace(rLocStr, Separators(rLocale)).first; + } + return it->second; +} + OUString getNumberText(const Locale& aLocale, sal_Int16 numType, const OUString& rNumberString) { assert(numType == NativeNumberMode::NATNUM12 || numType == NativeNumberMode::NATNUM13 @@ -540,6 +566,9 @@ OUString getNumberText(const Locale& aLocale, sal_Int16 numType, const OUString& const sal_Int32 len = rNumberString.getLength(); const sal_Unicode* src = rNumberString.getStr(); + OUString aLoc = LanguageTag::convertToBcp47(aLocale); + Separators aSeparators = getLocaleSeparators(aLocale, aLoc); + OUStringBuffer sBuf(len); for (i = 0; i < len; i++) { @@ -549,7 +578,11 @@ OUString getNumberText(const Locale& aLocale, sal_Int16 numType, const OUString& ++count; sBuf.append(ch); } - else if (isSeparator(ch) && count > 0) + else if (ch == aSeparators.DecimalSeparator) + // Convert any decimal separator to point - in case libnumbertext has a different one + // for this locale (it seems that point is supported for all locales in libnumbertext) + sBuf.append('.'); + else if (ch == aSeparators.ThousandSeparator && count > 0) continue; else if (isMinus(ch) && count == 0) sBuf.append(ch); @@ -567,7 +600,6 @@ OUString getNumberText(const Locale& aLocale, sal_Int16 numType, const OUString& static auto xNumberText = css::linguistic2::NumberText::create(comphelper::getProcessComponentContext()); - OUString aLoc = LanguageTag::convertToBcp47(aLocale); OUString numbertext_prefix; if (numType == NativeNumberMode::NATNUM14) numbertext_prefix = "ordinal-number "; |