[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - svl/qa svl/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Mon Nov 11 13:01:15 UTC 2019


 svl/qa/unit/svl.cxx            |   41 +++++++++++++++++++++++++++++++++++++++++
 svl/source/numbers/zformat.cxx |   34 ++++++++++++++++++++++------------
 2 files changed, 63 insertions(+), 12 deletions(-)

New commits:
commit 1f01cf55897582ace26795f21ec548d3a5906c7c
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Thu Nov 7 21:24:04 2019 +0100
Commit:     Xisco FaulĂ­ <xiscofauli at libreoffice.org>
CommitDate: Mon Nov 11 14:00:21 2019 +0100

    Resolves: tdf#128649 Do not insert duplicate LCID for currency
    
    Fallout from
    
        commit d0f8daa0980ba8e403b32006831657c5a0a4ea17
        CommitDate: Wed Aug 22 19:03:27 2018 +0200
    
            Resolves: tdf#73063 preserve and roundtrip LCID from/to Excel number formats
    
    Change-Id: I356f37624786d753370a272b0f1b54b17b5d206c
    Reviewed-on: https://gerrit.libreoffice.org/82249
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins
    Reviewed-by: Xisco FaulĂ­ <xiscofauli at libreoffice.org>
    Signed-off-by: Xisco Fauli <xiscofauli at libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/82265

diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index cd68d7472427..e936a5a53d2d 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -74,6 +74,7 @@ public:
     void testNfEnglishKeywordsIntegrity();
     void testStandardColorIntegrity();
     void testColorNamesConversion();
+    void testExcelExportFormats();
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testNumberFormat);
@@ -90,6 +91,7 @@ public:
     CPPUNIT_TEST(testNfEnglishKeywordsIntegrity);
     CPPUNIT_TEST(testStandardColorIntegrity);
     CPPUNIT_TEST(testColorNamesConversion);
+    CPPUNIT_TEST(testExcelExportFormats);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1695,6 +1697,45 @@ void Test::testColorNamesConversion()
     }
 }
 
+void Test::testExcelExportFormats()
+{
+    // Create a formatter with "system" locale other than the specific formats'
+    // locale, and different from the en-US export locale.
+    SvNumberFormatter aFormatter( m_xContext, LANGUAGE_ENGLISH_UK);
+
+    OUString aCode;
+    sal_Int32 nCheckPos;
+    SvNumFormatType eType;
+    sal_uInt32 nKey1, nKey2;
+
+    aCode = "00.00";
+    aFormatter.PutandConvertEntry( aCode, nCheckPos, eType, nKey1,
+            LANGUAGE_ENGLISH_US, LANGUAGE_ENGLISH_SAFRICA, false);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("CheckPos should be 0.", sal_Int32(0), nCheckPos);
+    CPPUNIT_ASSERT_MESSAGE("Key should be greater than system locale's keys.",
+            nKey1 > SV_COUNTRY_LANGUAGE_OFFSET);
+
+    aCode = "[$R-1C09] #,##0.0;[$R-1C09]-#,##0.0";
+    aFormatter.PutandConvertEntry( aCode, nCheckPos, eType, nKey2,
+            LANGUAGE_ENGLISH_US, LANGUAGE_ENGLISH_SAFRICA, false);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("CheckPos should be 0.", sal_Int32(0), nCheckPos);
+    CPPUNIT_ASSERT_MESSAGE("Key should be greater than system locale's keys.",
+            nKey2 > SV_COUNTRY_LANGUAGE_OFFSET);
+
+    // The export formatter.
+    SvNumberFormatter aTempFormatter( m_xContext, LANGUAGE_ENGLISH_US);
+    NfKeywordTable aKeywords;
+    aTempFormatter.FillKeywordTableForExcel( aKeywords);
+
+    aCode = aFormatter.GetFormatStringForExcel( nKey1, aKeywords, aTempFormatter);
+    // Test that LCID is prepended.
+    CPPUNIT_ASSERT_EQUAL( OUString("[$-1C09]00.00"), aCode);
+
+    aCode = aFormatter.GetFormatStringForExcel( nKey2, aKeywords, aTempFormatter);
+    // Test that LCID is not prepended. Note that literal characters are escaped.
+    CPPUNIT_ASSERT_EQUAL( OUString("[$R-1C09]\\ #,##0.0;[$R-1C09]\\-#,##0.0"), aCode);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index c90c8479657c..6c5a08f520cc 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -5248,6 +5248,7 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords,
         {
             aStr.append( aPrefix );
         }
+        sal_Int32 nPosHaveLCID = -1;
         sal_Int32 nPosInsertLCID = aStr.getLength();
         sal_uInt32 nCalendarID = 0x0000000; // Excel ID of calendar used in sub-format see tdf#36038
         if ( nCnt )
@@ -5327,6 +5328,10 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords,
                         if ( nCalendarID > 0 )
                             j = j+2;
                         break;
+                    case NF_SYMBOLTYPE_CURREXT :
+                        nPosHaveLCID = aStr.getLength();
+                        aStr.append( rStrArray[j] );
+                        break;
                     default:
                         aStr.append( rStrArray[j] );
                     }
@@ -5437,19 +5442,24 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords,
             if ( aNatNum.GetDBNum() > 0 && nLanguageID == LANGUAGE_SYSTEM )
                 nLanguageID = MsLangId::getRealLanguage( aNatNum.GetLang());
         }
-        else if (!bSystemLanguage && nOriginalLang != LANGUAGE_DONTKNOW)
+        else if (nPosHaveLCID < 0)
         {
-            // Explicit locale, write only to the first subformat.
-            if (n == 0)
-                nLanguageID = MsLangId::getRealLanguage( nOriginalLang);
-        }
-        else if (bSystemLanguage && maLocale.meLanguageWithoutLocaleData != LANGUAGE_DONTKNOW)
-        {
-            // Explicit locale but no locale data thus assigned to system
-            // locale, preserve for roundtrip, write only to the first
-            // subformat.
-            if (n == 0)
-                nLanguageID = maLocale.meLanguageWithoutLocaleData;
+            // Do not insert a duplicated LCID that was already given with a
+            // currency format as [$R-1C09]
+            if (!bSystemLanguage && nOriginalLang != LANGUAGE_DONTKNOW)
+            {
+                // Explicit locale, write only to the first subformat.
+                if (n == 0)
+                    nLanguageID = MsLangId::getRealLanguage( nOriginalLang);
+            }
+            else if (bSystemLanguage && maLocale.meLanguageWithoutLocaleData != LANGUAGE_DONTKNOW)
+            {
+                // Explicit locale but no locale data thus assigned to system
+                // locale, preserve for roundtrip, write only to the first
+                // subformat.
+                if (n == 0)
+                    nLanguageID = maLocale.meLanguageWithoutLocaleData;
+            }
         }
         if ( nCalendarID > 0 )
         {   // Add alphabet and language to calendar


More information about the Libreoffice-commits mailing list