summaryrefslogtreecommitdiff
path: root/i18npool/source
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
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')
-rw-r--r--i18npool/source/calendar/calendar_gregorian.cxx3
-rw-r--r--i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx21
-rw-r--r--i18npool/source/nativenumber/nativenumbersupplier.cxx60
3 files changed, 64 insertions, 20 deletions
diff --git a/i18npool/source/calendar/calendar_gregorian.cxx b/i18npool/source/calendar/calendar_gregorian.cxx
index 9d8a4c1442d3..a4ac0acfe53d 100644
--- a/i18npool/source/calendar/calendar_gregorian.cxx
+++ b/i18npool/source/calendar/calendar_gregorian.cxx
@@ -935,7 +935,8 @@ Calendar_gregorian::getDisplayStringImpl( sal_Int32 nCalendarDisplayCode, sal_In
}
aOUStr = OUString::createFromAscii(aStr);
}
- if (nNativeNumberMode > 0) {
+ // NatNum12 used only for selected parts
+ if (nNativeNumberMode > 0 && nNativeNumberMode != 12) {
// For Japanese calendar, first year calls GAN, see bug 111668 for detail.
if (eraArray == gengou_eraArray && value == 1
&& (nCalendarDisplayCode == CalendarDisplayCode::SHORT_YEAR ||
diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
index d363407c19fe..99cf26fe60cb 100644
--- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
+++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
@@ -584,7 +584,6 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal
sal_Int16 tableSize = 0;
const sal_Unicode *table = nullptr; // initialize to avoid compiler warning
bool bRecycleSymbol = false;
- bool bCapitalize = false;
OUString sNatNumParams;
Locale locale;
@@ -638,21 +637,18 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal
break;
case TEXT_NUMBER: // ordinal indicators (1st, 2nd, 3rd, ...)
natNum = NativeNumberMode::NATNUM12;
- sNatNumParams = "ordinal-number";
+ sNatNumParams = "capitalize ordinal-number";
locale = aLocale;
- bCapitalize = true;
break;
case TEXT_CARDINAL: // cardinal number names (One, Two, Three, ...)
natNum = NativeNumberMode::NATNUM12;
- sNatNumParams = "cardinal";
+ sNatNumParams = "capitalize";
locale = aLocale;
- bCapitalize = true;
break;
case TEXT_ORDINAL: // ordinal number names (First, Second, Third, ...)
natNum = NativeNumberMode::NATNUM12;
- sNatNumParams = "ordinal";
+ sNatNumParams = "capitalize ordinal";
locale = aLocale;
- bCapitalize = true;
break;
case ROMAN_UPPER:
result += toRoman( number );
@@ -913,17 +909,8 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal
if (natNum) {
rtl::Reference<NativeNumberSupplierService> xNatNum(new NativeNumberSupplierService);
- OUString aNum = xNatNum->getNativeNumberStringParams(OUString::number(number), locale,
+ result += xNatNum->getNativeNumberStringParams(OUString::number(number), locale,
natNum, sNatNumParams);
- if (bCapitalize)
- {
- if (!xCharClass.is())
- xCharClass = CharacterClassification::create(m_xContext);
- // capitalize first letter
- result += xCharClass->toTitle(aNum, 0, 1, aLocale) + aNum.copy(1);
- }
- else
- result += aNum;
} else if (tableSize) {
if ( number > tableSize && !bRecycleSymbol)
result += OUString::number( number);
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)