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

Winfried Donkers winfrieddonkers at libreoffice.org
Mon Apr 20 09:08:28 PDT 2015


 sc/source/core/inc/interpre.hxx  |    4 +--
 sc/source/core/tool/interpr2.cxx |    2 -
 sc/source/core/tool/interpr3.cxx |   41 ++++++++++++++++++++++++++-------------
 sc/source/core/tool/interpr5.cxx |    6 ++---
 4 files changed, 34 insertions(+), 19 deletions(-)

New commits:
commit 799fd7552f544834ae2d3b77c3ce69e36590b63a
Author: Winfried Donkers <winfrieddonkers at libreoffice.org>
Date:   Thu Mar 12 13:10:24 2015 +0100

    tdf#88547 allow inline date-arrays for Calc array functions
    
    only allow for Calc functions NETWORKDAYS.INTL, WORKDAY.INTL
    for compatibilty with Excel
    
    Change-Id: Ic695fbb0c35fe3cac3857abe2d40fe2d71870e99
    Reviewed-on: https://gerrit.libreoffice.org/14839
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index a76124f..d1d4670 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -816,8 +816,8 @@ void ScMedian();
 double GetMedian( ::std::vector<double> & rArray );
 double GetPercentile( ::std::vector<double> & rArray, double fPercentile );
 double GetPercentileExclusive( ::std::vector<double> & rArray, double fPercentile );
-void GetNumberSequenceArray( sal_uInt8 nParamCount, ::std::vector<double>& rArray );
-void GetSortArray(sal_uInt8 nParamCount, ::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
+void GetNumberSequenceArray( sal_uInt8 nParamCount, ::std::vector<double>& rArray, bool bAllowText );
+void GetSortArray( sal_uInt8 nParamCount, ::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder, bool bAllowText );
 void QuickSort(::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
 void ScModalValue();
 void ScModalValue_Multi();
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 94b227f..8dee4f2 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -254,7 +254,7 @@ sal_uInt16 ScInterpreter::GetWeekendAndHolidayMasks(
     sal_uInt16 nErr = 0;
     if ( nParamCount == 4 )
     {
-        GetSortArray( 1, rSortArray );
+        GetSortArray( 1, rSortArray, NULL, true );
         size_t nMax = rSortArray.size();
         for ( size_t i = 0; i < nMax; i++ )
             rSortArray.at( i ) = ::rtl::math::approxFloor( rSortArray.at( i ) ) + nNullDate;
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 2def402..7b21392 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -3357,7 +3357,7 @@ void ScInterpreter::ScMedian()
     if ( !MustHaveParamCountMin( nParamCount, 1 )  )
         return;
     vector<double> aArray;
-    GetNumberSequenceArray( nParamCount, aArray);
+    GetNumberSequenceArray( nParamCount, aArray, false );
     PushDouble( GetMedian( aArray));
 }
 
@@ -3434,7 +3434,7 @@ void ScInterpreter::ScPercentile( bool bInclusive )
         return;
     }
     vector<double> aArray;
-    GetNumberSequenceArray( 1, aArray);
+    GetNumberSequenceArray( 1, aArray, false );
     if ( bInclusive )
         PushDouble( GetPercentile( aArray, alpha ));
     else
@@ -3452,7 +3452,7 @@ void ScInterpreter::ScQuartile( bool bInclusive )
         return;
     }
     vector<double> aArray;
-    GetNumberSequenceArray( 1, aArray);
+    GetNumberSequenceArray( 1, aArray, false );
     if ( bInclusive )
         PushDouble( fFlag == 2.0 ? GetMedian( aArray ) : GetPercentile( aArray, 0.25 * fFlag ) );
     else
@@ -3465,7 +3465,7 @@ void ScInterpreter::ScModalValue()
     if ( !MustHaveParamCountMin( nParamCount, 1 ) )
         return;
     vector<double> aSortArray;
-    GetSortArray(nParamCount, aSortArray);
+    GetSortArray( nParamCount, aSortArray, NULL, false );
     SCSIZE nSize = aSortArray.size();
     if (aSortArray.empty() || nSize == 0 || nGlobalError)
         PushNoValue();
@@ -3520,7 +3520,7 @@ void ScInterpreter::CalculateSmallLarge(bool bSmall)
      * actually are defined to return an array of values if an array of
      * positions was passed, in which case, depending on the number of values,
      * we may or will need a real sorted array again, see #i32345. */
-    GetNumberSequenceArray(1, aSortArray);
+    GetNumberSequenceArray(1, aSortArray, false );
     SCSIZE nSize = aSortArray.size();
     if (aSortArray.empty() || nSize == 0 || nGlobalError || nSize < k)
         PushNoValue();
@@ -3551,7 +3551,7 @@ void ScInterpreter::ScPercentrank( bool bInclusive )
     double fSignificance = ( nParamCount == 3 ? ::rtl::math::approxFloor( GetDouble() ) : 3.0 );
     double fNum = GetDouble();
     vector<double> aSortArray;
-    GetSortArray( 1, aSortArray );
+    GetSortArray( 1, aSortArray, NULL, false );
     SCSIZE nSize = aSortArray.size();
     if ( aSortArray.empty() || nSize == 0 || nGlobalError )
         PushNoValue();
@@ -3644,7 +3644,7 @@ void ScInterpreter::ScTrimMean()
         return;
     }
     vector<double> aSortArray;
