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

Eike Rathke erack at redhat.com
Thu Mar 15 16:04:33 UTC 2018


 sc/qa/unit/subsequent_filters-test.cxx |    5 +++--
 svl/source/numbers/zformat.cxx         |    2 ++
 svl/source/numbers/zforscan.cxx        |   20 ++++++++++++++++++++
 svl/source/numbers/zforscan.hxx        |    5 +++++
 4 files changed, 30 insertions(+), 2 deletions(-)

New commits:
commit feb3da3dc53c9b702e39ec12b037b07a67bedcbd
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Mar 2 17:15:47 2018 +0100

    Resolves: tdf#115351 convert boolean equivalent format codes to proper Boolean
    
    Because Excel does not know a Boolean number format, BOOLEAN is
    saved to Excel as
    
    "TRUE";"TRUE";"FALSE"
    
    with implicit conditions [>0] and [<0]. This when loaded has no
    boolean property. Then saved to ODF it is loaded as
    
    [>0]"TRUE";[<0]"TRUE";"FALSE"
    
    with explicit conditions, which has identical meaning.
    
    Convert both equivalent format codes to proper BOOLEAN when
    reading. Locale dependent representations are treated the same,
    e.g. "WAHR";"WAHR";"FALSCH"
    
    Reviewed-on: https://gerrit.libreoffice.org/50642
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit ce4fc2fc08be8ea2773194e303ed42d2579e93a0)
    
    Backported.
    
     Conflicts:
            svl/source/numbers/zforscan.cxx
    
    Change-Id: I49383d71fce972fdd7ad9b19ce3bc150d02aba62
    Reviewed-on: https://gerrit.libreoffice.org/50645
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 1a1ff8fa6452..38e348fe3785 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -441,7 +441,8 @@ void ScFiltersTest::testBooleanFormatXLSX()
     ScDocShellRef xDocSh = loadDoc("check-boolean.", FORMAT_XLSX);
     ScDocument& rDoc = xDocSh->GetDocument();
     SvNumberFormatter* pNumFormatter = rDoc.GetFormatTable();
-    const OUString aBooleanTypeStr = "\"TRUE\";\"TRUE\";\"FALSE\"";
+    // Saved as >"TRUE";"TRUE";"FALSE"< but reading converted back to >BOOLEAN<
+    const OUString aBooleanTypeStr = "BOOLEAN";
 
     CPPUNIT_ASSERT_MESSAGE("Failed to load check-boolean.xlsx", xDocSh.is());
     sal_uInt32 nNumberFormat;
@@ -451,7 +452,7 @@ void ScFiltersTest::testBooleanFormatXLSX()
         rDoc.GetNumberFormat(0, i, 0, nNumberFormat);
         const SvNumberformat* pNumberFormat = pNumFormatter->GetEntry(nNumberFormat);
         const OUString& rFormatStr = pNumberFormat->GetFormatstring();
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format != boolean", rFormatStr, aBooleanTypeStr);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format != boolean", aBooleanTypeStr, rFormatStr);
     }
 
     xDocSh->DoClose();
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index d3e48317f4d0..8614c412bfd5 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -761,6 +761,8 @@ SvNumberformat::SvNumberformat(OUString& rString,
         , bAdditionalBuiltin( false )
         , bStarFlag( false )
 {
+    rScan.ReplaceBooleanEquivalent( rString);
+
     OUStringBuffer sBuff(rString);
 
     // If the group (AKA thousand) separator is a No-Break Space (French)
diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx
index 3687ebc4756b..da88794a40cf 100644
--- a/svl/source/numbers/zforscan.cxx
+++ b/svl/source/numbers/zforscan.cxx
@@ -553,6 +553,16 @@ void ImpSvNumberformatScan::SetDependentKeywords()
     InitSpecialKeyword( NF_KEY_TRUE );
     InitSpecialKeyword( NF_KEY_FALSE );
 
+    // Boolean equivalent format codes that are written to Excel files, may
+    // have been written to ODF as well, specifically if such loaded Excel file
+    // was saved as ODF, and shall result in proper Boolean again.
+    // "TRUE";"TRUE";"FALSE"
+    sBooleanEquivalent1 = "\"" + sKeyword[NF_KEY_TRUE] + "\";\"" +
+        sKeyword[NF_KEY_TRUE] + "\";\"" + sKeyword[NF_KEY_FALSE] + "\"";
+    // [>0]"TRUE";[<0]"TRUE";"FALSE"
+    sBooleanEquivalent2 = "[>0]\"" + sKeyword[NF_KEY_TRUE] + "\";[<0]\"" +
+        sKeyword[NF_KEY_TRUE] + "\";\"" + sKeyword[NF_KEY_FALSE] + "\"";
+
     // compatibility currency strings
     InitCompatCur();
 }
@@ -3302,4 +3312,14 @@ void ImpSvNumberformatScan::CopyInfo(ImpSvNumberformatInfo* pInfo, sal_uInt16 nC
     pInfo->nCntExp      = nCntExp;
 }
 
+void ImpSvNumberformatScan::ReplaceBooleanEquivalent( OUString& rString )
+{
+    InitKeywords();
+    /* TODO: compare case insensitive? Or rather leave as is and case not
+     * matching indicates user supplied on purpose? Written to file / generated
+     * was always uppercase. */
+    if (rString == sBooleanEquivalent1 || rString == sBooleanEquivalent2)
+        rString = GetKeywords()[NF_KEY_BOOLEAN];
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx
index e5eeab899d24..79bc6e7512d1 100644
--- a/svl/source/numbers/zforscan.hxx
+++ b/svl/source/numbers/zforscan.hxx
@@ -143,6 +143,9 @@ public:
             return sCurString;
         }
 
+    /// Replace Boolean equivalent format codes with proper Boolean format.
+    void ReplaceBooleanEquivalent( OUString& rString );
+
     void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
             bool bSystemToSystem = false, bool bForExcelExport = false)
     {
@@ -203,6 +206,8 @@ private: // Private section
     OUString sCurSymbol;                        // Currency symbol for compatibility format codes
     OUString sCurString;                        // Currency symbol in upper case
     OUString sCurAbbrev;                        // Currency abbreviation
+    OUString sBooleanEquivalent1;               // "TRUE";"TRUE";"FALSE"
+    OUString sBooleanEquivalent2;               // [>0]"TRUE";[<0]"TRUE";"FALSE"
     static const OUString sErrStr;              // String for error output
 
     bool bConvertMode;                          // Set in the convert mode


More information about the Libreoffice-commits mailing list