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>
This commit is contained in:
Noel Grandin 2018-01-22 14:04:06 +02:00
parent cc45c96770
commit 23e9b12944
17 changed files with 90 additions and 109 deletions

View file

@ -210,6 +210,9 @@ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, cons
// painful linked list
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/basic/source/inc/runtime.hxx"))
return;
// not sure how the node management is working here
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/i18npool/source/localedata/saxparser.cxx"))
return;
report(
DiagnosticsEngine::Warning,

View file

@ -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;

View file

@ -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;
};

View file

@ -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) ---

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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() )

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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))
{

View file

@ -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