summaryrefslogtreecommitdiff
path: root/i18npool/source/nativenumber/nativenumbersupplier.cxx
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2018-06-12 11:50:05 +0200
committerLászló Németh <nemeth@numbertext.org>2018-06-21 09:20:31 +0200
commit1d48e998ae038263b092e0de71da97fceee299f4 (patch)
treea3b455a2e571b6d15626824dd3e6a8456e339635 /i18npool/source/nativenumber/nativenumbersupplier.cxx
parentb86a8857e6488bac1224a9eed471bcf930994399 (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. Reviewed-on: https://gerrit.libreoffice.org/55681 Tested-by: Jenkins Reviewed-by: Eike Rathke <erack@redhat.com> Conflicts: svl/qa/unit/svl.cxx Change-Id: I5fceb784930e6bc6d376116f5a42ad49cd248a54 Reviewed-on: https://gerrit.libreoffice.org/56202 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'i18npool/source/nativenumber/nativenumbersupplier.cxx')
-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 a18d8c7c798a..5fb34c993167 100644
--- a/i18npool/source/nativenumber/nativenumbersupplier.cxx
+++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx
@@ -600,7 +600,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.
@@ -631,7 +631,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)