summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-03-17 17:01:05 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-04-03 09:20:33 +0200
commita2aaf28bdd01653ea3e35ee6f965257921785b92 (patch)
treeaf485684487ee2de7393e82918d9add81dd5152b /i18npool
parent140f286303118d0436efd51806e63415454424cc (diff)
sw pad-to-3 numbering: add doc model, UNO API and layout
This is similar to the existing padded numbering, but that one padded to 2. Another difference is pad-to-2 has more file format support: pad-to-3 is not supported in DOC and RTF. (cherry picked from commit f4dd9ecdc21696b360dedf7fefa371c8858c1830) Change-Id: Ie2ac2691c58a89e181d24d7002cf873ebab380c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91591 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/qa/cppunit/test_defaultnumberingprovider.cxx29
-rw-r--r--i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx12
2 files changed, 37 insertions, 4 deletions
diff --git a/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
index 2a1cb55502e2..4418a283de2b 100644
--- a/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
+++ b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
@@ -52,6 +52,35 @@ CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest, testArabicZero)
CPPUNIT_ASSERT_EQUAL(OUString("10"), aActual);
}
+CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest, testArabicZero3)
+{
+ uno::Reference<uno::XComponentContext> xComponentContext
+ = comphelper::getComponentContext(getMultiServiceFactory());
+
+ // 10 -> "010"
+ uno::Reference<text::XNumberingFormatter> xFormatter(
+ text::DefaultNumberingProvider::create(xComponentContext), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aProperties = {
+ comphelper::makePropertyValue("NumberingType",
+ static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO3)),
+ comphelper::makePropertyValue("Value", static_cast<sal_Int32>(10)),
+ };
+ lang::Locale aLocale;
+ OUString aActual = xFormatter->makeNumberingString(aProperties, aLocale);
+ // Without the accompanying fix in place, this test would have failed with a
+ // lang.IllegalArgumentException, support for ARABIC_ZERO3 was missing.
+ CPPUNIT_ASSERT_EQUAL(OUString("010"), aActual);
+
+ // 100 -> "100"
+ aProperties = {
+ comphelper::makePropertyValue("NumberingType",
+ static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO3)),
+ comphelper::makePropertyValue("Value", static_cast<sal_Int32>(100)),
+ };
+ aActual = xFormatter->makeNumberingString(aProperties, aLocale);
+ CPPUNIT_ASSERT_EQUAL(OUString("100"), aActual);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
index 3b5cb977d33a..21a0eb8e7d7e 100644
--- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
+++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
@@ -556,11 +556,11 @@ bool should_ignore( const OUString& s )
}
/**
- * Turn nNumber into a string and pad the result to 2 using zero characters.
+ * Turn nNumber into a string and pad the result to nLimit by inserting zero characters at the
+ * start.
*/
-static OUString lcl_formatArabicZero(sal_Int32 nNumber)
+static OUString lcl_formatArabicZero(sal_Int32 nNumber, sal_Int32 nLimit)
{
- sal_Int32 nLimit = 2;
OUString aRet = OUString::number(nNumber);
sal_Int32 nDiff = nLimit - aRet.getLength();
@@ -940,7 +940,11 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal
break;
case ARABIC_ZERO:
- result += lcl_formatArabicZero(number);
+ result += lcl_formatArabicZero(number, 2);
+ break;
+
+ case ARABIC_ZERO3:
+ result += lcl_formatArabicZero(number, 3);
break;
default: