From 481b8589d135baced12469bec4ee734b23faac21 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Wed, 15 Jun 2016 16:28:44 +0200 Subject: 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 --- sc/inc/scmatrix.hxx | 6 ++++++ sc/source/core/tool/scmatrix.cxx | 45 +++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index aacb9cee4f99..a5c810fed308 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 a693aba55d68..59787d979b82 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -69,6 +69,20 @@ typedef mdds::multi_type_matrix 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 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(this)->ensureFullMatrix(); + return mpFullMatrix->GetDoubleWithStringConversion(nC, nR); +} + svl::SharedString ScVectorRefMatrix::GetString(SCSIZE nC, SCSIZE nR) const { const_cast(this)->ensureFullMatrix(); -- cgit v1.2.3