summaryrefslogtreecommitdiff
path: root/i18npool/source/nativenumber
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2018-06-12 11:50:05 +0200
committerEike Rathke <erack@redhat.com>2018-06-20 20:24:37 +0200
commit261ff0cdf0e89a80f5d2af7ba5a331bc237a0ceb (patch)
tree00aea88431dc91e8fcf9b5a966ef7ca140bd589a /i18npool/source/nativenumber
parentec36da3788ffc7007dadc568d00f019c0ea831b4 (diff)
NatNum12: fix and add capitalization prefixes, tdf#115007 follow-up
Limit NatNum12 conversion only for the selected parts of the date format (this bug – double calls of getNumberText – was hidden by the space prefix " " and empty return values at the first calls, resulting unchanged dates yet). New prefixes: "capitalize", "upper" and "title" to handle optional capitalization. (In Calc, it was not possible to format the result of NatNum formatting, but some languages often need capitalization or title case to format numbers and currencies.) Thanks code clean up using enum WhichCasing to Eike Rathke. Change-Id: I5fceb784930e6bc6d376116f5a42ad49cd248a54 Reviewed-on: https://gerrit.libreoffice.org/55681 Tested-by: Jenkins Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'i18npool/source/nativenumber')
-rw-r--r--i18npool/source/nativenumber/nativenumbersupplier.cxx60
1 files changed, 58 insertions, 2 deletions
diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx
index b8cc35dcfef4..d9bff101a08c 100644
--- a/i18npool/source/nativenumber/nativenumbersupplier.cxx
+++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx
@@ -597,7 +597,7 @@ OUString getNumberText(const Locale& rLocale, const OUString& rNumberString,
= css::linguistic2::NumberText::create(comphelper::getProcessComponentContext());
OUString numbertext_prefix;
// default "cardinal" gets empty prefix
- if (sNumberTextParams != "cardinal")
+ if (!sNumberTextParams.isEmpty() && sNumberTextParams != "cardinal")
numbertext_prefix = sNumberTextParams + " ";
// Several hundreds of headings could result typing lags because
// of the continuous update of the multiple number names during typing.
@@ -628,7 +628,63 @@ OUString NativeNumberSupplierService::getNativeNumberString(const OUString& aNum
return aNumberString;
if (nNativeNumberMode == NativeNumberMode::NATNUM12)
- return getNumberText(rLocale, aNumberString, rNativeNumberParams);
+ {
+ // handle capitalization prefixes "capitalize", "upper" and "title"
+
+ enum WhichCasing
+ {
+ CAPITALIZE,
+ UPPER,
+ TITLE
+ };
+
+ struct CasingEntry
+ {
+ OUStringLiteral aLiteral;
+ WhichCasing eCasing;
+ };
+
+ static const CasingEntry Casings[] =
+ {
+ { OUStringLiteral("capitalize"), CAPITALIZE },
+ { OUStringLiteral("upper"), UPPER },
+ { OUStringLiteral("title"), TITLE }
+ };
+
+ sal_Int32 nStripCase = 0;
+ size_t nCasing;
+ for (nCasing = 0; nCasing < SAL_N_ELEMENTS(Casings); ++nCasing)
+ {
+ if (rNativeNumberParams.startsWith( Casings[nCasing].aLiteral))
+ {
+ nStripCase = Casings[nCasing].aLiteral.size;
+ break;
+ }
+ }
+
+ if (nStripCase > 0 && (rNativeNumberParams.getLength() == nStripCase ||
+ rNativeNumberParams[nStripCase++] == ' '))
+ {
+ OUString aStr = getNumberText(rLocale, aNumberString, rNativeNumberParams.copy(nStripCase));
+
+ if (!xCharClass.is())
+ xCharClass = CharacterClassification::create(comphelper::getProcessComponentContext());
+
+ switch (Casings[nCasing].eCasing)
+ {
+ case CAPITALIZE:
+ return xCharClass->toTitle(aStr, 0, 1, aLocale) + aStr.copy(1);
+ case UPPER:
+ return xCharClass->toUpper(aStr, 0, aStr.getLength(), aLocale);
+ case TITLE:
+ return xCharClass->toTitle(aStr, 0, aStr.getLength(), aLocale);
+ }
+ }
+ else
+ {
+ return getNumberText(rLocale, aNumberString, rNativeNumberParams);
+ }
+ }
sal_Int16 langnum = getLanguageNumber(rLocale);
if (langnum == -1)