[Libreoffice-commits] core.git: sc/inc sc/source

Tor Lillqvist tml at collabora.com
Tue Nov 28 07:50:26 UTC 2017


 sc/inc/conditio.hxx              |    5 +
 sc/source/core/data/conditio.cxx |  106 +++++++++++----------------------------
 2 files changed, 35 insertions(+), 76 deletions(-)

New commits:
commit b8ea39bc24850fb958f5f1bb8d46c41a7b7be11e
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Nov 27 15:19:06 2017 +0200

    Factor out a code snippet copy-pasted four times
    
    Change-Id: I29fb16ea51873b396c4f884f6acf454ce2b229e6
    Reviewed-on: https://gerrit.libreoffice.org/45363
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>

diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index dfd8d10bc630..dede939a9185 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -318,6 +318,11 @@ class SC_DLLPUBLIC ScConditionEntry : public ScFormatEntry
     bool                bFirstRun;
     std::unique_ptr<ScFormulaListener> mpListener;
 
+    void    SimplifyCompiledFormula( ScTokenArray*& rFormula,
+                                     double& rVal,
+                                     bool& rIsStr,
+                                     OUString& rStrVal );
+
     void    MakeCells( const ScAddress& rPos );
     void    Compile( const OUString& rExpr1, const OUString& rExpr2,
                         const OUString& rExprNmsp1, const OUString& rExprNmsp2,
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 4bebfb90c1ea..940181582b22 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -309,49 +309,13 @@ ScConditionEntry::ScConditionEntry( ScConditionMode eOper,
     if ( pArr1 )
     {
         pFormula1 = new ScTokenArray( *pArr1 );
-        if ( pFormula1->GetLen() == 1 )
-        {
-            // Single (constant number)?
-            FormulaToken* pToken = pFormula1->FirstToken();
-            if ( pToken->GetOpCode() == ocPush )
-            {
-                if ( pToken->GetType() == svDouble )
-                {
-                    nVal1 = pToken->GetDouble();
-                    DELETEZ(pFormula1);             // Do not remember as formula
-                }
-                else if ( pToken->GetType() == svString )
-                {
-                    bIsStr1 = true;
-                    aStrVal1 = pToken->GetString().getString();
-                    DELETEZ(pFormula1);             // Do not remember as formula
-                }
-            }
-        }
+        SimplifyCompiledFormula( pFormula1, nVal1, bIsStr1, aStrVal1 );
         bRelRef1 = lcl_HasRelRef( mpDoc, pFormula1 );
     }
     if ( pArr2 )
     {
         pFormula2 = new ScTokenArray( *pArr2 );
-        if ( pFormula2->GetLen() == 1 )
-        {
-            // Single (constant number)?
-            FormulaToken* pToken = pFormula2->FirstToken();
-            if ( pToken->GetOpCode() == ocPush )
-            {
-                if ( pToken->GetType() == svDouble )
-                {
-                    nVal2 = pToken->GetDouble();
-                    DELETEZ(pFormula2);             // Do not remember as formula
-                }
-                else if ( pToken->GetType() == svString )
-                {
-                    bIsStr2 = true;
-                    aStrVal2 = pToken->GetString().getString();
-                    DELETEZ(pFormula2);             // Do not remember as formula
-                }
-            }
-        }
+        SimplifyCompiledFormula( pFormula2, nVal2, bIsStr2, aStrVal2 );
         bRelRef2 = lcl_HasRelRef( mpDoc, pFormula2 );
     }
 
@@ -369,6 +333,32 @@ ScConditionEntry::~ScConditionEntry()
     delete pFormula2;
 }
 
+void ScConditionEntry::SimplifyCompiledFormula( ScTokenArray*& rFormula,
+                                                double& rVal,
+                                                bool& rIsStr,
+                                                OUString& rStrVal )
+{
+    if ( rFormula->GetLen() == 1 )
+    {
+        // Single (constant number)?
+        FormulaToken* pToken = rFormula->FirstToken();
+        if ( pToken->GetOpCode() == ocPush )
+        {
+            if ( pToken->GetType() == svDouble )
+            {
+                rVal = pToken->GetDouble();
+                DELETEZ(rFormula);             // Do not remember as formula
+            }
+            else if ( pToken->GetType() == svString )
+            {
+                rIsStr = true;
+                rStrVal = pToken->GetString().getString();
+                DELETEZ(rFormula);             // Do not remember as formula
+            }
+        }
+    }
+}
+
 void ScConditionEntry::SetOperation(ScConditionMode eMode)
 {
     eOp = eMode;
@@ -396,25 +386,7 @@ void ScConditionEntry::Compile( const OUString& rExpr1, const OUString& rExpr2,
             else
             {
                 pFormula1 = aComp.CompileString( rExpr1, rExprNmsp1 );
-                if ( pFormula1->GetLen() == 1 )
-                {
-                    // Single (constant number)?
-                    FormulaToken* pToken = pFormula1->FirstToken();
-                    if ( pToken->GetOpCode() == ocPush )
-                    {
-                        if ( pToken->GetType() == svDouble )
-                        {
-                            nVal1 = pToken->GetDouble();
-                            DELETEZ(pFormula1);             // Do not remember as formula
-                        }
-                        else if ( pToken->GetType() == svString )
-                        {
-                            bIsStr1 = true;
-                            aStrVal1 = pToken->GetString().getString();
-                            DELETEZ(pFormula1);             // Do not remember as formula
-                        }
-                    }
-                }
+                SimplifyCompiledFormula( pFormula1, nVal1, bIsStr1, aStrVal1 );
                 bRelRef1 = lcl_HasRelRef( mpDoc, pFormula1 );
             }
         }
@@ -433,25 +405,7 @@ void ScConditionEntry::Compile( const OUString& rExpr1, const OUString& rExpr2,
             else
             {
                 pFormula2 = aComp.CompileString( rExpr2, rExprNmsp2 );
-                if ( pFormula2->GetLen() == 1 )
-                {
-                    // Sigle (constant number)?
-                    FormulaToken* pToken = pFormula2->FirstToken();
-                    if ( pToken->GetOpCode() == ocPush )
-                    {
-                        if ( pToken->GetType() == svDouble )
-                        {
-                            nVal2 = pToken->GetDouble();
-                            DELETEZ(pFormula2);             // Do not remember as formula
-                        }
-                        else if ( pToken->GetType() == svString )
-                        {
-                            bIsStr2 = true;
-                            aStrVal2 = pToken->GetString().getString();
-                            DELETEZ(pFormula2);             // Do not remember as formula
-                        }
-                    }
-                }
+                SimplifyCompiledFormula( pFormula2, nVal2, bIsStr2, aStrVal2 );
                 bRelRef2 = lcl_HasRelRef( mpDoc, pFormula2 );
             }
         }


More information about the Libreoffice-commits mailing list