sc/inc/scmatrix.hxx | 6 ++++ sc/source/core/tool/interpr4.cxx | 4 +-- sc/source/core/tool/scmatrix.cxx | 48 ++++++++++++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 12 deletions(-)
New commits: commit 68455c20cb5edf2bfc57243b44fc81b7fa5ea5db Author: Eike Rathke <er...@redhat.com> Date: Wed Jun 15 20:49:31 2016 +0200 set string conversion error also at interpreter if available Change-Id: Idedb9192938a01ecfda3dd93e69c16a896801fd7 diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index 59787d9..7133004 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -77,7 +77,10 @@ double convertStringToValue( ScInterpreter* pErrorInterpreter, const OUString& r short nCurFmtType = 0; double fValue = pErrorInterpreter->ConvertStringToValue( rStr, nError, nCurFmtType); if (nError) + { + pErrorInterpreter->SetError( nError); return formula::CreateDoubleError( nError); + } return fValue; } return formula::CreateDoubleError( formula::errNoValue); commit f219bd4c3599e0933760f8a9f0155fc97a9ab23c Author: Eike Rathke <er...@redhat.com> Date: Wed Jun 15 16:45:32 2016 +0200 Resolves: tdf#100409 GetDoubleWithStringConversion() in GetDoubleFromMatrix() Change-Id: I1e88e9fa6361c6f1f2aebebc101d44bc8e974283 diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index f5138bb..c773f7b 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -1989,14 +1989,14 @@ double ScInterpreter::GetDoubleFromMatrix(const ScMatrixRef& pMat) return 0.0; if ( !pJumpMatrix ) - return pMat->GetDouble( 0 ); + return pMat->GetDoubleWithStringConversion( 0, 0); SCSIZE nCols, nRows, nC, nR; pMat->GetDimensions( nCols, nRows); pJumpMatrix->GetPos( nC, nR); // Use vector replication for single row/column arrays. if ( (nC < nCols || nCols == 1) && (nR < nRows || nRows == 1) ) - return pMat->GetDouble( nC, nR); + return pMat->GetDoubleWithStringConversion( nC, nR); SetError( errNoValue); return 0.0; commit 481b8589d135baced12469bec4ee734b23faac21 Author: Eike Rathke <er...@redhat.com> Date: Wed Jun 15 16:28:44 2016 +0200 introduce ScMatrix::GetDoubleWithStringConversion() preparing for tdf#100409 ... as GetDouble() returns 0.0 for any string and we don't want to change that, most relevant places already check for numeric/text beforehand. Change-Id: Ifbc04e892f6f504040026042faa38674ced880fb diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index aacb9ce..a5c810f 100644 --- a/sc/inc/scmatrix.hxx +++ b/sc/inc/scmatrix.hxx @@ -306,6 +306,8 @@ public: virtual double GetDouble( SCSIZE nC, SCSIZE nR) const = 0; /// @return 0.0 if empty or empty path, else value or DoubleError. virtual double GetDouble( SCSIZE nIndex) const = 0; + /// @return value or DoubleError or string converted to value. + virtual double GetDoubleWithStringConversion( SCSIZE nC, SCSIZE nR ) const = 0; /// @return empty string if empty or empty path, else string content. virtual svl::SharedString GetString( SCSIZE nC, SCSIZE nR) const = 0; @@ -517,6 +519,8 @@ public: virtual double GetDouble( SCSIZE nC, SCSIZE nR) const override; /// @return 0.0 if empty or empty path, else value or DoubleError. virtual double GetDouble( SCSIZE nIndex) const override; + /// @return value or DoubleError or string converted to value. + virtual double GetDoubleWithStringConversion( SCSIZE nC, SCSIZE nR ) const override; /// @return empty string if empty or empty path, else string content. virtual svl::SharedString GetString( SCSIZE nC, SCSIZE nR) const override; @@ -731,6 +735,8 @@ public: virtual double GetDouble(SCSIZE nC, SCSIZE nR) const override; /// @return 0.0 if empty or empty path, else value or DoubleError. virtual double GetDouble(SCSIZE nIndex) const override; + /// @return value or DoubleError or string converted to value. + virtual double GetDoubleWithStringConversion( SCSIZE nC, SCSIZE nR ) const override; /// @return empty string if empty or empty path, else string content. virtual svl::SharedString GetString(SCSIZE nC, SCSIZE nR) const override; diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index a693aba..59787d9 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -69,6 +69,20 @@ typedef mdds::multi_type_matrix<matrix_trait> MatrixImplType; namespace { +double convertStringToValue( ScInterpreter* pErrorInterpreter, const OUString& rStr ) +{ + if (pErrorInterpreter) + { + sal_uInt16 nError = 0; + short nCurFmtType = 0; + double fValue = pErrorInterpreter->ConvertStringToValue( rStr, nError, nCurFmtType); + if (nError) + return formula::CreateDoubleError( nError); + return fValue; + } + return formula::CreateDoubleError( formula::errNoValue); +} + struct ElemEqualZero : public unary_function<double, double> { double operator() (double val) const @@ -244,6 +258,7 @@ public: sal_uInt16 GetError( SCSIZE nC, SCSIZE nR) const; double GetDouble(SCSIZE nC, SCSIZE nR) const; double GetDouble( SCSIZE nIndex) const; + double GetDoubleWithStringConversion(SCSIZE nC, SCSIZE nR) const; svl::SharedString GetString(SCSIZE nC, SCSIZE nR) const; svl::SharedString GetString( SCSIZE nIndex) const; svl::SharedString GetString( SvNumberFormatter& rFormatter, SCSIZE nC, SCSIZE nR) const; @@ -560,6 +575,14 @@ double ScMatrixImpl::GetDouble( SCSIZE nIndex) const return GetDouble(nC, nR); } +double ScMatrixImpl::GetDoubleWithStringConversion(SCSIZE nC, SCSIZE nR) const +{ + ScMatrixValue aMatVal = Get(nC, nR); + if (aMatVal.nType == SC_MATVAL_STRING) + return convertStringToValue( pErrorInterpreter, aMatVal.aStr.getString()); + return aMatVal.fVal; +} + svl::SharedString ScMatrixImpl::GetString(SCSIZE nC, SCSIZE nR) const { if (ValidColRowOrReplicated( nC, nR )) @@ -2734,6 +2757,11 @@ double ScFullMatrix::GetDouble( SCSIZE nIndex) const return pImpl->GetDouble(nIndex); } +double ScFullMatrix::GetDoubleWithStringConversion(SCSIZE nC, SCSIZE nR) const +{ + return pImpl->GetDoubleWithStringConversion(nC, nR); +} + svl::SharedString ScFullMatrix::GetString(SCSIZE nC, SCSIZE nR) const { return pImpl->GetString(nC, nR); @@ -3034,16 +3062,7 @@ public: double operator()(const svl::SharedString& rStr) const { - if (mpErrorInterpreter) - { - sal_uInt16 nError = 0; - short nCurFmtType = 0; - double fValue = mpErrorInterpreter->ConvertStringToValue( rStr.getString(), nError, nCurFmtType); - if (nError) - return formula::CreateDoubleError( nError); - return fValue; - } - return formula::CreateDoubleError( formula::errNoValue); + return convertStringToValue( mpErrorInterpreter, rStr.getString()); } TEmptyRes operator()(char) const @@ -3603,6 +3622,12 @@ double ScVectorRefMatrix::GetDouble(SCSIZE nIndex) const return mpFullMatrix->GetDouble(nIndex); } +double ScVectorRefMatrix::GetDoubleWithStringConversion(SCSIZE nC, SCSIZE nR) const +{ + const_cast<ScVectorRefMatrix*>(this)->ensureFullMatrix(); + return mpFullMatrix->GetDoubleWithStringConversion(nC, nR); +} + svl::SharedString ScVectorRefMatrix::GetString(SCSIZE nC, SCSIZE nR) const { const_cast<ScVectorRefMatrix*>(this)->ensureFullMatrix(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits