formula/source/ui/dlg/FormulaHelper.cxx        |   52 ++++++++++++++++++++++++-
 include/formula/IFunctionDescription.hxx       |    4 +
 include/formula/formulahelper.hxx              |    2 
 reportdesign/source/ui/misc/FunctionHelper.cxx |    4 +
 sc/source/core/data/funcdesc.cxx               |    4 +
 5 files changed, 63 insertions(+), 3 deletions(-)

New commits:
commit 0b683547bbb22cab46e92dfd65c129630bd9ca94
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Fri Jul 26 22:43:47 2024 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Sat Jul 27 00:19:57 2024 +0200

    Related: tdf#159343 Handle TableRef separator in brackets for Function 
Wizard
    
    ... not breaking to next argument of a function parameter.
    
    Change-Id: Ibc7a64c4ea64c415098a213f0ff3d96b8a9dd73c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171085
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/formula/source/ui/dlg/FormulaHelper.cxx 
b/formula/source/ui/dlg/FormulaHelper.cxx
index c2541403ff2a..bf6a142da9f5 100644
--- a/formula/source/ui/dlg/FormulaHelper.cxx
+++ b/formula/source/ui/dlg/FormulaHelper.cxx
@@ -68,6 +68,8 @@ FormulaHelper::FormulaHelper(const IFunctionManager* 
_pFunctionManager)
     ,sep(_pFunctionManager->getSingleToken(IFunctionManager::eSep))
     ,arrayOpen(_pFunctionManager->getSingleToken(IFunctionManager::eArrayOpen))
     
,arrayClose(_pFunctionManager->getSingleToken(IFunctionManager::eArrayClose))
+    
,tableRefOpen(_pFunctionManager->getSingleToken(IFunctionManager::eTableRefOpen))
+    
,tableRefClose(_pFunctionManager->getSingleToken(IFunctionManager::eTableRefClose))
 {
 }
 
@@ -306,14 +308,37 @@ sal_Int32  FormulaHelper::GetFunctionEnd( 
std::u16string_view rStr, sal_Int32 nS
         return nStart;
 
     short   nParCount = 0;
+    short   nTableRefCount = 0;
     bool    bInArray = false;
     bool    bFound = false;
+    bool    bTickEscaped = false;
 
     while ( !bFound && (nStart < nStrLen) )
     {
         sal_Unicode c = rStr[nStart];
 
-        if ( c == '"' )
+        if (nTableRefCount > 0)
+        {
+            // Column names may contain anything, skip. Also skip separator
+            // between item specifier and column name or whatever in a
+            // TableRef [[...]; [...]]
+            // But keep track of apostrophe ' tick escaped brackets.
+            if (c == '\'')
+                bTickEscaped = !bTickEscaped;
+            else
+            {
+                if (c == tableRefOpen && !bTickEscaped)
+                    ++nTableRefCount;
+                else if (c == tableRefClose && !bTickEscaped)
+                    --nTableRefCount;
+                bTickEscaped = false;
+            }
+        }
+        else if (c == tableRefOpen)
+        {
+            ++nTableRefCount;
+        }
+        else if ( c == '"' )
         {
             nStart++;
             while ( (nStart < nStrLen) && rStr[nStart] != '"' )
@@ -365,14 +390,37 @@ sal_Int32 FormulaHelper::GetArgStart( std::u16string_view 
rStr, sal_Int32 nStart
         return nStart;
 
     short   nParCount   = 0;
+    short   nTableRefCount = 0;
     bool    bInArray    = false;
     bool    bFound      = false;
+    bool    bTickEscaped = false;
 
     while ( !bFound && (nStart < nStrLen) )
     {
         sal_Unicode c = rStr[nStart];
 
-        if ( c == '"' )
+        if (nTableRefCount > 0)
+        {
+            // Column names may contain anything, skip. Also skip separator
+            // between item specifier and column name or whatever in a
+            // TableRef [[...]; [...]]
+            // But keep track of apostrophe ' tick escaped brackets.
+            if (c == '\'')
+                bTickEscaped = !bTickEscaped;
+            else
+            {
+                if (c == tableRefOpen && !bTickEscaped)
+                    ++nTableRefCount;
+                else if (c == tableRefClose && !bTickEscaped)
+                    --nTableRefCount;
+                bTickEscaped = false;
+            }
+        }
+        else if (c == tableRefOpen)
+        {
+            ++nTableRefCount;
+        }
+        else if ( c == '"' )
         {
             nStart++;
             while ( (nStart < nStrLen) && rStr[nStart] != '"' )
diff --git a/include/formula/IFunctionDescription.hxx 
b/include/formula/IFunctionDescription.hxx
index 216389451f9d..d511089a274b 100644
--- a/include/formula/IFunctionDescription.hxx
+++ b/include/formula/IFunctionDescription.hxx
@@ -53,7 +53,9 @@ namespace formula
             eClose,
             eSep,
             eArrayOpen,
-            eArrayClose
+            eArrayClose,
+            eTableRefOpen,
+            eTableRefClose
         };
         virtual sal_uInt32 getCount() const = 0;
         virtual const IFunctionCategory* getCategory(sal_uInt32 nPos) const = 
0;
diff --git a/include/formula/formulahelper.hxx 
b/include/formula/formulahelper.hxx
index b298dfa36b07..e584af565ca2 100644
--- a/include/formula/formulahelper.hxx
+++ b/include/formula/formulahelper.hxx
@@ -44,6 +44,8 @@ namespace formula
         const sal_Unicode sep;
         const sal_Unicode arrayOpen;
         const sal_Unicode arrayClose;
+        const sal_Unicode tableRefOpen;
+        const sal_Unicode tableRefClose;
     public:
         FormulaHelper(const IFunctionManager* _pFunctionManager);
 
diff --git a/reportdesign/source/ui/misc/FunctionHelper.cxx 
b/reportdesign/source/ui/misc/FunctionHelper.cxx
index 363242a34457..ec3a2650cb33 100644
--- a/reportdesign/source/ui/misc/FunctionHelper.cxx
+++ b/reportdesign/source/ui/misc/FunctionHelper.cxx
@@ -51,6 +51,10 @@ sal_Unicode FunctionManager::getSingleToken(const 
formula::IFunctionManager::ETo
             return '{';
         case eArrayClose:
             return '}';
+        case eTableRefOpen:
+            return '[';
+        case eTableRefClose:
+            return ']';
     }
     return 0;
 }
diff --git a/sc/source/core/data/funcdesc.cxx b/sc/source/core/data/funcdesc.cxx
index 0231e5af190e..49f0dbfd9eba 100644
--- a/sc/source/core/data/funcdesc.cxx
+++ b/sc/source/core/data/funcdesc.cxx
@@ -1178,6 +1178,10 @@ sal_Unicode ScFunctionMgr::getSingleToken(const 
formula::IFunctionManager::EToke
             return ScCompiler::GetNativeSymbolChar(ocArrayOpen);
         case eArrayClose:
             return ScCompiler::GetNativeSymbolChar(ocArrayClose);
+        case eTableRefOpen:
+            return ScCompiler::GetNativeSymbolChar(ocTableRefOpen);
+        case eTableRefClose:
+            return ScCompiler::GetNativeSymbolChar(ocTableRefClose);
     }
     return 0;
 }

Reply via email to