Kaydet (Commit) 34bdbdee authored tarafından Eike Rathke's avatar Eike Rathke Kaydeden (comit) Markus Mohrhard

Resolves: tdf#58838 do not use collation for Equal/NotEqual operators

Unicode collation ignores control characters and other specific
characters, see
http://www.unicode.org/charts/collation/chart_Ignored.html
and thus is not suitable to be used for Equal/NotEqual operators.

Change-Id: Ib84713e1da59d92e07bc974d93b6def8217bb067
(cherry picked from commit 1e5e7b93)
Reviewed-on: https://gerrit.libreoffice.org/17240Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst 29be11a5
......@@ -61,9 +61,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 );
......
......@@ -407,7 +407,7 @@ void ScChooseJump();
// 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!
*/
......
......@@ -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
......
......@@ -802,9 +802,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-- )
{
......@@ -889,7 +890,7 @@ double ScInterpreter::Compare()
if( nGlobalError )
return 0;
nCurFmtType = nFuncFmtType = css::util::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 )
......@@ -998,8 +999,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);
......@@ -1089,7 +1089,7 @@ void ScInterpreter::ScEqual()
PushMatrix(aMat);
}
else
PushInt( int(Compare() == 0) );
PushInt( int(Compare( SC_EQUAL) == 0) );
}
void ScInterpreter::ScNotEqual()
......@@ -1106,7 +1106,7 @@ void ScInterpreter::ScNotEqual()
PushMatrix(aMat);
}
else
PushInt( int(Compare() != 0) );
PushInt( int(Compare( SC_NOT_EQUAL) != 0) );
}
void ScInterpreter::ScLess()
......@@ -1123,7 +1123,7 @@ void ScInterpreter::ScLess()
PushMatrix(aMat);
}
else
PushInt( int(Compare() < 0) );
PushInt( int(Compare( SC_LESS) < 0) );
}
void ScInterpreter::ScGreater()
......@@ -1140,7 +1140,7 @@ void ScInterpreter::ScGreater()
PushMatrix(aMat);
}
else
PushInt( int(Compare() > 0) );
PushInt( int(Compare( SC_GREATER) > 0) );
}
void ScInterpreter::ScLessEqual()
......@@ -1157,7 +1157,7 @@ void ScInterpreter::ScLessEqual()
PushMatrix(aMat);
}
else
PushInt( int(Compare() <= 0) );
PushInt( int(Compare( SC_LESS_EQUAL) <= 0) );
}
void ScInterpreter::ScGreaterEqual()
......@@ -1174,7 +1174,7 @@ void ScInterpreter::ScGreaterEqual()
PushMatrix(aMat);
}
else
PushInt( int(Compare() >= 0) );
PushInt( int(Compare( SC_GREATER_EQUAL) >= 0) );
}
void ScInterpreter::ScAnd()
......
......@@ -1380,7 +1380,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));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment