diff options
author | Eike Rathke <erack@redhat.com> | 2015-07-20 19:13:06 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2015-08-31 13:52:47 +0200 |
commit | faf178d59cf9793e8b9a1b3c4b8afcc96bd72dc6 (patch) | |
tree | 5ad351b5d6b3b3cdf73a125f5c73db8a1a29ac60 /sc/source/core/tool | |
parent | f453458f7e4ec8f8ce85c538f3ac297bd08bf850 (diff) |
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.
(cherry picked from commit 1e5e7b9323c3321a380edf86097ccc2e3f0a7a7a)
Conflicts:
sc/source/core/tool/interpr1.cxx
Change-Id: Ib84713e1da59d92e07bc974d93b6def8217bb067
Reviewed-on: https://gerrit.libreoffice.org/17238
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'sc/source/core/tool')
-rw-r--r-- | sc/source/core/tool/compare.cxx | 22 | ||||
-rw-r--r-- | sc/source/core/tool/interpr1.cxx | 20 | ||||
-rw-r--r-- | sc/source/core/tool/scmatrix.cxx | 2 |
3 files changed, 27 insertions, 17 deletions
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)); } |