[Libreoffice-commits] core.git: i18npool/inc i18npool/source svl/qa
László Németh
nemeth at numbertext.org
Wed Jun 20 18:25:03 UTC 2018
i18npool/inc/defaultnumberingprovider.hxx | 2
i18npool/inc/nativenumbersupplier.hxx | 2
i18npool/source/calendar/calendar_gregorian.cxx | 3
i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx | 21 ---
i18npool/source/nativenumber/nativenumbersupplier.cxx | 60 +++++++++-
svl/qa/unit/svl.cxx | 13 +-
6 files changed, 77 insertions(+), 24 deletions(-)
New commits:
commit 261ff0cdf0e89a80f5d2af7ba5a331bc237a0ceb
Author: László Németh <nemeth at numbertext.org>
Date: Tue Jun 12 11:50:05 2018 +0200
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 at redhat.com>
diff --git a/i18npool/inc/defaultnumberingprovider.hxx b/i18npool/inc/defaultnumberingprovider.hxx
index 97608c122000..1320b7e41a73 100644
--- a/i18npool/inc/defaultnumberingprovider.hxx
+++ b/i18npool/inc/defaultnumberingprovider.hxx
@@ -25,7 +25,6 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/i18n/XTransliteration.hpp>
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
-#include <com/sun/star/i18n/CharacterClassification.hpp>
#include <cppuhelper/implbase.hxx>
#include <rtl/ref.hxx>
@@ -81,7 +80,6 @@ private:
OUString makeNumberingIdentifier( sal_Int16 index );
/// @throws css::uno::RuntimeException
bool isScriptFlagEnabled(const OUString& aName );
- mutable css::uno::Reference< css::i18n::XCharacterClassification > xCharClass;
};
}
diff --git a/i18npool/inc/nativenumbersupplier.hxx b/i18npool/inc/nativenumbersupplier.hxx
index d17c39fe7490..067a590b441a 100644
--- a/i18npool/inc/nativenumbersupplier.hxx
+++ b/i18npool/inc/nativenumbersupplier.hxx
@@ -24,6 +24,7 @@
#include <com/sun/star/i18n/NativeNumberXmlAttributes.hpp>
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/i18n/CharacterClassification.hpp>
namespace i18npool {
@@ -76,6 +77,7 @@ public:
private:
css::lang::Locale aLocale;
bool useOffset;
+ mutable css::uno::Reference< css::i18n::XCharacterClassification > xCharClass;
};
}
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)
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 26b2f6a41588..7f0c54a2547e 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -1394,14 +1394,23 @@ void Test::testUserDefinedNumberFormats()
sCode = "[NatNum12 ordinal-number]0";
sExpected = "123rd";
checkPreviewString(aFormatter, sCode, 123, eLang, sExpected);
+ sCode = "[NatNum12 capitalize]0";
+ sExpected = "One hundred twenty-three";
+ checkPreviewString(aFormatter, sCode, 123, eLang, sExpected);
+ sCode = "[NatNum12 title ordinal]0";
+ sExpected = "One Thousand Two Hundred Thirty-Fourth";
+ checkPreviewString(aFormatter, sCode, 1234, eLang, sExpected);
+ sCode = "[NatNum12 upper ordinal-number]0";
+ sExpected = "12345TH";
+ checkPreviewString(aFormatter, sCode, 12345, eLang, sExpected);
sCode = "[NatNum12 D=ordinal-number]D\" of \"MMMM";
sExpected = "2nd of January";
checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected);
sCode = "[NatNum12 D=ordinal-number,YYYY=year]D\" of \"MMMM\", \"YYYY";
sExpected = "2nd of January, nineteen hundred";
checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected);
- sCode = "[NatNum12 YYYY=year, D=ordinal]D\" of \"MMMM\", \"YYYY";
- sExpected = "second of January, nineteen hundred";
+ sCode = "[NatNum12 YYYY=title year, D=capitalize ordinal]D\" of \"MMMM\", \"YYYY";
+ sExpected = "Second of January, Nineteen Hundred";
checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected);
#endif
}
More information about the Libreoffice-commits
mailing list