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 14:32:56 +0200 |
commit | 7b5f5d77d56ee494647d9e7868546b3f2140896e (patch) | |
tree | 25a7b50c1393518d3cd73aa70e73bba601c24b0d /i18npool | |
parent | tdf#117843 DOCX import: disable compat increased spacing in header/footer (diff) | |
download | core-7b5f5d77d56ee494647d9e7868546b3f2140896e.tar.gz core-7b5f5d77d56ee494647d9e7868546b3f2140896e.zip |
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>
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 c19f339bc2eb..bc6b74a0aded 100644 --- a/i18npool/source/nativenumber/nativenumbersupplier.cxx +++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx @@ -530,6 +530,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 @@ -539,6 +565,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++) { @@ -548,7 +577,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); @@ -566,7 +599,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 "; |