[Libreoffice-commits] .: 2 commits - sc/qa sc/source

Eike Rathke erack at kemper.freedesktop.org
Wed Jul 18 08:25:53 PDT 2012


 sc/qa/unit/ucalc.cxx             |   15 +++++++++++++++
 sc/source/core/tool/interpr4.cxx |   15 +++++++++++++++
 2 files changed, 30 insertions(+)

New commits:
commit 123fa79cb24dced9adea7ef4d007a4516c1555d4
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Jul 18 17:24:08 2012 +0200

    unit test fdo#50345 accept empty string as scalar numeric 0 argument
    
    Change-Id: Ie04cb8d32e9328212d41fedb63cf81b235aa69de

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index b816f5c..7ea887c 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1042,6 +1042,21 @@ void Test::testFuncParam()
     m_pDoc->GetValue(0, 0, 0, val);
     CPPUNIT_ASSERT_MESSAGE("incorrect result", val == 0.25);
 
+    // Conversion of string to numeric argument.
+    m_pDoc->SetString(0, 0, 0, OUString("=\"\"+3"));    // empty string
+    m_pDoc->SetString(0, 1, 0, OUString("=\" \"+3"));   // only blank
+    m_pDoc->SetString(0, 2, 0, OUString("=\" 4 \"+3")); // number in blanks
+    m_pDoc->SetString(0, 3, 0, OUString("=\" x \"+3")); // non-numeric => #VALUE! error
+    m_pDoc->CalcFormulaTree(false, true);
+    m_pDoc->GetValue(0, 0, 0, val);
+    CPPUNIT_ASSERT_MESSAGE("incorrect result", val == 3);
+    m_pDoc->GetValue(0, 1, 0, val);
+    CPPUNIT_ASSERT_MESSAGE("incorrect result", val == 3);
+    m_pDoc->GetValue(0, 2, 0, val);
+    CPPUNIT_ASSERT_MESSAGE("incorrect result", val == 7);
+    rtl::OUString aVal = m_pDoc->GetString( 0, 3, 0);
+    CPPUNIT_ASSERT_MESSAGE("incorrect result", aVal == "#VALUE!");
+
     m_pDoc->DeleteTab(0);
 }
 
commit a439cb5aba49d01df20f67a2c84b68542e4d3d5a
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Jul 18 17:04:33 2012 +0200

    resolved fdo#50345 accept empty string as scalar numeric 0 argument
    
    For OOo/AOOi interoperability convert an empty string or string
    containing only spaces to numeric 0 for scalar numeric arguments.
    
    Change-Id: I551d10b647c961df08ca8c936ca8fed5de14d99f

diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index bca2977..566d0b3 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -243,6 +243,21 @@ double ScInterpreter::ConvertStringToValue( const String& rStr )
         SetError( mnStringNoValueError);
         return fValue;
     }
+    // The number scanner does not accept empty strings or strings containing
+    // only spaces, be on par in these cases with what was accepted in OOo and
+    // is in AOO (see also the #else branch below) and convert to 0 to prevent
+    // interoperability nightmares.
+    if (!rStr.Len())
+        return fValue;
+    else if (rStr.GetChar(0) == ' ')
+    {
+        const sal_Unicode* p = rStr.GetBuffer() + 1;
+        const sal_Unicode* const pStop = p - 1 + rStr.Len();
+        while (p < pStop && *p == ' ')
+            ++p;
+        if (p == pStop)
+            return fValue;
+    }
     sal_uInt32 nFIndex = 0;
     if (!pFormatter->IsNumberFormat(rStr, nFIndex, fValue))
     {


More information about the Libreoffice-commits mailing list