From ce707fc2d3420be9423bb5e8d0300dbb71a5db6e Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 17 Sep 2021 10:59:51 +0200 Subject: rather return ref from GetCollator since we never return a nullptr. Also add a new utility method to simplify the call sites that need to pick the right collator Change-Id: I5deb009cb5144fd182bbc6470ae30ea05e6979c9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122237 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/inc/global.hxx | 7 +++++-- sc/qa/unit/ucalc.cxx | 3 +-- sc/source/core/data/conditio.cxx | 10 +++++----- sc/source/core/data/dociter.cxx | 14 ++++++-------- sc/source/core/data/dpcache.cxx | 5 ++--- sc/source/core/data/dpitemdata.cxx | 2 +- sc/source/core/data/funcdesc.cxx | 2 +- sc/source/core/data/global.cxx | 12 ++++++++---- sc/source/core/data/table3.cxx | 9 ++++----- sc/source/core/tool/autoform.cxx | 2 +- sc/source/core/tool/compare.cxx | 8 ++++---- sc/source/core/tool/interpr1.cxx | 8 ++++---- sc/source/core/tool/rangelst.cxx | 4 ++-- sc/source/core/tool/rangenam.cxx | 2 +- sc/source/core/tool/typedstrdata.cxx | 8 ++++---- sc/source/filter/excel/xelink.cxx | 2 +- sc/source/ui/miscdlgs/acredlin.cxx | 2 +- sc/source/ui/miscdlgs/solveroptions.cxx | 2 +- sc/source/ui/view/dbfunc3.cxx | 2 +- 19 files changed, 53 insertions(+), 51 deletions(-) (limited to 'sc') diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 6a3eab0d837d..a8b939114201 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -539,8 +539,11 @@ public: SC_DLLPUBLIC static const CharClass& getCharClass(); static CalendarWrapper& GetCalendar(); - SC_DLLPUBLIC static CollatorWrapper* GetCollator(); - static CollatorWrapper* GetCaseCollator(); + /// case-insensitive collator + SC_DLLPUBLIC static CollatorWrapper& GetCollator(); + /// case-sensitive collator + static CollatorWrapper& GetCaseCollator(); + static CollatorWrapper& GetCollator(bool bCaseSensitive); static css::lang::Locale* GetLocale(); SC_DLLPUBLIC static ::utl::TransliterationWrapper* GetpTransliteration(); diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 2655ee68428c..87c5d297002a 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -383,8 +383,7 @@ void Test::tearDown() void Test::testCollator() { - CollatorWrapper* p = ScGlobal::GetCollator(); - sal_Int32 nRes = p->compareString("A", "B"); + sal_Int32 nRes = ScGlobal::GetCollator().compareString("A", "B"); CPPUNIT_ASSERT_MESSAGE("these strings are supposed to be different!", nRes != 0); } diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 0bede8f8b336..008592410a75 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -1138,7 +1138,7 @@ bool ScConditionEntry::IsValidStr( const OUString& rArg, const ScAddress& rPos ) OUString aUpVal2( aStrVal2 ); if ( eOp == ScConditionMode::Between || eOp == ScConditionMode::NotBetween ) - if (ScGlobal::GetCollator()->compareString( aUpVal1, aUpVal2 ) > 0) + if (ScGlobal::GetCollator().compareString( aUpVal1, aUpVal2 ) > 0) { // Right order for value range OUString aTemp( aUpVal1 ); aUpVal1 = aUpVal2; aUpVal2 = aTemp; @@ -1147,11 +1147,11 @@ bool ScConditionEntry::IsValidStr( const OUString& rArg, const ScAddress& rPos ) switch ( eOp ) { case ScConditionMode::Equal: - bValid = (ScGlobal::GetCollator()->compareString( + bValid = (ScGlobal::GetCollator().compareString( rArg, aUpVal1 ) == 0); break; case ScConditionMode::NotEqual: - bValid = (ScGlobal::GetCollator()->compareString( + bValid = (ScGlobal::GetCollator().compareString( rArg, aUpVal1 ) != 0); break; case ScConditionMode::TopPercent: @@ -1181,7 +1181,7 @@ bool ScConditionEntry::IsValidStr( const OUString& rArg, const ScAddress& rPos ) break; default: { - sal_Int32 nCompare = ScGlobal::GetCollator()->compareString( + sal_Int32 nCompare = ScGlobal::GetCollator().compareString( rArg, aUpVal1 ); switch ( eOp ) { @@ -1201,7 +1201,7 @@ bool ScConditionEntry::IsValidStr( const OUString& rArg, const ScAddress& rPos ) case ScConditionMode::NotBetween: // Test for NOTBETWEEN: bValid = ( nCompare < 0 || - ScGlobal::GetCollator()->compareString( rArg, + ScGlobal::GetCollator().compareString( rArg, aUpVal2 ) > 0 ); if ( eOp == ScConditionMode::Between ) bValid = !bValid; diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index 1a0f8b645382..9c6d7773ba6f 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -620,8 +620,7 @@ bool ScDBQueryDataIterator::DataAccessMatrix::isValidQuery(SCROW nRow, const ScM vector aResults; aResults.reserve(nEntryCount); - const CollatorWrapper& rCollator = - mpParam->bCaseSens ? *ScGlobal::GetCaseCollator() : *ScGlobal::GetCollator(); + const CollatorWrapper& rCollator = ScGlobal::GetCollator(mpParam->bCaseSens); for (SCSIZE i = 0; i < nEntryCount; ++i) { @@ -1809,8 +1808,7 @@ bool ScQueryCellIterator::BinarySearch() if (pCol->IsEmptyData()) return false; - CollatorWrapper* pCollator = (maParam.bCaseSens ? ScGlobal::GetCaseCollator() : - ScGlobal::GetCollator()); + CollatorWrapper& rCollator = ScGlobal::GetCollator(maParam.bCaseSens); SvNumberFormatter& rFormatter = *(mrContext.GetFormatTable()); const ScQueryEntry& rEntry = maParam.GetEntry(0); const ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); @@ -1834,7 +1832,7 @@ bool ScQueryCellIterator::BinarySearch() sal_uInt32 nFormat = pCol->GetNumberFormat(mrContext, nRow); OUString aCellStr; ScCellFormat::GetInputString(aCell, nFormat, aCellStr, rFormatter, rDoc); - sal_Int32 nTmp = pCollator->compareString(aCellStr, rEntry.GetQueryItem().maString.getString()); + sal_Int32 nTmp = rCollator.compareString(aCellStr, rEntry.GetQueryItem().maString.getString()); if ((rEntry.eOp == SC_LESS_EQUAL && nTmp > 0) || (rEntry.eOp == SC_GREATER_EQUAL && nTmp < 0) || (rEntry.eOp == SC_EQUAL && nTmp != 0)) @@ -1959,10 +1957,10 @@ bool ScQueryCellIterator::BinarySearch() sal_uInt32 nFormat = pCol->GetNumberFormat(mrContext, aCellData.second); ScCellFormat::GetInputString(aCell, nFormat, aCellStr, rFormatter, rDoc); - nRes = pCollator->compareString(aCellStr, rEntry.GetQueryItem().maString.getString()); + nRes = rCollator.compareString(aCellStr, rEntry.GetQueryItem().maString.getString()); if (nRes < 0 && bLessEqual) { - sal_Int32 nTmp = pCollator->compareString( aLastInRangeString, + sal_Int32 nTmp = rCollator.compareString( aLastInRangeString, aCellStr); if (nTmp < 0) { @@ -1978,7 +1976,7 @@ bool ScQueryCellIterator::BinarySearch() } else if (nRes > 0 && !bLessEqual) { - sal_Int32 nTmp = pCollator->compareString( aLastInRangeString, + sal_Int32 nTmp = rCollator.compareString( aLastInRangeString, aCellStr); if (nTmp > 0) { diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx index 7054fef3ba14..2867c6616fa5 100644 --- a/sc/source/core/data/dpcache.cxx +++ b/sc/source/core/data/dpcache.cxx @@ -694,8 +694,7 @@ bool ScDPCache::ValidQuery( SCROW nRow, const ScQueryParam &rParam) const std::vector aPassed(nEntryCount, false); tools::Long nPos = -1; - CollatorWrapper* pCollator = (rParam.bCaseSens ? ScGlobal::GetCaseCollator() : - ScGlobal::GetCollator() ); + CollatorWrapper& rCollator = ScGlobal::GetCollator(rParam.bCaseSens); ::utl::TransliterationWrapper* pTransliteration = (rParam.bCaseSens ? ScGlobal::GetCaseTransliteration() : ScGlobal::GetpTransliteration()); @@ -823,7 +822,7 @@ bool ScDPCache::ValidQuery( SCROW nRow, const ScQueryParam &rParam) const } else { // use collator here because data was probably sorted - sal_Int32 nCompare = pCollator->compareString( + sal_Int32 nCompare = rCollator.compareString( aCellStr, rEntry.GetQueryItem().maString.getString()); switch (rEntry.eOp) { diff --git a/sc/source/core/data/dpitemdata.cxx b/sc/source/core/data/dpitemdata.cxx index da3293d7c2be..7247d2165541 100644 --- a/sc/source/core/data/dpitemdata.cxx +++ b/sc/source/core/data/dpitemdata.cxx @@ -64,7 +64,7 @@ sal_Int32 ScDPItemData::Compare(const ScDPItemData& rA, const ScDPItemData& rB) // strings may be interned. return 0; - return ScGlobal::GetCollator()->compareString(rA.GetString(), rB.GetString()); + return ScGlobal::GetCollator().compareString(rA.GetString(), rB.GetString()); default: ; } diff --git a/sc/source/core/data/funcdesc.cxx b/sc/source/core/data/funcdesc.cxx index 741b785e0869..51f03a4e4bf4 100644 --- a/sc/source/core/data/funcdesc.cxx +++ b/sc/source/core/data/funcdesc.cxx @@ -392,7 +392,7 @@ bool ScFuncDesc::isParameterOptional(sal_uInt32 _nPos) const bool ScFuncDesc::compareByName(const ScFuncDesc* a, const ScFuncDesc* b) { - return (ScGlobal::GetCaseCollator()->compareString(*a->mxFuncName, *b->mxFuncName ) < 0); + return (ScGlobal::GetCaseCollator().compareString(*a->mxFuncName, *b->mxFuncName ) < 0); } #define ENTRY(CODE) CODE, SAL_N_ELEMENTS(CODE) diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index be6711849c02..6166b3f3ec80 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -1040,9 +1040,9 @@ struct GetMutex { } -CollatorWrapper* ScGlobal::GetCollator() +CollatorWrapper& ScGlobal::GetCollator() { - return comphelper::doubleCheckedInit( pCollator, + return *comphelper::doubleCheckedInit( pCollator, []() { CollatorWrapper* p = new CollatorWrapper( ::comphelper::getProcessComponentContext() ); @@ -1051,9 +1051,9 @@ CollatorWrapper* ScGlobal::GetCollator() }, GetMutex()); } -CollatorWrapper* ScGlobal::GetCaseCollator() +CollatorWrapper& ScGlobal::GetCaseCollator() { - return comphelper::doubleCheckedInit( pCaseCollator, + return *comphelper::doubleCheckedInit( pCaseCollator, []() { CollatorWrapper* p = new CollatorWrapper( ::comphelper::getProcessComponentContext() ); @@ -1062,6 +1062,10 @@ CollatorWrapper* ScGlobal::GetCaseCollator() }, GetMutex()); } +CollatorWrapper& ScGlobal::GetCollator(bool bCaseSensitive) +{ + return bCaseSensitive ? GetCaseCollator() : GetCollator(); +} css::lang::Locale* ScGlobal::GetLocale() { return comphelper::doubleCheckedInit( pLocale, diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 852e4a36f2f0..e90adbeb5c42 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -626,8 +626,8 @@ struct PatternSpan bool ScTable::IsSortCollatorGlobal() const { - return pSortCollator == ScGlobal::GetCollator() || - pSortCollator == ScGlobal::GetCaseCollator(); + return pSortCollator == &ScGlobal::GetCollator() || + pSortCollator == &ScGlobal::GetCaseCollator(); } void ScTable::InitSortCollator( const ScSortParam& rPar ) @@ -642,8 +642,7 @@ void ScTable::InitSortCollator( const ScSortParam& rPar ) else { // SYSTEM DestroySortCollator(); - pSortCollator = (rPar.bCaseSens ? ScGlobal::GetCaseCollator() : - ScGlobal::GetCollator()); + pSortCollator = &ScGlobal::GetCollator(rPar.bCaseSens); } } @@ -2393,7 +2392,7 @@ class QueryEvaluator void setupCollatorIfNeeded() { if (!mpCollator) - mpCollator = mrParam.bCaseSens ? ScGlobal::GetCaseCollator() : ScGlobal::GetCollator(); + mpCollator = &ScGlobal::GetCollator(mrParam.bCaseSens); } public: diff --git a/sc/source/core/tool/autoform.cxx b/sc/source/core/tool/autoform.cxx index 20c18d1b3f93..e4ab89221632 100644 --- a/sc/source/core/tool/autoform.cxx +++ b/sc/source/core/tool/autoform.cxx @@ -750,7 +750,7 @@ bool DefaultFirstEntry::operator() (const OUString& left, const OUString& right) return true; if ( ScGlobal::GetpTransliteration()->isEqual( right, aStrStandard ) ) return false; - return ScGlobal::GetCollator()->compareString( left, right) < 0; + return ScGlobal::GetCollator().compareString( left, right) < 0; } void ScAutoFormat::SetSaveLater( bool bSet ) diff --git a/sc/source/core/tool/compare.cxx b/sc/source/core/tool/compare.cxx index 51491abcfd7f..ac931d2c1982 100644 --- a/sc/source/core/tool/compare.cxx +++ b/sc/source/core/tool/compare.cxx @@ -176,10 +176,10 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions ) fRes = (bMatch ? 0 : 1); } else if (rComp.mbIgnoreCase) - fRes = static_cast(ScGlobal::GetCollator()->compareString( + fRes = static_cast(ScGlobal::GetCollator().compareString( rCell1.maStr.getString(), rCell2.maStr.getString())); else - fRes = static_cast(ScGlobal::GetCaseCollator()->compareString( + fRes = static_cast(ScGlobal::GetCaseCollator().compareString( rCell1.maStr.getString(), rCell2.maStr.getString())); } else if (rComp.meOp == SC_EQUAL || rComp.meOp == SC_NOT_EQUAL) @@ -190,10 +190,10 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions ) fRes = (rCell1.maStr.getData() == rCell2.maStr.getData()) ? 0 : 1; } else if (rComp.mbIgnoreCase) - fRes = static_cast(ScGlobal::GetCollator()->compareString( + fRes = static_cast(ScGlobal::GetCollator().compareString( rCell1.maStr.getString(), rCell2.maStr.getString())); else - fRes = static_cast(ScGlobal::GetCaseCollator()->compareString( + fRes = static_cast(ScGlobal::GetCaseCollator().compareString( rCell1.maStr.getString(), rCell2.maStr.getString())); } diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 8d2d81fe850a..5923116be0d2 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -4722,7 +4722,7 @@ sal_Int32 lcl_CompareMatrix2Query( OUString aStr1 = rMat.GetString(i); OUString aStr2 = rEntry.GetQueryItem().maString.getString(); - return ScGlobal::GetCollator()->compareString(aStr1, aStr2); // case-insensitive + return ScGlobal::GetCollator().compareString(aStr1, aStr2); // case-insensitive } /** returns the last item with the identical value as the original item @@ -6720,7 +6720,7 @@ void ScInterpreter::ScLookup() if (rItem.meType != ScQueryEntry::ByString) bFound = false; else - bFound = (ScGlobal::GetCollator()->compareString(aDataStr.getString(), rItem.maString.getString()) <= 0); + bFound = (ScGlobal::GetCollator().compareString(aDataStr.getString(), rItem.maString.getString()) <= 0); } if (!bFound) @@ -7306,13 +7306,13 @@ void ScInterpreter::CalculateLookup(bool bHLookup) svl::SharedString aParamStr = rItem.maString; if ( bSorted ) { - CollatorWrapper* pCollator = ScGlobal::GetCollator(); + CollatorWrapper& rCollator = ScGlobal::GetCollator(); for (SCSIZE i = 0; i < nMatCount; i++) { if (bHLookup ? pMat->IsStringOrEmpty(i, 0) : pMat->IsStringOrEmpty(0, i)) { sal_Int32 nRes = - pCollator->compareString( + rCollator.compareString( bHLookup ? pMat->GetString(i,0).getString() : pMat->GetString(0,i).getString(), aParamStr.getString()); if (nRes <= 0) nDelta = i; diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx index 8b1059e3b15e..d1b7e598c67e 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -1329,7 +1329,7 @@ public: { mrDoc.GetName( rStartPos1.Tab(), aStr1 ); mrDoc.GetName( rStartPos2.Tab(), aStr2 ); - nComp = ScGlobal::GetCollator()->compareString( aStr1, aStr2 ); + nComp = ScGlobal::GetCollator().compareString( aStr1, aStr2 ); } if (nComp < 0) { @@ -1360,7 +1360,7 @@ public: { mrDoc.GetName( rEndPos1.Tab(), aStr1 ); mrDoc.GetName( rEndPos2.Tab(), aStr2 ); - nComp = ScGlobal::GetCollator()->compareString( aStr1, aStr2 ); + nComp = ScGlobal::GetCollator().compareString( aStr1, aStr2 ); } if (nComp < 0) { diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index debd75c30d44..e554597ce819 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -626,7 +626,7 @@ void ScRangeData::InitCode() extern "C" int ScRangeData_QsortNameCompare( const void* p1, const void* p2 ) { - return static_cast(ScGlobal::GetCollator()->compareString( + return static_cast(ScGlobal::GetCollator().compareString( (*static_cast(p1))->GetName(), (*static_cast(p2))->GetName() )); } diff --git a/sc/source/core/tool/typedstrdata.cxx b/sc/source/core/tool/typedstrdata.cxx index 59831dac7271..83ecdfa64053 100644 --- a/sc/source/core/tool/typedstrdata.cxx +++ b/sc/source/core/tool/typedstrdata.cxx @@ -23,7 +23,7 @@ bool ScTypedStrData::LessCaseSensitive::operator() (const ScTypedStrData& left, if (left.mbIsDate != right.mbIsDate) return left.mbIsDate < right.mbIsDate; - return ScGlobal::GetCaseCollator()->compareString( + return ScGlobal::GetCaseCollator().compareString( left.maStrValue, right.maStrValue) < 0; } @@ -38,7 +38,7 @@ bool ScTypedStrData::LessCaseInsensitive::operator() (const ScTypedStrData& left if (left.mbIsDate != right.mbIsDate) return left.mbIsDate < right.mbIsDate; - return ScGlobal::GetCollator()->compareString( + return ScGlobal::GetCollator().compareString( left.maStrValue, right.maStrValue) < 0; } @@ -53,7 +53,7 @@ bool ScTypedStrData::EqualCaseSensitive::operator() (const ScTypedStrData& left, if (left.mbIsDate != right.mbIsDate ) return false; - return ScGlobal::GetCaseCollator()->compareString( + return ScGlobal::GetCaseCollator().compareString( left.maStrValue, right.maStrValue) == 0; } @@ -68,7 +68,7 @@ bool ScTypedStrData::EqualCaseInsensitive::operator() (const ScTypedStrData& lef if (left.mbIsDate != right.mbIsDate ) return false; - return ScGlobal::GetCollator()->compareString( + return ScGlobal::GetCollator().compareString( left.maStrValue, right.maStrValue) == 0; } diff --git a/sc/source/filter/excel/xelink.cxx b/sc/source/filter/excel/xelink.cxx index ef922401f3c0..4e30a29e9867 100644 --- a/sc/source/filter/excel/xelink.cxx +++ b/sc/source/filter/excel/xelink.cxx @@ -879,7 +879,7 @@ struct XclExpTabNameSort { bool operator ()( const XclExpTabName& rArg1, const XclExpTabName& rArg2 ) { // compare the sheet names only - return ScGlobal::GetCollator()->compareString( rArg1.first, rArg2.first ) < 0; + return ScGlobal::GetCollator().compareString( rArg1.first, rArg2.first ) < 0; } }; diff --git a/sc/source/ui/miscdlgs/acredlin.cxx b/sc/source/ui/miscdlgs/acredlin.cxx index 9cdc8a14cd81..06d4ef3a7b57 100644 --- a/sc/source/ui/miscdlgs/acredlin.cxx +++ b/sc/source/ui/miscdlgs/acredlin.cxx @@ -1806,7 +1806,7 @@ int ScAcceptChgDlg::ColCompareHdl(const weld::TreeIter& rLeft, const weld::TreeI } } - return ScGlobal::GetCaseCollator()->compareString(rTreeView.get_text(rLeft, nSortCol), + return ScGlobal::GetCaseCollator().compareString(rTreeView.get_text(rLeft, nSortCol), rTreeView.get_text(rRight, nSortCol)); } diff --git a/sc/source/ui/miscdlgs/solveroptions.cxx b/sc/source/ui/miscdlgs/solveroptions.cxx index b449d741eeb8..4c849959399a 100644 --- a/sc/source/ui/miscdlgs/solveroptions.cxx +++ b/sc/source/ui/miscdlgs/solveroptions.cxx @@ -48,7 +48,7 @@ struct ScSolverOptionsEntry bool operator< (const ScSolverOptionsEntry& rOther) const { - return (ScGlobal::GetCollator()->compareString( aDescription, rOther.aDescription ) < 0); + return (ScGlobal::GetCollator().compareString( aDescription, rOther.aDescription ) < 0); } }; diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index 94102611fdfd..29479c7ef78f 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -1730,7 +1730,7 @@ void ScDBFunc::DataPilotSort(ScDPObject* pDPObj, tools::Long nDimIndex, bool bAs } // Sort the member list in ascending order. - ScOUStringCollate aCollate( ScGlobal::GetCollator() ); + ScOUStringCollate aCollate( &ScGlobal::GetCollator() ); std::stable_sort(aMembers.begin(), aMembers.end(), aCollate); // Collect and rank those custom sort strings that also exist in the member name list. -- cgit v1.2.3