-    GetSortArray(1, aSortArray);
+    GetSortArray( 1, aSortArray, NULL, false );
     SCSIZE nSize = aSortArray.size();
     if (aSortArray.empty() || nSize == 0 || nGlobalError)
         PushNoValue();
@@ -3662,7 +3662,7 @@ void ScInterpreter::ScTrimMean()
     }
 }
 
-void ScInterpreter::GetNumberSequenceArray( sal_uInt8 nParamCount, vector<double>& rArray )
+void ScInterpreter::GetNumberSequenceArray( sal_uInt8 nParamCount, vector<double>& rArray, bool bAllowText )
 {
     ScAddress aAdr;
     ScRange aRange;
@@ -3727,8 +3727,24 @@ void ScInterpreter::GetNumberSequenceArray( sal_uInt8 nParamCount, vector<double
                 else
                 {
                     for (SCSIZE i = 0; i < nCount; ++i)
-                        if (!pMat->IsString(i))
+                    {
+                        if ( pMat->IsValue( i ) )
                             rArray.push_back( pMat->GetDouble(i));
+                        else
+                        {
+                            if ( bAllowText )
+                            {
+                                // tdf 88547 try to convert string to (date)value
+                                OUString aStr = pMat->GetString( i ).getString();
+                                if ( aStr.getLength() > 0 )
+                                {
+                                    double fVal = ConvertStringToValue( aStr );
+                                    if ( !nGlobalError )
+                                        rArray.push_back( fVal );
+                                }
+                            }
+                        }
+                    }
                 }
             }
             break;
@@ -3746,10 +3762,9 @@ void ScInterpreter::GetNumberSequenceArray( sal_uInt8 nParamCount, vector<double
         PopError();
 }
 
-void ScInterpreter::GetSortArray( sal_uInt8 nParamCount, vector<double>& rSortArray, vector<long>* pIndexOrder )
+void ScInterpreter::GetSortArray( sal_uInt8 nParamCount, vector<double>& rSortArray, vector<long>* pIndexOrder, bool bAllowText )
 {
-    GetNumberSequenceArray( nParamCount, rSortArray);
-
+    GetNumberSequenceArray( nParamCount, rSortArray, bAllowText );
     if (rSortArray.size() > MAX_ANZ_DOUBLE_FOR_SORT)
         SetError( errStackOverflow);
     else if (rSortArray.empty())
@@ -3849,7 +3864,7 @@ void ScInterpreter::ScRank( bool bAverage )
         bAscending = false;
 
     vector<double> aSortArray;
-    GetSortArray( 1, aSortArray );
+    GetSortArray( 1, aSortArray, NULL, false );
     double fVal = GetDouble();
     SCSIZE nSize = aSortArray.size();
     if ( aSortArray.empty() || nSize == 0 || nGlobalError )
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 5b472ee..8397a0e 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -834,7 +834,7 @@ void ScInterpreter::ScModalValue_Multi()
     if ( !MustHaveParamCountMin( nParamCount, 1 ) )
         return;
     vector<double> aSortArray;
-    GetSortArray(nParamCount, aSortArray);
+    GetSortArray( nParamCount, aSortArray, NULL, false );
     SCSIZE nSize = aSortArray.size();
     if ( aSortArray.empty() || nSize == 0 || nGlobalError )
         PushNoValue();
@@ -1801,7 +1801,7 @@ void ScInterpreter::ScFrequency()
     vector<double>  aBinArray;
     vector<long>    aBinIndexOrder;
 
-    GetSortArray(1, aBinArray, &aBinIndexOrder);
+    GetSortArray( 1, aBinArray, &aBinIndexOrder, false );
     SCSIZE nBinSize = aBinArray.size();
     if (nGlobalError)
     {
@@ -1810,7 +1810,7 @@ void ScInterpreter::ScFrequency()
     }
 
     vector<double>  aDataArray;
-    GetSortArray(1, aDataArray);
+    GetSortArray( 1, aDataArray, NULL, false );
     SCSIZE nDataSize = aDataArray.size();
 
     if (aDataArray.empty() || nGlobalError)


More information about the Libreoffice-commits mailing list