[Libreoffice-commits] core.git: include/svl svl/qa svl/source

Eike Rathke erack at redhat.com
Thu Dec 14 10:15:32 UTC 2017


 include/svl/zforlist.hxx        |   27 +++++++++++++++++++++++++++
 include/svl/zformat.hxx         |    5 -----
 svl/qa/unit/svl.cxx             |   15 ++++++---------
 svl/source/numbers/zforlist.cxx |   26 ++++++++++++++++++++++++++
 svl/source/numbers/zformat.cxx  |   20 --------------------
 svl/source/numbers/zforscan.hxx |    4 +++-
 6 files changed, 62 insertions(+), 35 deletions(-)

New commits:
commit 52274384a3de2d0a0c9023c62ed9159df965fbd0
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Dec 13 21:56:36 2017 +0100

    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 <erack at redhat.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx
index 5ac719d5fe4d..4f27621c9b0f 100644
--- a/include/svl/zforlist.hxx
+++ b/include/svl/zforlist.hxx
@@ -803,6 +803,33 @@ public:
     /** Check if a specific locale has supported locale data. */
     static bool IsLocaleInstalled( LanguageType eLang );
 
+    /** Obtain NfKeywordTable used with a format, possibly localized.
+
+        XXX NOTE: the content (actual keywords) is only valid as long as the
+        locale context of the associated ImpSvNumberformatScan instance does
+        not change to a locale with different keywords, which may happen
+        anytime with a call (implicit or explicit) to
+        SvNumberFormatter::ChangeIntl(). If needed longer, copy-create another
+        NfKeywordTable instance or copy individual elements.
+
+        If the format specified with nKey does not exist, the content of the
+        NfKeywordTable matches the locale with which the SvNumberFormatter
+        instance was created and initialized.
+
+        This function preliminary exists for unit tests and otherwise is
+        pretty much useless.
+     */
+    const NfKeywordTable & GetKeywords( sal_uInt32 nKey );
+
+    /** Access for unit tests. */
+    const std::vector<OUString> & GetEnglishKeywords() const;
+
+    /** Access for unit tests. */
+    const std::vector<Color> & GetStandardColors() const;
+
+    /** Access for unit tests. */
+    size_t GetMaxDefaultColors() const;
+
 private:
     mutable ::osl::Mutex m_aMutex;
     css::uno::Reference< css::uno::XComponentContext > m_xContext;
diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index 9077e45d92ff..2b4813184c9d 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -473,11 +473,6 @@ public:
             return false;
         }
 
-    const NfKeywordTable & GetKeywords() const;
-    const ::std::vector<OUString> & GetEnglishKeywords() const;
-    const ::std::vector<Color> & GetStandardColor() const;
-    size_t GetMaxDefaultColors() const;
-
 private:
     ImpSvNumFor NumFor[4];          // Array for the 4 subformats
     OUString sFormatstring;         // The format code string
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<OUString> & sEnglishKeywords = pNumberFormat->GetEnglishKeywords();
+    const ::std::vector<OUString> & 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<Color> & aStandardColors = pNumberFormat->GetStandardColor();
-    const size_t nMaxDefaultColors = pNumberFormat->GetMaxDefaultColors();
+    const ::std::vector<Color> & 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<OUString> & rEnglishKeywords = pNumberFormat->GetEnglishKeywords();
-    const NfKeywordTable& rKeywords = pNumberFormat->GetKeywords();
+    const ::std::vector<OUString> & 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<OUString> & SvNumberFormatter::GetEnglishKeywords() const
+{
+    return ImpSvNumberformatScan::GetEnglishKeywords();
+}
+
+const std::vector<Color> & 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<OUString> & SvNumberformat::GetEnglishKeywords() const
-{
-    return ImpSvNumberformatScan::GetEnglishKeywords();
-}
-
-const ::std::vector<Color> & 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<OUString> & 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<Color> & GetStandardColor()
+    static const ::std::vector<Color> & GetStandardColors()
         {
             return StandardColor;
         }


More information about the Libreoffice-commits mailing list