summaryrefslogtreecommitdiff
path: root/i18npool/source/search/textsearch.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-01-22 14:04:06 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-02-02 11:12:15 +0100
commit23e9b1294471459d386152b1197cfe58514af5da (patch)
tree0c8705260a4f33810e4c69f09a09dca7031e0ea7 /i18npool/source/search/textsearch.cxx
parentcc45c96770def8fb3cc8c6d6c3d385c592806ae9 (diff)
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/source/search/textsearch.cxx')
-rw-r--r--i18npool/source/search/textsearch.cxx68
1 files changed, 28 insertions, 40 deletions
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))
{