From 52274384a3de2d0a0c9023c62ed9159df965fbd0 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Wed, 13 Dec 2017 21:56:36 +0100 Subject: Move GetKeywords() and related from SvNumberformat to SvNumberFormatter ... as especially the keywords are controlled by the current state (locale) of the ImpSvNumberformatScan instance and *not* a property of SvNumberformat. Add a clarifying descriptive comment as well, and outline it's only for the unit tests anyway.. Change-Id: I732918026bf9ffc25db11033d5f10bc2f51e3505 Reviewed-on: https://gerrit.libreoffice.org/46426 Reviewed-by: Eike Rathke Tested-by: Jenkins --- svl/qa/unit/svl.cxx | 15 ++++++--------- svl/source/numbers/zforlist.cxx | 26 ++++++++++++++++++++++++++ svl/source/numbers/zformat.cxx | 20 -------------------- svl/source/numbers/zforscan.hxx | 4 +++- 4 files changed, 35 insertions(+), 30 deletions(-) (limited to 'svl') diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index defc53df056d..be9310db0af9 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -1393,9 +1393,8 @@ void Test::testUserDefinedNumberFormats() void Test::testNfEnglishKeywordsIntegrity() { SvNumberFormatter aFormatter(m_xContext, LANGUAGE_ENGLISH_US); - const SvNumberformat* pNumberFormat = aFormatter.GetEntry(0); - const NfKeywordTable& sKeywords = pNumberFormat->GetKeywords(); - const ::std::vector & sEnglishKeywords = pNumberFormat->GetEnglishKeywords(); + const ::std::vector & sEnglishKeywords = aFormatter.GetEnglishKeywords(); + const NfKeywordTable& sKeywords = aFormatter.GetKeywords(0); CPPUNIT_ASSERT_EQUAL( size_t(NF_KEYWORD_ENTRIES_COUNT), sEnglishKeywords.size() ); for (size_t i = 0; i < size_t(NF_KEYWORD_ENTRIES_COUNT); ++i) { @@ -1459,9 +1458,8 @@ void Test::testNfEnglishKeywordsIntegrity() void Test::testStandardColorIntegrity() { SvNumberFormatter aFormatter(m_xContext, LANGUAGE_ENGLISH_US); - const SvNumberformat* pNumberFormat = aFormatter.GetEntry(0); - const ::std::vector & aStandardColors = pNumberFormat->GetStandardColor(); - const size_t nMaxDefaultColors = pNumberFormat->GetMaxDefaultColors(); + const ::std::vector & aStandardColors = aFormatter.GetStandardColors(); + const size_t nMaxDefaultColors = aFormatter.GetMaxDefaultColors(); CPPUNIT_ASSERT_EQUAL( nMaxDefaultColors, size_t(NF_KEY_LASTCOLOR) - size_t(NF_KEY_FIRSTCOLOR) + 1 ); CPPUNIT_ASSERT_EQUAL( nMaxDefaultColors, aStandardColors.size() ); // Colors must follow same order as in sEnglishKeyword @@ -1480,9 +1478,8 @@ void Test::testStandardColorIntegrity() void Test::testColorNamesConversion() { SvNumberFormatter aFormatter(m_xContext, LANGUAGE_GERMAN); - const SvNumberformat* pNumberFormat = aFormatter.GetEntry(0); - const ::std::vector & rEnglishKeywords = pNumberFormat->GetEnglishKeywords(); - const NfKeywordTable& rKeywords = pNumberFormat->GetKeywords(); + const ::std::vector & rEnglishKeywords = aFormatter.GetEnglishKeywords(); + const NfKeywordTable& rKeywords = aFormatter.GetKeywords(0); // Holding a reference to the NfKeywordTable doesn't help if we switch // locales internally, so copy the relevant parts in advance. diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index ec99b5caaefc..89c938a9e17a 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -4617,4 +4617,30 @@ sal_uInt16 NfCurrencyEntry::GetEffectiveNegativeFormat( sal_uInt16 nIntlFormat, return nIntlFormat; } +const NfKeywordTable & SvNumberFormatter::GetKeywords( sal_uInt32 nKey ) +{ + osl::MutexGuard aGuard( GetInstanceMutex() ); + const SvNumberformat* pFormat = GetFormatEntry( nKey); + if (pFormat) + ChangeIntl( pFormat->GetLanguage()); + else + ChangeIntl( IniLnge); + return pFormatScanner->GetKeywords(); +} + +const std::vector & SvNumberFormatter::GetEnglishKeywords() const +{ + return ImpSvNumberformatScan::GetEnglishKeywords(); +} + +const std::vector & SvNumberFormatter::GetStandardColors() const +{ + return ImpSvNumberformatScan::GetStandardColors(); +} + +size_t SvNumberFormatter::GetMaxDefaultColors() const +{ + return ImpSvNumberformatScan::GetMaxDefaultColors(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index c4c26e19df3b..d9368ea7ea35 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -5527,24 +5527,4 @@ const SvNumberFormatter& SvNumberformat::GetFormatter() const return *rScan.GetNumberformatter(); } -const NfKeywordTable & SvNumberformat::GetKeywords() const -{ - return rScan.GetKeywords(); -} - -const ::std::vector & SvNumberformat::GetEnglishKeywords() const -{ - return ImpSvNumberformatScan::GetEnglishKeywords(); -} - -const ::std::vector & SvNumberformat::GetStandardColor() const -{ - return ImpSvNumberformatScan::GetStandardColor(); -} - -size_t SvNumberformat::GetMaxDefaultColors() const -{ - return ImpSvNumberformatScan::GetMaxDefaultColors(); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx index 2ed23617b235..6282481c669a 100644 --- a/svl/source/numbers/zforscan.hxx +++ b/svl/source/numbers/zforscan.hxx @@ -73,10 +73,12 @@ public: } return sKeyword; } + static const ::std::vector & GetEnglishKeywords() { return sEnglishKeyword; } + // Keywords used in output like true and false const OUString& GetSpecialKeyword( NfKeywordIndex eIdx ) const { @@ -91,7 +93,7 @@ public: const OUString& GetRedString() const { return GetKeywords()[NF_KEY_RED]; } const OUString& GetBooleanString() const { return GetKeywords()[NF_KEY_BOOLEAN]; } static const OUString& GetErrorString() { return sErrStr; } - static const ::std::vector & GetStandardColor() + static const ::std::vector & GetStandardColors() { return StandardColor; } -- cgit