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

Eike Rathke erack at redhat.com
Fri Jan 6 17:29:40 UTC 2017


 formula/source/core/api/FormulaCompiler.cxx |    5 ++--
 sc/source/core/data/formulacell.cxx         |    4 +++
 sc/source/filter/xml/xmlcelli.cxx           |   34 +++++++++++++++++++++++-----
 sc/source/filter/xml/xmlimprt.cxx           |    6 ++--
 sc/source/filter/xml/xmlimprt.hxx           |    2 -
 5 files changed, 39 insertions(+), 12 deletions(-)

New commits:
commit 75d963bc7bb87429f304d29138c27178880c039a
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jan 6 18:28:42 2017 +0100

    recognize the broken "Err:xxx" written by 5.2 and earlier, tdf#105024 related
    
    ... and handle same as "#ERRxxx!" if present.
    
    Change-Id: I1ebb31d628b080c52b450a8fe624c20e9e1188b7

diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 3b38ac4..8fd7eda 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1357,11 +1357,22 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
         }
         else
         {
-            OUString aFormulaNmsp = maFormula->second;
-            if( eGrammar != formula::FormulaGrammar::GRAM_EXTERNAL )
-                aFormulaNmsp.clear();
-            pCode->AssignXMLString( aText, aFormulaNmsp );
-            rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() );
+            // 5.2 and earlier wrote broken "Err:xxx" as formula to designate
+            // an error formula cell.
+            if (aText.startsWithIgnoreAsciiCase("Err:") && aText.getLength() <= 9 &&
+                    ((nError =
+                      GetScImport().GetFormulaErrorConstant( "#ERR" + aText.copy(4) + "!")) != FormulaError::NONE))
+            {
+                pCode->SetCodeError(nError);
+            }
+            else
+            {
+                OUString aFormulaNmsp = maFormula->second;
+                if( eGrammar != formula::FormulaGrammar::GRAM_EXTERNAL )
+                    aFormulaNmsp.clear();
+                pCode->AssignXMLString( aText, aFormulaNmsp );
+                rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() );
+            }
         }
 
         ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, pCode, eGrammar, MM_NONE);
commit 4fcbe16959c839bfacf745cfa554b234e639f794
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jan 6 17:46:02 2017 +0100

    read single error constant formula as such, tdf#105024 related
    
    ... without creating a token so when writing again no leading '=' is prepended,
    with which we can enable 5.2 to read such thing correctly, and when re-reading
    in 5.3 it also doesn't lead to a "real" formula.
    
    Change-Id: I26fbd20536436b49b781e2bbb5bba1dc6bafbb37

diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 9398159..9ad3731 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -1282,6 +1282,10 @@ void ScFormulaCell::CompileXML( sc::CompileFormulaContext& rCxt, ScProgress& rPr
         return ;
     }
 
+    // Error constant formula cell stays as is.
+    if (!pCode->GetLen() && pCode->GetCodeError() != FormulaError::NONE)
+        return;
+
     // Compilation changes RPN count, remove and reinsert to FormulaTree if it
     // was in to update its count.
     bool bWasInFormulaTree = pDocument->IsInFormulaTree( this);
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index ddd8543..3b38ac4 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1348,12 +1348,22 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
         // temporary formula string as string tokens
         ScTokenArray *pCode = new ScTokenArray();
 
-        OUString aFormulaNmsp = maFormula->second;
-        if( eGrammar != formula::FormulaGrammar::GRAM_EXTERNAL )
-            aFormulaNmsp.clear();
-        pCode->AssignXMLString( aText, aFormulaNmsp );
+        // Check the special case of a single error constant without leading
+        // '=' and create an error formula cell without tokens.
+        FormulaError nError = GetScImport().GetFormulaErrorConstant(aText);
+        if (nError != FormulaError::NONE)
+        {
+            pCode->SetCodeError(nError);
+        }
+        else
+        {
+            OUString aFormulaNmsp = maFormula->second;
+            if( eGrammar != formula::FormulaGrammar::GRAM_EXTERNAL )
+                aFormulaNmsp.clear();
+            pCode->AssignXMLString( aText, aFormulaNmsp );
+            rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() );
+        }
 
-        rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() );
         ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, pCode, eGrammar, MM_NONE);
         SetFormulaCell(pNewCell);
         rDoc.setFormulaCell(rCellPos, pNewCell);
@@ -1466,7 +1476,8 @@ bool ScXMLTableRowCellContext::IsPossibleErrorString() const
         return false;
     else if(mbNewValueType && mbErrorValue)
         return true;
-    return mbPossibleErrorCell || ( mbCheckWithCompilerForError && GetScImport().IsFormulaErrorConstant(*maStringValue) );
+    return mbPossibleErrorCell || (mbCheckWithCompilerForError &&
+            GetScImport().GetFormulaErrorConstant(*maStringValue) != FormulaError::NONE);
 }
 
 void ScXMLTableRowCellContext::EndElement()
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 6b8e31b..c798e19 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -3393,12 +3393,12 @@ void ScXMLImport::ExtractFormulaNamespaceGrammar(
     reGrammar = eDefaultGrammar;
 }
 
-bool ScXMLImport::IsFormulaErrorConstant( const OUString& rStr ) const
+FormulaError ScXMLImport::GetFormulaErrorConstant( const OUString& rStr ) const
 {
     if (!mpComp)
-        return false;
+        return FormulaError::NONE;
 
-    return mpComp->GetErrorConstant(rStr) > FormulaError::NONE;
+    return mpComp->GetErrorConstant(rStr);
 }
 
 ScEditEngineDefaulter* ScXMLImport::GetEditEngine()
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 317fad7..28f9ae9 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -1223,7 +1223,7 @@ public:
             const OUString& rAttrValue,
             bool bRestrictToExternalNmsp = false ) const;
 
-    bool IsFormulaErrorConstant( const OUString& rStr ) const;
+    FormulaError GetFormulaErrorConstant( const OUString& rStr ) const;
 
     ScEditEngineDefaulter* GetEditEngine();
     const ScXMLEditAttributeMap& GetEditAttributeMap() const;
commit b36bf9f567f5b531f526dad6776c84e06203396f
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jan 6 17:38:39 2017 +0100

    check length of string as this can be called untokenized, tdf#105024 related
    
    i.e. during import of ODFF
    
    Change-Id: I7f5419d393f89d8a84efca7444e8dde3a3e9199f

diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 66c92fb..a271410 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1188,8 +1188,9 @@ FormulaError FormulaCompiler::GetErrorConstant( const OUString& rName ) const
     else
     {
         // Per convention recognize detailed "#ERRxxx!" constants, always
-        // untranslated.
-        if (rName.startsWithIgnoreAsciiCase("#ERR") && rName[rName.getLength()-1] == '!')
+        // untranslated. Error numbers are sal_uInt16 so at most 5 decimal
+        // digits.
+        if (rName.startsWithIgnoreAsciiCase("#ERR") && rName.getLength() <= 10 && rName[rName.getLength()-1] == '!')
         {
             sal_uInt32 nErr = rName.copy( 4, rName.getLength() - 5).toUInt32();
             if (0 < nErr && nErr <= SAL_MAX_UINT16 && isPublishedFormulaError(static_cast<FormulaError>(nErr)))


More information about the Libreoffice-commits mailing list