summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/inc/compare.hxx8
-rw-r--r--sc/source/core/inc/interpre.hxx2
-rw-r--r--sc/source/core/tool/compare.cxx22
-rw-r--r--sc/source/core/tool/interpr1.cxx20
-rw-r--r--sc/source/core/tool/scmatrix.cxx2
5 files changed, 34 insertions, 20 deletions
diff --git a/sc/inc/compare.hxx b/sc/inc/compare.hxx
index 5f99ef2db4aa..a4ac35f3c112 100644
--- a/sc/inc/compare.hxx
+++ b/sc/inc/compare.hxx
@@ -63,9 +63,13 @@ private:
};
/** @param pOptions
- NULL means case sensitivity document option is to be used!
+ Used for comparing two strings, if given.
+ NULL means that for comparing two strings ScQueryOp rComp.meOp is
+ tested for SC_EQUAL and SC_NOT_EQUAL, else pOptions->aQueryEntry.eOp
+ Case sensitivity document option is always to be passed in
+ rComp.mbIgnoreCase.
*/
-double CompareFunc( const Compare::Cell& rCell1, const Compare::Cell& rCell2, bool bIgnoreCase, CompareOptions* pOptions = NULL );
+double CompareFunc( const Compare& rComp, CompareOptions* pOptions = NULL );
double CompareFunc( const Compare::Cell& rCell1, double fCell2, CompareOptions* pOptions = NULL );
double CompareFunc( double fCell1, double fCell2 );
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 7ca010a2deb4..f1bceb181f07 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -405,7 +405,7 @@ void ScChoseJump();
// Returns true if last jump was executed and result matrix pushed.
bool JumpMatrix( short nStackLevel );
-double Compare();
+double Compare( ScQueryOp eOp );
/** @param pOptions
NULL means case sensitivity document option is to be used!
*/
diff --git a/sc/source/core/tool/compare.cxx b/sc/source/core/tool/compare.cxx
index 6395f2f31a01..b8836056a6aa 100644
--- a/sc/source/core/tool/compare.cxx
+++ b/sc/source/core/tool/compare.cxx
@@ -43,8 +43,11 @@ CompareOptions::CompareOptions( ScDocument* pDoc, const ScQueryEntry& rEntry, bo
// struct if needed.
}
-double CompareFunc( const Compare::Cell& rCell1, const Compare::Cell& rCell2, bool bIgnoreCase, CompareOptions* pOptions )
+double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
{
+ const Compare::Cell& rCell1 = rComp.maCells[0];
+ const Compare::Cell& rCell2 = rComp.maCells[1];
+
// Keep DoubleError if encountered
// #i40539# if bEmpty is set, bVal/nVal are uninitialized
if (!rCell1.mbEmpty && rCell1.mbValue && !rtl::math::isFinite(rCell1.mfValue))
@@ -134,7 +137,7 @@ double CompareFunc( const Compare::Cell& rCell1, const Compare::Cell& rCell2, bo
sal_Int32 nStart = 0;
sal_Int32 nStop = rCell1.maStr.getLength();
bool bMatch = rEntry.GetSearchTextPtr(
- !bIgnoreCase)->SearchForward(
+ !rComp.mbIgnoreCase)->SearchForward(
rCell1.maStr.getString(), &nStart, &nStop);
if (bMatch && pOptions->bMatchWholeCell && (nStart != 0 || nStop != rCell1.maStr.getLength()))
bMatch = false; // RegEx must match entire string.
@@ -143,12 +146,12 @@ double CompareFunc( const Compare::Cell& rCell1, const Compare::Cell& rCell2, bo
else if (rEntry.eOp == SC_EQUAL || rEntry.eOp == SC_NOT_EQUAL)
{
::utl::TransliterationWrapper* pTransliteration =
- (bIgnoreCase ? ScGlobal::GetpTransliteration() :
+ (rComp.mbIgnoreCase ? ScGlobal::GetpTransliteration() :
ScGlobal::GetCaseTransliteration());
bool bMatch = false;
if (pOptions->bMatchWholeCell)
{
- if (bIgnoreCase)
+ if (rComp.mbIgnoreCase)
bMatch = rCell1.maStr.getDataIgnoreCase() == rCell2.maStr.getDataIgnoreCase();
else
bMatch = rCell1.maStr.getData() == rCell2.maStr.getData();
@@ -165,14 +168,21 @@ double CompareFunc( const Compare::Cell& rCell1, const Compare::Cell& rCell2, bo
}
fRes = (bMatch ? 0 : 1);
}
- else if (bIgnoreCase)
+ else if (rComp.mbIgnoreCase)
fRes = (double) ScGlobal::GetCollator()->compareString(
rCell1.maStr.getString(), rCell2.maStr.getString());
else
fRes = (double) ScGlobal::GetCaseCollator()->compareString(
rCell1.maStr.getString(), rCell2.maStr.getString());
}
- else if (bIgnoreCase)
+ else if (rComp.meOp == SC_EQUAL || rComp.meOp == SC_NOT_EQUAL)
+ {
+ if (rComp.mbIgnoreCase)
+ fRes = (rCell1.maStr.getDataIgnoreCase() == rCell2.maStr.getDataIgnoreCase()) ? 0 : 1;
+ else
+ fRes = (rCell1.maStr.getData() == rCell2.maStr.getData()) ? 0 : 1;
+ }
+ else if (rComp.mbIgnoreCase)
fRes = (double) ScGlobal::GetCollator()->compareString(
rCell1.maStr.getString(), rCell2.maStr.getString());
else
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index fe314bfef995..e86b955f7686 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -794,9 +794,10 @@ bool ScInterpreter::JumpMatrix( short nStackLevel )
return false;
}
-double ScInterpreter::Compare()
+double ScInterpreter::Compare( ScQueryOp eOp )
{
sc::Compare aComp;
+ aComp.meOp = eOp;
aComp.mbIgnoreCase = pDok->GetDocOptions().IsIgnoreCase();
for( short i = 1; i >= 0; i-- )
{
@@ -881,7 +882,7 @@ double ScInterpreter::Compare()
if( nGlobalError )
return 0;
nCurFmtType = nFuncFmtType = NUMBERFORMAT_LOGICAL;
- return sc::CompareFunc(aComp.maCells[0], aComp.maCells[1], aComp.mbIgnoreCase);
+ return sc::CompareFunc(aComp);
}
sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pOptions )
@@ -990,8 +991,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
rCell.mbEmpty = false;
}
}
- aRes.mpMat->PutDouble(
- sc::CompareFunc(aComp.maCells[0], aComp.maCells[1], aComp.mbIgnoreCase, pOptions), j, k);
+ aRes.mpMat->PutDouble( sc::CompareFunc( aComp, pOptions), j, k);
}
else
aRes.mpMat->PutError( errNoValue, j, k);
@@ -1081,7 +1081,7 @@ void ScInterpreter::ScEqual()
PushMatrix(aMat);
}
else
- PushInt( int(Compare() == 0) );
+ PushInt( int(Compare( SC_EQUAL) == 0) );
}
void ScInterpreter::ScNotEqual()
@@ -1098,7 +1098,7 @@ void ScInterpreter::ScNotEqual()
PushMatrix(aMat);
}
else
- PushInt( int(Compare() != 0) );
+ PushInt( int(Compare( SC_NOT_EQUAL) != 0) );
}
void ScInterpreter::ScLess()
@@ -1115,7 +1115,7 @@ void ScInterpreter::ScLess()
PushMatrix(aMat);
}
else
- PushInt( int(Compare() < 0) );
+ PushInt( int(Compare( SC_LESS) < 0) );
}
void ScInterpreter::ScGreater()
@@ -1132,7 +1132,7 @@ void ScInterpreter::ScGreater()
PushMatrix(aMat);
}
else
- PushInt( int(Compare() > 0) );
+ PushInt( int(Compare( SC_GREATER) > 0) );
}
void ScInterpreter::ScLessEqual()
@@ -1149,7 +1149,7 @@ void ScInterpreter::ScLessEqual()
PushMatrix(aMat);
}
else
- PushInt( int(Compare() <= 0) );
+ PushInt( int(Compare( SC_LESS_EQUAL) <= 0) );
}
void ScInterpreter::ScGreaterEqual()
@@ -1166,7 +1166,7 @@ void ScInterpreter::ScGreaterEqual()
PushMatrix(aMat);
}
else
- PushInt( int(Compare() >= 0) );
+ PushInt( int(Compare( SC_GREATER_EQUAL) >= 0) );
}
void ScInterpreter::ScAnd()
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 707337e71275..dbc59ecb3c8e 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -1395,7 +1395,7 @@ class CompareMatrixFunc : std::unary_function<MatrixImplType::element_block_type
void compare()
{
- double fVal = sc::CompareFunc(mrComp.maCells[0], mrComp.maCells[1], mrComp.mbIgnoreCase, mpOptions);
+ double fVal = sc::CompareFunc( mrComp, mpOptions);
maResValues.push_back(evaluate(fVal, mrComp.meOp));
}