[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Wed Mar 20 16:18:55 PDT 2013


 sc/inc/stringutil.hxx              |   16 ++++++++++++++++
 sc/source/core/tool/stringutil.cxx |   35 +++++++++++++++++++++++++++++++++++
 sc/source/ui/unoobj/cellsuno.cxx   |   30 +++++++++++++++++++++++-------
 3 files changed, 74 insertions(+), 7 deletions(-)

New commits:
commit a6c949774059858803dd720fb94d0ba887e436af
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 20 19:18:36 2013 -0400

    One less use of PutCell().
    
    Change-Id: I10120476e3bb17c330fa8a59ae51ac7d4573d937

diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index f5bdf3e..e161fc7 100644
--- a/sc/inc/stringutil.hxx
+++ b/sc/inc/stringutil.hxx
@@ -23,6 +23,7 @@
 #include "rtl/ustring.hxx"
 #include "tools/string.hxx"
 #include "scdllapi.h"
+#include "i18npool/lang.h"
 
 class SvNumberFormatter;
 
@@ -96,9 +97,21 @@ struct SC_DLLPUBLIC ScSetStringParam
 
 // ============================================================================
 
+struct ScInputStringType
+{
+    enum StringType { Unknown = 0, Text, Formula, Number };
+
+    StringType meType;
+
+    OUString maText;
+    double mfValue;
+    short mnFormatType;
+};
+
 class ScStringUtil
 {
 public:
+
     /**
      * Check if a given string is a simple decimal number (e.g. 12.345). We
      * don't do any elaborate parsing here; we only check for the simplest
@@ -121,6 +134,9 @@ public:
                                         sal_Unicode cTok,  sal_Int32& rIndex );
 
     static bool SC_DLLPUBLIC isMultiline( const OUString& rStr );
+
+    static ScInputStringType parseInputString(
+        SvNumberFormatter& rFormatter, const OUString& rStr, LanguageType eLang );
 };
 
 
diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 3a997e9..82dfc69 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -21,6 +21,7 @@
 #include "rtl/ustrbuf.hxx"
 #include "rtl/math.hxx"
 #include "global.hxx"
+#include "svl/zforlist.hxx"
 
 ScSetStringParam::ScSetStringParam() :
     mpNumFormatter(NULL),
@@ -333,4 +334,38 @@ bool ScStringUtil::isMultiline( const OUString& rStr )
     return false;
 }
 
+ScInputStringType ScStringUtil::parseInputString(
+    SvNumberFormatter& rFormatter, const OUString& rStr, LanguageType eLang )
+{
+    ScInputStringType aRet;
+    aRet.meType = ScInputStringType::Unknown;
+    aRet.maText = rStr;
+
+    if (rStr.getLength() > 1 && rStr[0] == '=')
+    {
+        aRet.meType = ScInputStringType::Formula;
+    }
+    else if (rStr.getLength() > 1 && rStr[0] == '\'')
+    {
+        //  for bEnglish, "'" at the beginning is always interpreted as text
+        //  marker and stripped
+        aRet.maText = rStr.copy(1);
+        aRet.meType = ScInputStringType::Text;
+    }
+    else        // (nur) auf englisches Zahlformat testen
+    {
+        sal_uInt32 nNumFormat = rFormatter.GetStandardIndex(eLang);
+
+        if (rFormatter.IsNumberFormat(rStr, nNumFormat, aRet.mfValue))
+            aRet.mnFormatType = rFormatter.GetType(nNumFormat);
+        else if (!rStr.isEmpty())
+            aRet.meType = ScInputStringType::Text;
+
+        //  das (englische) Zahlformat wird nicht gesetzt
+        //! passendes lokales Format suchen und setzen???
+    }
+
+    return aRet;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 198bbb7..0e3994c 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -118,6 +118,7 @@
 #include "unoreflist.hxx"
 #include "formula/grammar.hxx"
 #include "editeng/escapementitem.hxx"
+#include "stringutil.hxx"
 
 #include <list>
 #include <boost/scoped_ptr.hpp>
@@ -1282,7 +1283,7 @@ static sal_Bool lcl_PutDataArray( ScDocShell& rDocShell, const ScRange& rRange,
 
 static sal_Bool lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRange,
         const uno::Sequence< uno::Sequence<rtl::OUString> >& aData,
-        const ::rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar )
+        const formula::FormulaGrammar::Grammar eGrammar )
 {
     ScDocument* pDoc = rDocShell.GetDocument();
     SCTAB nTab = rRange.aStart.Tab();
@@ -1320,7 +1321,7 @@ static sal_Bool lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRang
 
     pDoc->DeleteAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, IDF_CONTENTS );
 
-    sal_Bool bError = false;
+    bool bError = false;
     SCROW nDocRow = nStartRow;
     for (long nRow=0; nRow<nRows; nRow++)
     {
@@ -1333,15 +1334,30 @@ static sal_Bool lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRang
             {
                 String aText(pColArr[nCol]);
                 ScAddress aPos( nDocCol, nDocRow, nTab );
-                ScBaseCell* pNewCell = rDocShell.GetDocFunc().InterpretEnglishString(
-                                                aPos, aText, rFormulaNmsp, eGrammar );
-                pDoc->PutCell( aPos, pNewCell );
+
+                ScInputStringType aRes =
+                    ScStringUtil::parseInputString(
+                        *pDoc->GetFormatTable(), aText, LANGUAGE_ENGLISH_US);
+                switch (aRes.meType)
+                {
+                    case ScInputStringType::Formula:
+                        pDoc->SetFormula(aPos, aRes.maText, eGrammar);
+                    break;
+                    case ScInputStringType::Number:
+                        pDoc->SetValue(aPos, aRes.mfValue);
+                    break;
+                    case ScInputStringType::Text:
+                        pDoc->SetTextCell(aPos, aRes.maText);
+                    break;
+                    default:
+                        ;
+                }
 
                 ++nDocCol;
             }
         }
         else
-            bError = sal_True;                          // wrong size
+            bError = true;                          // wrong size
 
         ++nDocRow;
     }
@@ -5370,7 +5386,7 @@ void SAL_CALL ScCellRangeObj::setFormulaArray(
         ScExternalRefManager::ApiGuard aExtRefGuard(pDocSh->GetDocument());
 
         // GRAM_PODF_A1 for API compatibility.
-        bDone = lcl_PutFormulaArray( *pDocSh, aRange, aArray, EMPTY_STRING, formula::FormulaGrammar::GRAM_PODF_A1 );
+        bDone = lcl_PutFormulaArray( *pDocSh, aRange, aArray, formula::FormulaGrammar::GRAM_PODF_A1 );
     }
 
     if (!bDone)


More information about the Libreoffice-commits mailing list