diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-01-22 14:04:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-02 11:12:15 +0100 |
commit | 23e9b1294471459d386152b1197cfe58514af5da (patch) | |
tree | 0c8705260a4f33810e4c69f09a09dca7031e0ea7 /i18npool | |
parent | use TypedWhichId in BaseProperties::GetItem (diff) | |
download | core-23e9b1294471459d386152b1197cfe58514af5da.tar.gz core-23e9b1294471459d386152b1197cfe58514af5da.zip |
loplugin:useuniqueptr in i18npool
Change-Id: Iff39b9298bfad474c5c011b6355b8ebf5be06318
Reviewed-on: https://gerrit.libreoffice.org/49091
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/inc/breakiteratorImpl.hxx | 2 | ||||
-rw-r--r-- | i18npool/inc/calendarImpl.hxx | 2 | ||||
-rw-r--r-- | i18npool/inc/cclass_unicode.hxx | 3 | ||||
-rw-r--r-- | i18npool/inc/characterclassificationImpl.hxx | 3 | ||||
-rw-r--r-- | i18npool/inc/collatorImpl.hxx | 3 | ||||
-rw-r--r-- | i18npool/inc/collator_unicode.hxx | 2 | ||||
-rw-r--r-- | i18npool/inc/inputsequencechecker.hxx | 3 | ||||
-rw-r--r-- | i18npool/source/breakiterator/breakiteratorImpl.cxx | 20 | ||||
-rw-r--r-- | i18npool/source/calendar/calendarImpl.cxx | 12 | ||||
-rw-r--r-- | i18npool/source/characterclassification/cclass_unicode.cxx | 6 | ||||
-rw-r--r-- | i18npool/source/characterclassification/characterclassificationImpl.cxx | 19 | ||||
-rw-r--r-- | i18npool/source/collator/collatorImpl.cxx | 16 | ||||
-rw-r--r-- | i18npool/source/collator/collator_unicode.cxx | 16 | ||||
-rw-r--r-- | i18npool/source/inputchecker/inputsequencechecker.cxx | 12 | ||||
-rw-r--r-- | i18npool/source/search/textsearch.cxx | 68 | ||||
-rw-r--r-- | i18npool/source/search/textsearch.hxx | 9 |
16 files changed, 87 insertions, 109 deletions
diff --git a/i18npool/inc/breakiteratorImpl.hxx b/i18npool/inc/breakiteratorImpl.hxx index 6ecaef630d3e..6d12a9cf24bd 100644 --- a/i18npool/inc/breakiteratorImpl.hxx +++ b/i18npool/inc/breakiteratorImpl.hxx @@ -116,7 +116,7 @@ private: css::lang::Locale aLocale; css::uno::Reference < XBreakIterator > xBI; }; - std::vector<lookupTableItem*> lookupTable; + std::vector<lookupTableItem> lookupTable; css::lang::Locale aLocale; css::uno::Reference < XBreakIterator > xBI; css::uno::Reference < css::uno::XComponentContext > m_xContext; diff --git a/i18npool/inc/calendarImpl.hxx b/i18npool/inc/calendarImpl.hxx index aec643dcd59e..8d8f0d3afd23 100644 --- a/i18npool/inc/calendarImpl.hxx +++ b/i18npool/inc/calendarImpl.hxx @@ -100,7 +100,7 @@ private: OUString uniqueID; css::uno::Reference < css::i18n::XCalendar4 > xCalendar; }; - std::vector<lookupTableItem*> lookupTable; + std::vector<lookupTableItem> lookupTable; css::uno::Reference < css::uno::XComponentContext > m_xContext; css::uno::Reference < css::i18n::XCalendar4 > xCalendar; }; diff --git a/i18npool/inc/cclass_unicode.hxx b/i18npool/inc/cclass_unicode.hxx index bea025a231e9..2b6e3d9e890f 100644 --- a/i18npool/inc/cclass_unicode.hxx +++ b/i18npool/inc/cclass_unicode.hxx @@ -27,6 +27,7 @@ #include "transliteration_body.hxx" #include <o3tl/typed_flags_set.hxx> +#include <memory> namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; @@ -95,7 +96,7 @@ public: virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; private: - Transliteration_casemapping *trans; + std::unique_ptr<Transliteration_casemapping> trans; // --- parser specific (implemented in cclass_unicode_parser.cxx) --- diff --git a/i18npool/inc/characterclassificationImpl.hxx b/i18npool/inc/characterclassificationImpl.hxx index 36d37c69e4fc..078a31b116ba 100644 --- a/i18npool/inc/characterclassificationImpl.hxx +++ b/i18npool/inc/characterclassificationImpl.hxx @@ -22,6 +22,7 @@ #include <com/sun/star/i18n/XCharacterClassification.hpp> #include <cppuhelper/implbase.hxx> #include <vector> +#include <memory> #include <com/sun/star/i18n/KCharacterType.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/XComponentContext.hpp> @@ -80,7 +81,7 @@ private: aLocale.Variant == rLocale.Variant; }; }; - std::vector<lookupTableItem*> lookupTable; + std::vector<std::unique_ptr<lookupTableItem>> lookupTable; lookupTableItem *cachedItem; css::uno::Reference < css::uno::XComponentContext > m_xContext; diff --git a/i18npool/inc/collatorImpl.hxx b/i18npool/inc/collatorImpl.hxx index 534690897731..940031a1480f 100644 --- a/i18npool/inc/collatorImpl.hxx +++ b/i18npool/inc/collatorImpl.hxx @@ -29,6 +29,7 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <vector> +#include <memory> namespace i18npool { @@ -88,7 +89,7 @@ private: algorithm == _algorithm; } }; - std::vector<lookupTableItem*> lookupTable; + std::vector<std::unique_ptr<lookupTableItem>> lookupTable; lookupTableItem * cachedItem; // Service Factory diff --git a/i18npool/inc/collator_unicode.hxx b/i18npool/inc/collator_unicode.hxx index d943bc9bc2c1..275b8f8faf79 100644 --- a/i18npool/inc/collator_unicode.hxx +++ b/i18npool/inc/collator_unicode.hxx @@ -63,7 +63,7 @@ public: private: const sal_Char *implementationName; - icu::RuleBasedCollator *uca_base, *collator; + std::unique_ptr<icu::RuleBasedCollator> uca_base, collator; #ifndef DISABLE_DYNLOADING oslModule hModule; #endif diff --git a/i18npool/inc/inputsequencechecker.hxx b/i18npool/inc/inputsequencechecker.hxx index 0c27637b9535..a8dbdb80d21f 100644 --- a/i18npool/inc/inputsequencechecker.hxx +++ b/i18npool/inc/inputsequencechecker.hxx @@ -26,6 +26,7 @@ #include <com/sun/star/i18n/XExtendedInputSequenceChecker.hpp> #include <vector> +#include <memory> namespace i18npool { @@ -63,7 +64,7 @@ private: const sal_Char* aLanguage; css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > xISC; }; - std::vector<lookupTableItem*> lookupTable; + std::vector<std::unique_ptr<lookupTableItem>> lookupTable; lookupTableItem *cachedItem; css::uno::Reference < css::uno::XComponentContext > m_xContext; diff --git a/i18npool/source/breakiterator/breakiteratorImpl.cxx b/i18npool/source/breakiterator/breakiteratorImpl.cxx index de45516ec31d..e923fbd99eaa 100644 --- a/i18npool/source/breakiterator/breakiteratorImpl.cxx +++ b/i18npool/source/breakiterator/breakiteratorImpl.cxx @@ -41,10 +41,6 @@ BreakIteratorImpl::BreakIteratorImpl() BreakIteratorImpl::~BreakIteratorImpl() { - // Clear lookuptable - for (lookupTableItem* p : lookupTable) - delete p; - lookupTable.clear(); } #define LBI getLocaleSpecificBreakIterator(rLocale) @@ -530,9 +526,9 @@ sal_Int16 BreakIteratorImpl::getScriptClass(sal_uInt32 currentChar) bool BreakIteratorImpl::createLocaleSpecificBreakIterator(const OUString& aLocaleName) { // to share service between same Language but different Country code, like zh_CN and zh_TW - for (lookupTableItem* listItem : lookupTable) { - if (aLocaleName == listItem->aLocale.Language) { - xBI = listItem->xBI; + for (lookupTableItem& listItem : lookupTable) { + if (aLocaleName == listItem.aLocale.Language) { + xBI = listItem.xBI; return true; } } @@ -560,7 +556,7 @@ bool BreakIteratorImpl::createLocaleSpecificBreakIterator(const OUString& aLocal if ( xI.is() ) { xBI.set(xI, UNO_QUERY); if (xBI.is()) { - lookupTable.push_back(new lookupTableItem(Locale(aLocaleName, aLocaleName, aLocaleName), xBI)); + lookupTable.emplace_back(Locale(aLocaleName, aLocaleName, aLocaleName), xBI); return true; } } @@ -575,9 +571,9 @@ BreakIteratorImpl::getLocaleSpecificBreakIterator(const Locale& rLocale) else if (m_xContext.is()) { aLocale = rLocale; - for (lookupTableItem* listItem : lookupTable) { - if (rLocale == listItem->aLocale) - return xBI = listItem->xBI; + for (lookupTableItem& listItem : lookupTable) { + if (rLocale == listItem.aLocale) + return xBI = listItem.xBI; } sal_Unicode under = '_'; @@ -606,7 +602,7 @@ BreakIteratorImpl::getLocaleSpecificBreakIterator(const Locale& rLocale) createLocaleSpecificBreakIterator(rLocale.Language)) || // load default service with name <base>_Unicode createLocaleSpecificBreakIterator("Unicode")) { - lookupTable.push_back( new lookupTableItem(aLocale, xBI) ); + lookupTable.emplace_back( aLocale, xBI ); return xBI; } } diff --git a/i18npool/source/calendar/calendarImpl.cxx b/i18npool/source/calendar/calendarImpl.cxx index c40735b83761..2f3ffc5c1043 100644 --- a/i18npool/source/calendar/calendarImpl.cxx +++ b/i18npool/source/calendar/calendarImpl.cxx @@ -36,10 +36,6 @@ CalendarImpl::CalendarImpl(const Reference< XComponentContext > &rxContext) : m_ CalendarImpl::~CalendarImpl() { - // Clear lookuptable - for (lookupTableItem* p : lookupTable) - delete p; - lookupTable.clear(); } void SAL_CALL @@ -62,9 +58,9 @@ CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) sal_Int32 i; for (i = 0; i < sal::static_int_cast<sal_Int32>(lookupTable.size()); i++) { - lookupTableItem *listItem = lookupTable[i]; - if (uniqueID == listItem->uniqueID) { - xCalendar = listItem->xCalendar; + lookupTableItem &listItem = lookupTable[i]; + if (uniqueID == listItem.uniqueID) { + xCalendar = listItem.xCalendar; break; } } @@ -88,7 +84,7 @@ CalendarImpl::loadCalendar(const OUString& uniqueID, const Locale& rLocale ) throw ERROR; xCalendar.set(xI, UNO_QUERY); - lookupTable.push_back( new lookupTableItem(uniqueID, xCalendar) ); + lookupTable.emplace_back( uniqueID, xCalendar ); } if ( !xCalendar.is() ) diff --git a/i18npool/source/characterclassification/cclass_unicode.cxx b/i18npool/source/characterclassification/cclass_unicode.cxx index 5b000060c49b..70727dea8cb1 100644 --- a/i18npool/source/characterclassification/cclass_unicode.cxx +++ b/i18npool/source/characterclassification/cclass_unicode.cxx @@ -39,7 +39,9 @@ namespace i18npool { // class cclass_Unicode // ----------------------------------------------------; -cclass_Unicode::cclass_Unicode( const uno::Reference < XComponentContext >& rxContext ) : m_xContext( rxContext ), +cclass_Unicode::cclass_Unicode( const uno::Reference < XComponentContext >& rxContext ) : + trans( new Transliteration_casemapping() ), + m_xContext( rxContext ), pTable( nullptr ), pStart( nullptr ), pCont( nullptr ), @@ -50,12 +52,10 @@ cclass_Unicode::cclass_Unicode( const uno::Reference < XComponentContext >& rxCo cDecimalSep( '.' ), cDecimalSepAlt( 0 ) { - trans = new Transliteration_casemapping(); } cclass_Unicode::~cclass_Unicode() { destroyParserTable(); - delete trans; } diff --git a/i18npool/source/characterclassification/characterclassificationImpl.cxx b/i18npool/source/characterclassification/characterclassificationImpl.cxx index ccccbe432bf9..b9f008d26930 100644 --- a/i18npool/source/characterclassification/characterclassificationImpl.cxx +++ b/i18npool/source/characterclassification/characterclassificationImpl.cxx @@ -36,10 +36,6 @@ CharacterClassificationImpl::CharacterClassificationImpl( } CharacterClassificationImpl::~CharacterClassificationImpl() { - // Clear lookuptable - for (lookupTableItem* p : lookupTable) - delete p; - lookupTable.clear(); } @@ -128,9 +124,10 @@ bool CharacterClassificationImpl::createLocaleSpecificCharacterClassification(co { // to share service between same Language but different Country code, like zh_CN and zh_SG for (size_t l = 0; l < lookupTable.size(); l++) { - cachedItem = lookupTable[l]; + cachedItem = lookupTable[l].get(); if (serviceName == cachedItem->aName) { - lookupTable.push_back( cachedItem = new lookupTableItem(rLocale, serviceName, cachedItem->xCI) ); + lookupTable.emplace_back( new lookupTableItem(rLocale, serviceName, cachedItem->xCI) ); + cachedItem = lookupTable.back().get(); return true; } } @@ -142,7 +139,8 @@ bool CharacterClassificationImpl::createLocaleSpecificCharacterClassification(co if ( xI.is() ) { xCI.set( xI, UNO_QUERY ); if (xCI.is()) { - lookupTable.push_back( cachedItem = new lookupTableItem(rLocale, serviceName, xCI) ); + lookupTable.emplace_back( new lookupTableItem(rLocale, serviceName, xCI) ); + cachedItem = lookupTable.back().get(); return true; } } @@ -156,8 +154,8 @@ CharacterClassificationImpl::getLocaleSpecificCharacterClassification(const Loca if (cachedItem && cachedItem->equals(rLocale)) return cachedItem->xCI; else { - for (lookupTableItem* i : lookupTable) { - cachedItem = i; + for (auto & i : lookupTable) { + cachedItem = i.get(); if (cachedItem->equals(rLocale)) return cachedItem->xCI; } @@ -180,7 +178,8 @@ CharacterClassificationImpl::getLocaleSpecificCharacterClassification(const Loca return cachedItem->xCI; else if (xUCI.is()) { - lookupTable.push_back( cachedItem = new lookupTableItem( rLocale, "Unicode", xUCI)); + lookupTable.emplace_back( new lookupTableItem(rLocale, "Unicode", xUCI) ); + cachedItem = lookupTable.back().get(); return cachedItem->xCI; } } diff --git a/i18npool/source/collator/collatorImpl.cxx b/i18npool/source/collator/collatorImpl.cxx index b9eed0230c40..27737270a7f0 100644 --- a/i18npool/source/collator/collatorImpl.cxx +++ b/i18npool/source/collator/collatorImpl.cxx @@ -40,10 +40,6 @@ CollatorImpl::CollatorImpl( const Reference < XComponentContext >& rxContext ) : CollatorImpl::~CollatorImpl() { - // Clear lookuptable - for (lookupTableItem* p : lookupTable) - delete p; - lookupTable.clear(); } sal_Int32 SAL_CALL @@ -144,9 +140,10 @@ bool CollatorImpl::createCollator(const lang::Locale& rLocale, const OUString& serviceName, const OUString& rSortAlgorithm) { for (size_t l = 0; l < lookupTable.size(); l++) { - cachedItem = lookupTable[l]; + cachedItem = lookupTable[l].get(); if (cachedItem->service == serviceName) {// cross locale sharing - lookupTable.push_back(cachedItem = new lookupTableItem(rLocale, rSortAlgorithm, serviceName, cachedItem->xC)); + lookupTable.emplace_back(new lookupTableItem(rLocale, rSortAlgorithm, serviceName, cachedItem->xC)); + cachedItem = lookupTable.back().get(); return true; } } @@ -157,7 +154,8 @@ CollatorImpl::createCollator(const lang::Locale& rLocale, const OUString& servic Reference < XCollator > xC; xC.set( xI, UNO_QUERY ); if (xC.is()) { - lookupTable.push_back(cachedItem = new lookupTableItem(rLocale, rSortAlgorithm, serviceName, xC)); + lookupTable.emplace_back(new lookupTableItem(rLocale, rSortAlgorithm, serviceName, xC)); + cachedItem = lookupTable.back().get(); return true; } } @@ -167,8 +165,8 @@ CollatorImpl::createCollator(const lang::Locale& rLocale, const OUString& servic void CollatorImpl::loadCachedCollator(const lang::Locale& rLocale, const OUString& rSortAlgorithm) { - for (lookupTableItem* i : lookupTable) { - cachedItem = i; + for (auto& i : lookupTable) { + cachedItem = i.get(); if (cachedItem->equals(rLocale, rSortAlgorithm)) { return; } diff --git a/i18npool/source/collator/collator_unicode.cxx b/i18npool/source/collator/collator_unicode.cxx index 37dc7eec6ea6..5bbe015e4d5e 100644 --- a/i18npool/source/collator/collator_unicode.cxx +++ b/i18npool/source/collator/collator_unicode.cxx @@ -48,8 +48,8 @@ Collator_Unicode::Collator_Unicode() Collator_Unicode::~Collator_Unicode() { - delete collator; - delete uca_base; + collator.reset(); + uca_base.reset(); #ifndef DISABLE_DYNLOADING if (hModule) osl_unloadModule(hModule); #endif @@ -138,7 +138,7 @@ Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang:: UErrorCode status = U_ZERO_ERROR; OUString rule = LocaleDataImpl::get()->getCollatorRuleByAlgorithm(rLocale, rAlgorithm); if (!rule.isEmpty()) { - collator = new icu::RuleBasedCollator(reinterpret_cast<const UChar *>(rule.getStr()), status); + collator.reset( new icu::RuleBasedCollator(reinterpret_cast<const UChar *>(rule.getStr()), status) ); if (! U_SUCCESS(status)) throw RuntimeException(); } if (!collator && OUString(LOCAL_RULE_LANGS).indexOf(rLocale.Language) >= 0) { @@ -354,12 +354,12 @@ Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang:: // The default collator of the en-US locale would also fulfill // the requirement. The collator of the actual locale or the // NULL (default) locale does not. - uca_base = static_cast<icu::RuleBasedCollator*>(icu::Collator::createInstance( - icu::Locale::getRoot(), status)); + uca_base.reset( static_cast<icu::RuleBasedCollator*>(icu::Collator::createInstance( + icu::Locale::getRoot(), status)) ); #endif if (! U_SUCCESS(status)) throw RuntimeException(); - collator = new icu::RuleBasedCollator( - reinterpret_cast<const uint8_t*>(ruleImage), ruleImageSize, uca_base, status); + collator.reset( new icu::RuleBasedCollator( + reinterpret_cast<const uint8_t*>(ruleImage), ruleImageSize, uca_base.get(), status) ); if (! U_SUCCESS(status)) throw RuntimeException(); } } @@ -372,7 +372,7 @@ Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang:: */ icu::Locale icuLocale( LanguageTagIcu::getIcuLocale( LanguageTag( rLocale), rAlgorithm)); // load ICU collator - collator = static_cast<icu::RuleBasedCollator*>( icu::Collator::createInstance(icuLocale, status) ); + collator.reset( static_cast<icu::RuleBasedCollator*>( icu::Collator::createInstance(icuLocale, status) ) ); if (! U_SUCCESS(status)) throw RuntimeException(); } } diff --git a/i18npool/source/inputchecker/inputsequencechecker.cxx b/i18npool/source/inputchecker/inputsequencechecker.cxx index 6fdc99440f28..15426db1bc57 100644 --- a/i18npool/source/inputchecker/inputsequencechecker.cxx +++ b/i18npool/source/inputchecker/inputsequencechecker.cxx @@ -43,11 +43,6 @@ InputSequenceCheckerImpl::InputSequenceCheckerImpl(const char *pServiceName) InputSequenceCheckerImpl::~InputSequenceCheckerImpl() { - // Clear lookuptable - for (lookupTableItem* p : lookupTable) - delete p; - - lookupTable.clear(); } sal_Bool SAL_CALL @@ -113,8 +108,8 @@ InputSequenceCheckerImpl::getInputSequenceChecker(sal_Char const * rLanguage) return cachedItem->xISC; } else { - for (lookupTableItem* l : lookupTable) { - cachedItem = l; + for (auto& l : lookupTable) { + cachedItem = l.get(); if (cachedItem->aLanguage == rLanguage) return cachedItem->xISC; } @@ -127,7 +122,8 @@ InputSequenceCheckerImpl::getInputSequenceChecker(sal_Char const * rLanguage) if ( xI.is() ) { Reference< XExtendedInputSequenceChecker > xISC( xI, UNO_QUERY ); if (xISC.is()) { - lookupTable.push_back(cachedItem = new lookupTableItem(rLanguage, xISC)); + lookupTable.emplace_back(new lookupTableItem(rLanguage, xISC)); + cachedItem = lookupTable.back().get(); return cachedItem->xISC; } } diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx index dfbdafbbf626..db3c5410b47c 100644 --- a/i18npool/source/search/textsearch.cxx +++ b/i18npool/source/search/textsearch.cxx @@ -118,10 +118,10 @@ TextSearch::TextSearch(const Reference < XComponentContext > & rxContext) TextSearch::~TextSearch() { - delete pRegexMatcher; - delete pWLD; - delete pJumpTable; - delete pJumpTable2; + pRegexMatcher.reset(); + pWLD.reset(); + pJumpTable.reset(); + pJumpTable2.reset(); } void TextSearch::setOptions2( const SearchOptions2& rOptions ) @@ -130,14 +130,10 @@ void TextSearch::setOptions2( const SearchOptions2& rOptions ) aSrchPara = rOptions; - delete pRegexMatcher; - pRegexMatcher = nullptr; - delete pWLD; - pWLD = nullptr; - delete pJumpTable; - pJumpTable = nullptr; - delete pJumpTable2; - pJumpTable2 = nullptr; + pRegexMatcher.reset(); + pWLD.reset(); + pJumpTable.reset(); + pJumpTable2.reset(); maWildcardReversePattern.clear(); maWildcardReversePattern2.clear(); TransliterationFlags transliterateFlags = static_cast<TransliterationFlags>(aSrchPara.transliterateFlags); @@ -232,9 +228,9 @@ void TextSearch::setOptions2( const SearchOptions2& rOptions ) fnForward = &TextSearch::ApproxSrchFrwrd; fnBackward = &TextSearch::ApproxSrchBkwrd; - pWLD = new WLevDistance( sSrchStr.getStr(), aSrchPara.changedChars, + pWLD.reset( new WLevDistance( sSrchStr.getStr(), aSrchPara.changedChars, aSrchPara.insertedChars, aSrchPara.deletedChars, - 0 != (SearchFlags::LEV_RELAXED & aSrchPara.searchFlag ) ); + 0 != (SearchFlags::LEV_RELAXED & aSrchPara.searchFlag ) ) ); nLimit = pWLD->GetLimit(); break; @@ -556,16 +552,15 @@ bool TextSearch::IsDelimiter( const OUString& rStr, sal_Int32 nPos ) const void TextSearch::MakeForwardTab() { // create the jumptable for the search text - if( pJumpTable ) + + if( pJumpTable && bIsForwardTab ) { - if( bIsForwardTab ) - return ; // the jumpTable is ok - delete pJumpTable; + return; // the jumpTable is ok } bIsForwardTab = true; sal_Int32 n, nLen = sSrchStr.getLength(); - pJumpTable = new TextSearchJumpTable; + pJumpTable.reset( new TextSearchJumpTable ); for( n = 0; n < nLen - 1; ++n ) { @@ -583,16 +578,14 @@ void TextSearch::MakeForwardTab() void TextSearch::MakeForwardTab2() { // create the jumptable for the search text - if( pJumpTable2 ) + if( pJumpTable2 && bIsForwardTab ) { - if( bIsForwardTab ) - return ; // the jumpTable is ok - delete pJumpTable2; + return; // the jumpTable is ok } bIsForwardTab = true; sal_Int32 n, nLen = sSrchStr2.getLength(); - pJumpTable2 = new TextSearchJumpTable; + pJumpTable2.reset( new TextSearchJumpTable ); for( n = 0; n < nLen - 1; ++n ) { @@ -610,16 +603,14 @@ void TextSearch::MakeForwardTab2() void TextSearch::MakeBackwardTab() { // create the jumptable for the search text - if( pJumpTable ) + if( pJumpTable && !bIsForwardTab) { - if( !bIsForwardTab ) - return ; // the jumpTable is ok - delete pJumpTable; + return; // the jumpTable is ok } bIsForwardTab = false; sal_Int32 n, nLen = sSrchStr.getLength(); - pJumpTable = new TextSearchJumpTable; + pJumpTable.reset( new TextSearchJumpTable ); for( n = nLen-1; n > 0; --n ) { @@ -635,16 +626,14 @@ void TextSearch::MakeBackwardTab() void TextSearch::MakeBackwardTab2() { // create the jumptable for the search text - if( pJumpTable2 ) + if( pJumpTable2 && !bIsForwardTab ) { - if( !bIsForwardTab ) - return ; // the jumpTable is ok - delete pJumpTable2; + return; // the jumpTable is ok } bIsForwardTab = false; sal_Int32 n, nLen = sSrchStr2.getLength(); - pJumpTable2 = new TextSearchJumpTable; + pJumpTable2.reset( new TextSearchJumpTable ); for( n = nLen-1; n > 0; --n ) { @@ -663,10 +652,10 @@ sal_Int32 TextSearch::GetDiff( const sal_Unicode cChr ) const OUString sSearchKey; if ( bUsePrimarySrchStr ) { - pJump = pJumpTable; + pJump = pJumpTable.get(); sSearchKey = sSrchStr; } else { - pJump = pJumpTable2; + pJump = pJumpTable2.get(); sSearchKey = sSrchStr2; } @@ -868,12 +857,11 @@ void TextSearch::RESrchPrepare( const css::util::SearchOptions2& rOptions) aIcuSearchPatStr = aChevronMatcherE.replaceAll( aChevronReplaceE, nIcuErr); aChevronMatcherE.reset(); #endif - pRegexMatcher = new RegexMatcher( aIcuSearchPatStr, nIcuSearchFlags, nIcuErr); + pRegexMatcher.reset( new RegexMatcher( aIcuSearchPatStr, nIcuSearchFlags, nIcuErr) ); if (nIcuErr) { SAL_INFO( "i18npool", "TextSearch::RESrchPrepare UErrorCode " << nIcuErr); - delete pRegexMatcher; - pRegexMatcher = nullptr; + pRegexMatcher.reset(); } else { @@ -897,7 +885,7 @@ void TextSearch::RESrchPrepare( const css::util::SearchOptions2& rOptions) } -static bool lcl_findRegex( RegexMatcher * pRegexMatcher, sal_Int32 nStartPos, UErrorCode & rIcuErr ) +static bool lcl_findRegex( std::unique_ptr<RegexMatcher>& pRegexMatcher, sal_Int32 nStartPos, UErrorCode & rIcuErr ) { if (!pRegexMatcher->find( nStartPos, rIcuErr)) { diff --git a/i18npool/source/search/textsearch.hxx b/i18npool/source/search/textsearch.hxx index 05c158d302a1..0459049842c5 100644 --- a/i18npool/source/search/textsearch.hxx +++ b/i18npool/source/search/textsearch.hxx @@ -29,6 +29,7 @@ #include <com/sun/star/uno/XComponentContext.hpp> #include <map> +#include <memory> #include <unicode/regex.h> using namespace U_ICU_NAMESPACE; @@ -64,8 +65,8 @@ class TextSearch: public cppu::WeakImplHelper FnSrch fnBackward; // Members and methods for the normal (Boyer-Moore) search - TextSearchJumpTable* pJumpTable; - TextSearchJumpTable* pJumpTable2; + std::unique_ptr<TextSearchJumpTable> pJumpTable; + std::unique_ptr<TextSearchJumpTable> pJumpTable2; bool bIsForwardTab; bool bUsePrimarySrchStr; void MakeForwardTab(); @@ -83,7 +84,7 @@ class TextSearch: public cppu::WeakImplHelper sal_Int32 startPos, sal_Int32 endPos ); // Members and methods for the regular expression search - RegexMatcher* pRegexMatcher; + std::unique_ptr<RegexMatcher> pRegexMatcher; /// @throws css::uno::RuntimeException css::util::SearchResult SAL_CALL RESrchFrwrd( const OUString& searchStr, @@ -96,7 +97,7 @@ class TextSearch: public cppu::WeakImplHelper // Members and methods for the "Weight Levenshtein-Distance" search int nLimit; - WLevDistance* pWLD; + std::unique_ptr<WLevDistance> pWLD; css::uno::Reference < css::i18n::XBreakIterator > xBreak; /// @throws css::uno::RuntimeException css::util::SearchResult SAL_CALL |