sc/source/core/tool/interpr8.cxx |   79 ++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 45 deletions(-)

New commits:
commit 45f53338461ba61c53c51a04f99fa281bf5150ae
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Wed Oct 20 14:30:34 2021 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Wed Oct 20 18:50:29 2021 +0200

    Related: tdf#145235 TEXTJOIN() allow empty delimiter of referenced empty
    
    Like =TEXTJOIN(B1;0;A1:A2) where B1 is empty, this simply
    concatenates content of A1 and A2 with an empty string delimiter.
    Previously Err:502 expected argument was raised.
    
    Also straighten array/matrix element handling and ensure all paths
    deliver a string value.
    
    Furthermore ScRefCellValue::hasEmptyValue() already includes
    isEmpty() so the extra check is superfluous.
    
    Change-Id: If761aa91df78c6b26fbfd626629e07860636e718
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123897
    Tested-by: Eike Rathke <er...@redhat.com>
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/source/core/tool/interpr8.cxx b/sc/source/core/tool/interpr8.cxx
index 2c2f1c212b3f..fd0762eabc62 100644
--- a/sc/source/core/tool/interpr8.cxx
+++ b/sc/source/core/tool/interpr8.cxx
@@ -1538,14 +1538,13 @@ void ScInterpreter::ScTextJoin_MS()
             if ( nGlobalError != FormulaError::NONE )
                 break;
             ScRefCellValue aCell( mrDoc, aAdr );
-            if ( !aCell.isEmpty() )
+            if (aCell.hasEmptyValue())
+                aDelimiters.emplace_back("");
+            else
             {
-                if ( !aCell.hasEmptyValue() )
-                {
-                    svl::SharedString aSS;
-                    GetCellString( aSS, aCell);
-                    aDelimiters.push_back( aSS.getString());
-                }
+                svl::SharedString aSS;
+                GetCellString( aSS, aCell);
+                aDelimiters.push_back( aSS.getString());
             }
         }
         break;
@@ -1579,17 +1578,14 @@ void ScInterpreter::ScTextJoin_MS()
                     aAdr.SetRow( nRow );
                     aAdr.SetCol( nCol );
                     ScRefCellValue aCell( mrDoc, aAdr );
-                    if ( !aCell.isEmpty() )
+                    if (aCell.hasEmptyValue())
+                        aDelimiters.emplace_back("");
+                    else
                     {
-                        if ( !aCell.hasEmptyValue() )
-                        {
-                            svl::SharedString aSS;
-                            GetCellString( aSS, aCell);
-                            aDelimiters.push_back( aSS.getString());
-                        }
+                        svl::SharedString aSS;
+                        GetCellString( aSS, aCell);
+                        aDelimiters.push_back( aSS.getString());
                     }
-                    else
-                        aDelimiters.emplace_back("" );
                 }
             }
         }
@@ -1611,18 +1607,17 @@ void ScInterpreter::ScTextJoin_MS()
                     {
                         for (SCSIZE j = 0; j < nC; ++j)
                         {
-                            if ( !pMat->IsEmpty( j, k ) )
+                            if (pMat->IsEmpty( j, k ))
+                                aDelimiters.emplace_back("");
+                            else if (pMat->IsStringOrEmpty( j, k ))
+                                aDelimiters.push_back( pMat->GetString( j, k 
).getString() );
+                            else if (pMat->IsValue( j, k ))
+                                aDelimiters.push_back( pMat->GetString( 
*pFormatter, j, k ).getString() );
+                            else
                             {
-                                if ( pMat->IsStringOrEmpty( j, k ) )
-                                    aDelimiters.push_back( pMat->GetString( j, 
k ).getString() );
-                                else
-                                {
-                                    if ( pMat->IsValue( j, k ) )
-                                        aDelimiters.push_back( 
pMat->GetString( *pFormatter, j, k ).getString() );
-                                }
+                                assert(!"should this really happen?");
+                                aDelimiters.emplace_back("");
                             }
-                            else
-                                aDelimiters.emplace_back("" );
                         }
                     }
                 }
@@ -1682,17 +1677,12 @@ void ScInterpreter::ScTextJoin_MS()
                     break;
                 ScRefCellValue aCell( mrDoc, aAdr );
                 OUString aStr;
-                if ( !aCell.isEmpty() )
+                if (!aCell.hasEmptyValue())
                 {
-                    if ( !aCell.hasEmptyValue() )
-                    {
-                        svl::SharedString aSS;
-                        GetCellString( aSS, aCell);
-                        aStr = aSS.getString();
-                    }
+                    svl::SharedString aSS;
+                    GetCellString( aSS, aCell);
+                    aStr = aSS.getString();
                 }
-                else
-                    aStr.clear();
                 if ( !aStr.isEmpty() || !bSkipEmpty )
                 {
                     if ( !bFirst )
@@ -1788,18 +1778,17 @@ void ScInterpreter::ScTextJoin_MS()
                         {
                             for (SCSIZE j = 0; j < nC; ++j)
                             {
-                                if ( !pMat->IsEmpty( j, k ) )
-                                {
-                                    if ( pMat->IsStringOrEmpty( j, k ) )
-                                        aStr = pMat->GetString( j, k 
).getString();
-                                    else
-                                    {
-                                        if ( pMat->IsValue( j, k ) )
-                                            aStr = pMat->GetString( 
*pFormatter, j, k ).getString();
-                                    }
-                                }
+                                if (pMat->IsEmpty( j, k ) )
+                                    aStr.clear();
+                                else if (pMat->IsStringOrEmpty( j, k ))
+                                    aStr = pMat->GetString( j, k ).getString();
+                                else if (pMat->IsValue( j, k ))
+                                    aStr = pMat->GetString( *pFormatter, j, k 
).getString();
                                 else
+                                {
+                                    assert(!"should this really happen?");
                                     aStr.clear();
+                                }
                                 if ( !aStr.isEmpty() || !bSkipEmpty )
                                 {
                                     if ( !bFirst )

Reply via email to