summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-03-03 09:27:01 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-03-03 10:19:26 +0100
commit642b7706101a991efc7e312f59dece640d8bfb60 (patch)
treec31382736ead8bd4dda39170e4a5775477392a51 /i18npool
parentb23183af90996395c19eea5c71c7b2f5640b838b (diff)
sw padded numbering: add layout
lcl_formatArabicZero() looks a bit over-complicated with its hardcoded limit of 2. Word supports limits of 3, 4 and 5 as well, so prepare for handling them in a generic way. Change-Id: If6e5634b11616f0ac05e1387016e22f4b171bbfb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89864 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk44
-rw-r--r--i18npool/Module_i18npool.mk1
-rw-r--r--i18npool/qa/cppunit/test_defaultnumberingprovider.cxx53
-rw-r--r--i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx28
4 files changed, 126 insertions, 0 deletions
diff --git a/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk b/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk
new file mode 100644
index 000000000000..421affb90b35
--- /dev/null
+++ b/i18npool/CppunitTest_i18npool_defaultnumberingprovider.mk
@@ -0,0 +1,44 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,i18npool_defaultnumberingprovider))
+
+$(eval $(call gb_CppunitTest_use_externals,i18npool_defaultnumberingprovider,\
+ boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,i18npool_defaultnumberingprovider, \
+ i18npool/qa/cppunit/test_defaultnumberingprovider \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,i18npool_defaultnumberingprovider, \
+ comphelper \
+ cppu \
+ sal \
+ test \
+ unotest \
+ utl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,i18npool_defaultnumberingprovider))
+
+$(eval $(call gb_CppunitTest_use_ure,i18npool_defaultnumberingprovider))
+$(eval $(call gb_CppunitTest_use_vcl,i18npool_defaultnumberingprovider))
+
+$(eval $(call gb_CppunitTest_use_rdb,i18npool_defaultnumberingprovider,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,i18npool_defaultnumberingprovider,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,i18npool_defaultnumberingprovider))
+
+# vim: set noet sw=4 ts=4:
diff --git a/i18npool/Module_i18npool.mk b/i18npool/Module_i18npool.mk
index 47fd1735f366..271c751081da 100644
--- a/i18npool/Module_i18npool.mk
+++ b/i18npool/Module_i18npool.mk
@@ -43,6 +43,7 @@ $(eval $(call gb_Module_add_check_targets,i18npool,\
CppunitTest_i18npool_test_characterclassification \
CppunitTest_i18npool_test_ordinalsuffix \
CppunitTest_i18npool_test_textsearch \
+ CppunitTest_i18npool_defaultnumberingprovider \
))
# vim: set noet sw=4 ts=4:
diff --git a/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
new file mode 100644
index 000000000000..daa464c9ac74
--- /dev/null
+++ b/i18npool/qa/cppunit/test_defaultnumberingprovider.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+
+#include <com/sun/star/style/NumberingType.hpp>
+#include <com/sun/star/text/DefaultNumberingProvider.hpp>
+#include <com/sun/star/text/XNumberingFormatter.hpp>
+
+#include <comphelper/propertyvalue.hxx>
+
+using namespace ::com::sun::star;
+
+/// i18npool defaultnumberingprovider tests.
+class I18npoolDefaultnumberingproviderTest : public test::BootstrapFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(I18npoolDefaultnumberingproviderTest, testArabicZero)
+{
+ // 1 -> "01"
+ uno::Reference<text::XNumberingFormatter> xFormatter(
+ text::DefaultNumberingProvider::create(mxComponentContext), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aProperties = {
+ comphelper::makePropertyValue("NumberingType",
+ static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO)),
+ comphelper::makePropertyValue("Value", static_cast<sal_Int32>(1)),
+ };
+ 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_ZERO was missing.
+ CPPUNIT_ASSERT_EQUAL(OUString("01"), aActual);
+
+ // 10 -> "10"
+ aProperties = {
+ comphelper::makePropertyValue("NumberingType",
+ static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO)),
+ comphelper::makePropertyValue("Value", static_cast<sal_Int32>(10)),
+ };
+ aActual = xFormatter->makeNumberingString(aProperties, aLocale);
+ CPPUNIT_ASSERT_EQUAL(OUString("10"), 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 7e746bb14d95..54eeaf841850 100644
--- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
+++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
@@ -552,6 +552,30 @@ bool should_ignore( const OUString& s )
return s == " " || (!s.isEmpty() && s[0]==0);
}
+/**
+ * Turn nNumber into a string and pad the result to 2 using zero characters.
+ */
+static OUString lcl_formatArabicZero(sal_Int32 nNumber)
+{
+ sal_Int32 nLimit = 2;
+ OUString aRet = OUString::number(nNumber);
+ sal_Int32 nDiff = nLimit - aRet.getLength();
+
+ if (nDiff <= 0)
+ {
+ return aRet;
+ }
+
+ OUStringBuffer aBuffer;
+ aBuffer.setLength(nDiff);
+ for (sal_Int32 i = 0; i < nDiff; ++i)
+ {
+ aBuffer[i] = '0';
+ }
+ aBuffer.append(aRet);
+ return aBuffer.makeStringAndClear();
+}
+
static
Any getPropertyByName( const Sequence<beans::PropertyValue>& aProperties,
const char* name, bool bRequired )
@@ -913,6 +937,10 @@ DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyVal
lcl_formatChars1( table_Chicago, 4, number-1, result ); // *, +, |, S, **, ++, ...
break;
+ case ARABIC_ZERO:
+ result += lcl_formatArabicZero(number);
+ break;
+
default:
OSL_ASSERT(false);
throw IllegalArgumentException();