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

Eike Rathke erack at redhat.com
Wed Mar 11 18:48:12 PDT 2015


 formula/source/core/api/FormulaCompiler.cxx |   37 +++++++++++++---------
 include/formula/FormulaCompiler.hxx         |    3 +
 sc/inc/compiler.hxx                         |    2 +
 sc/source/core/tool/compiler.cxx            |   46 ++++++++++++++++++++++++----
 4 files changed, 67 insertions(+), 21 deletions(-)

New commits:
commit 1714dd654ee04918c0814fd09cd8522493d804b4
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Mar 12 02:44:42 2015 +0100

    TableRef: parse item specifiers
    
    Change-Id: If1419844544be08fa14b6c78c755abba35fff353

diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index ec99d45..b4b1945 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -381,7 +381,9 @@ public:
 
     // Check if it is a valid english function name
     bool IsEnglishSymbol( const OUString& rName );
+
     bool IsErrorConstant( const OUString& ) const;
+    bool IsTableRefItem( const OUString& ) const;
 
     /**
      * When auto correction is set, the jump command reorder must be enabled.
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index ff06f17..fb999b4 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3282,6 +3282,27 @@ bool ScCompiler::IsErrorConstant( const OUString& rName ) const
         return false;
 }
 
+bool ScCompiler::IsTableRefItem( const OUString& rName ) const
+{
+    OpCodeHashMap::const_iterator iLook( mxSymbols->getHashMap()->find( rName));
+    if (iLook != mxSymbols->getHashMap()->end())
+    {
+        switch ((*iLook).second)
+        {
+            case ocTableRefItemAll:
+            case ocTableRefItemHeaders:
+            case ocTableRefItemData:
+            case ocTableRefItemTotals:
+            case ocTableRefItemThisRow:
+                maRawToken.SetOpCode( (*iLook).second );
+                return true;
+            default:
+                ;
+        }
+    }
+    return false;
+}
+
 void ScCompiler::SetAutoCorrection( bool bVal )
 {
     assert(mbJumpCommandReorder);
@@ -3596,9 +3617,17 @@ bool ScCompiler::NextNewToken( bool bInArray )
             bAsciiUpper = lcl_UpperAsciiOrI18n( aUpper, aOrg, meGrammar);
             if (cSymbol[0] == '#')
             {
+                // Check for TableRef item specifiers first.
+                if (!maTableRefs.empty())
+                {
+                    if (IsTableRefItem( aUpper ))
+                        return true;
+                }
+
                 // This can be only an error constant, if any.
                 if (IsErrorConstant( aUpper))
                     return true;
+
                 break;  // do; create ocBad token or set error.
             }
             if (IsOpCode( aUpper, bInArray ))
commit dbbe0f81e23cfd8139fad1ab94f2817d3bab02e6
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Mar 12 02:18:39 2015 +0100

    speed-up shortcut for non-alnum one character operators and separators
    
    Change-Id: I57281f8e98a7427a562ede1d2dcd9ed4624f33e1

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index f1a0a02..ff06f17 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3564,6 +3564,12 @@ bool ScCompiler::NextNewToken( bool bInArray )
         bMayBeFuncName = ScGlobal::pCharClass->isLetter( aTmpStr, 0 );
         bAsciiNonAlnum = false;
     }
+    if (bAsciiNonAlnum && cSymbol[1] == 0)
+    {
+        // Shortcut for operators and separators that need no further checks or upper.
+        if (IsOpCode( OUString( cSymbol), bInArray ))
+            return true;
+    }
     if ( bMayBeFuncName )
     {
         // a function name must be followed by a parenthesis
commit c6312364b60f65d63b9f99fcbe20c159a486aadb
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Mar 12 01:18:21 2015 +0100

    init and compare opcode hashmap with uppercase symbols
    
    This is necessary now there are TableRef items like #All that need to be
    matched case insensitive but displayed preserving the case as coded /
    translated.
    
    As a side effect, OOXML functions with _xlfn. prefix are now matched in
    case that prefix was uppercase.
    
    Change-Id: Ie14700d13c40c3e39e6d6aff560bcdfe23707196

diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 6af9f36..af4fcfa 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -151,7 +151,7 @@ public:
 
 private:
     bool getOpCodeString( OUString& rStr, sal_uInt16 nOp );
-    void putDefaultOpCode( FormulaCompiler::NonConstOpCodeMapPtr xMap, sal_uInt16 nOp );
+    void putDefaultOpCode( FormulaCompiler::NonConstOpCodeMapPtr xMap, sal_uInt16 nOp, const CharClass* pCharClass );
 
 private:
     FormulaCompiler::SeparatorType meSepType;
@@ -162,11 +162,13 @@ OpCodeList::OpCodeList( sal_uInt16 nRID, FormulaCompiler::NonConstOpCodeMapPtr x
     Resource( ResId( nRID, *ResourceManager::getResManager()))
     , meSepType( eSepType)
 {
+    SvtSysLocale aSysLocale;
+    const CharClass* pCharClass = (xMap->isEnglish() ? NULL : aSysLocale.GetCharClassPtr());
     if (meSepType == FormulaCompiler::RESOURCE_BASE)
     {
         for (sal_uInt16 i = 0; i <= SC_OPCODE_LAST_OPCODE_ID; ++i)
         {
-            putDefaultOpCode( xMap, i);
+            putDefaultOpCode( xMap, i, pCharClass);
         }
     }
     else
@@ -175,9 +177,9 @@ OpCodeList::OpCodeList( sal_uInt16 nRID, FormulaCompiler::NonConstOpCodeMapPtr x
         {
             OUString aOpStr;
             if ( getOpCodeString( aOpStr, i) )
-                xMap->putOpCode( aOpStr, OpCode(i));
+                xMap->putOpCode( aOpStr, OpCode(i), pCharClass);
             else
-                putDefaultOpCode( xMap, i);
+                putDefaultOpCode( xMap, i, pCharClass);
         }
     }
 
@@ -235,12 +237,13 @@ bool OpCodeList::getOpCodeString( OUString& rStr, sal_uInt16 nOp )
     return false;
 }
 
-void OpCodeList::putDefaultOpCode( FormulaCompiler::NonConstOpCodeMapPtr xMap, sal_uInt16 nOp )
+void OpCodeList::putDefaultOpCode( FormulaCompiler::NonConstOpCodeMapPtr xMap, sal_uInt16 nOp,
+        const CharClass* pCharClass )
 {
     ResId aRes( nOp, *ResourceManager::getResManager());
     aRes.SetRT( RSC_STRING);
     if (IsAvailableRes( aRes))
-        xMap->putOpCode( aRes.toString(), OpCode( nOp));
+        xMap->putOpCode( aRes.toString(), OpCode( nOp), pCharClass);
 }
 
 // static
@@ -508,7 +511,7 @@ uno::Sequence< sheet::FormulaOpCodeMapEntry > FormulaCompiler::OpCodeMap::create
 }
 
 
-void FormulaCompiler::OpCodeMap::putOpCode( const OUString & rStr, const OpCode eOp )
+void FormulaCompiler::OpCodeMap::putOpCode( const OUString & rStr, const OpCode eOp, const CharClass* pCharClass )
 {
     DBG_ASSERT( 0 < eOp && sal_uInt16(eOp) < mnSymbols, "OpCodeMap::putOpCode: OpCode out of range");
     if (0 < eOp && sal_uInt16(eOp) < mnSymbols)
@@ -519,8 +522,10 @@ void FormulaCompiler::OpCodeMap::putOpCode( const OUString & rStr, const OpCode
                 "OpCodeMap::putOpCode: reusing OpCode " << static_cast<sal_uInt16>(eOp)
                 << ", replacing '" << mpTable[eOp] << "' with '" << rStr << "' in "
                 << (mbEnglish ? "" : "non-") << "English map 0x" << ::std::hex << meGrammar);
+        // Case preserving opcode -> string, upper string -> opcode
         mpTable[eOp] = rStr;
-        mpHashMap->insert( OpCodeHashMap::value_type( rStr, eOp));
+        OUString aUpper( pCharClass ? pCharClass->uppercase( rStr) : rStr.toAsciiUpperCase());
+        mpHashMap->insert( OpCodeHashMap::value_type( aUpper, eOp));
     }
 }
 
@@ -623,13 +628,15 @@ FormulaCompiler::OpCodeMapPtr FormulaCompiler::CreateOpCodeMap(
     NonConstOpCodeMapPtr xMap( new OpCodeMap( SC_OPCODE_LAST_OPCODE_ID + 1, false,
                 FormulaGrammar::mergeToGrammar( FormulaGrammar::setEnglishBit(
                         FormulaGrammar::GRAM_EXTERNAL, bEnglish), FormulaGrammar::CONV_UNSPECIFIED)));
+    SvtSysLocale aSysLocale;
+    const CharClass* pCharClass = (xMap->isEnglish() ? NULL : aSysLocale.GetCharClassPtr());
     FormulaOpCodeMapEntry const * pArr2 = rMapping.getConstArray();
     FormulaOpCodeMapEntry const * const pStop = pArr2 + rMapping.getLength();
     for ( ; pArr2 < pStop; ++pArr2)
     {
         OpCode eOp = OpCode(pArr2->Token.OpCode);
         if (eOp != ocExternal)
-            xMap->putOpCode( pArr2->Name, eOp);
+            xMap->putOpCode( pArr2->Name, eOp, pCharClass);
         else
         {
             OUString aExternalName;
@@ -722,9 +729,9 @@ void FormulaCompiler::InitSymbolsEnglishXL() const
     // TODO: For now, just replace the separators to the Excel English
     // variants. Later, if we want to properly map Excel functions with Calc
     // functions, we'll need to do a little more work here.
-    mxSymbolsEnglishXL->putOpCode( OUString(','), ocSep);
-    mxSymbolsEnglishXL->putOpCode( OUString(','), ocArrayColSep);
-    mxSymbolsEnglishXL->putOpCode( OUString(';'), ocArrayRowSep);
+    mxSymbolsEnglishXL->putOpCode( OUString(','), ocSep, NULL);
+    mxSymbolsEnglishXL->putOpCode( OUString(','), ocArrayColSep, NULL);
+    mxSymbolsEnglishXL->putOpCode( OUString(';'), ocArrayRowSep, NULL);
 }
 
 void FormulaCompiler::InitSymbolsOOXML() const
@@ -1947,9 +1954,9 @@ void FormulaCompiler::UpdateSeparatorsNative(
 {
     NonConstOpCodeMapPtr xSymbolsNative;
     lcl_fillNativeSymbols( xSymbolsNative);
-    xSymbolsNative->putOpCode( rSep, ocSep);
-    xSymbolsNative->putOpCode( rArrayColSep, ocArrayColSep);
-    xSymbolsNative->putOpCode( rArrayRowSep, ocArrayRowSep);
+    xSymbolsNative->putOpCode( rSep, ocSep, NULL);
+    xSymbolsNative->putOpCode( rArrayColSep, ocArrayColSep, NULL);
+    xSymbolsNative->putOpCode( rArrayRowSep, ocArrayRowSep, NULL);
 }
 
 void FormulaCompiler::ResetNativeSymbols()
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx
index 7f9097b..74d618f 100644
--- a/include/formula/FormulaCompiler.hxx
+++ b/include/formula/FormulaCompiler.hxx
@@ -46,6 +46,7 @@ namespace com { namespace sun { namespace star {
     }
 }}}
 
+class CharClass;
 
 namespace formula
 {
@@ -159,7 +160,7 @@ public:
         inline bool hasExternals() const { return !mpExternalHashMap->empty(); }
 
         /// Put entry of symbol String and OpCode pair.
-        void putOpCode( const OUString & rStr, const OpCode eOp );
+        void putOpCode( const OUString & rStr, const OpCode eOp, const CharClass* pCharClass );
 
         /// Put entry of symbol String and AddIn international String pair.
         void putExternal( const OUString & rSymbol, const OUString & rAddIn );
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index e3d00e5..f1a0a02 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3582,26 +3582,27 @@ bool ScCompiler::NextNewToken( bool bInArray )
     {
         mbRewind = false;
         const OUString aOrg( cSymbol );
+        aUpper.clear();
+        bool bAsciiUpper = false;
 
         if (bAsciiNonAlnum)
         {
+            bAsciiUpper = lcl_UpperAsciiOrI18n( aUpper, aOrg, meGrammar);
             if (cSymbol[0] == '#')
             {
                 // This can be only an error constant, if any.
-                lcl_UpperAsciiOrI18n( aUpper, aOrg, meGrammar);
                 if (IsErrorConstant( aUpper))
                     return true;
                 break;  // do; create ocBad token or set error.
             }
-            if (IsOpCode( aOrg, bInArray ))
+            if (IsOpCode( aUpper, bInArray ))
                 return true;
         }
 
-        aUpper.clear();
-        bool bAsciiUpper = false;
         if (bMayBeFuncName)
         {
-            bAsciiUpper = lcl_UpperAsciiOrI18n( aUpper, aOrg, meGrammar);
+            if (aUpper.isEmpty())
+                bAsciiUpper = lcl_UpperAsciiOrI18n( aUpper, aOrg, meGrammar);
             if (IsOpCode( aUpper, bInArray ))
                 return true;
         }


More information about the Libreoffice-commits mailing list