diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-06 11:28:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-17 07:06:55 +0100 |
commit | abf173db4b46afd6925c5138f24f1f5146c96525 (patch) | |
tree | 363e5f6975eca5fb5dec9d400b98959c290cb3fd /lingucomponent | |
parent | 35ba29e093d41ce88a827ab145ba8df09ff0ee2f (diff) |
loplugin:useuniqueptr in Thesaurus
Change-Id: I59a2cbeb08242ec1929b0c70f28e1d059dec70ca
Reviewed-on: https://gerrit.libreoffice.org/49875
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'lingucomponent')
-rw-r--r-- | lingucomponent/source/thesaurus/libnth/nthesimp.cxx | 82 | ||||
-rw-r--r-- | lingucomponent/source/thesaurus/libnth/nthesimp.hxx | 17 |
2 files changed, 30 insertions, 69 deletions
diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx index ce1d4a07f492..c3b5bb08cabf 100644 --- a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx +++ b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx @@ -71,45 +71,12 @@ Thesaurus::Thesaurus() : { bDisposing = false; pPropHelper = nullptr; - aThes = nullptr; - aCharSetInfo = nullptr; - aTEncs = nullptr; - aTLocs = nullptr; - aTNames = nullptr; - numthes = 0; prevLocale = LANGUAGE_DONTKNOW; } Thesaurus::~Thesaurus() { - if (aThes) - { - for (int i = 0; i < numthes; i++) - { - if (aThes[i]) delete aThes[i]; - aThes[i] = nullptr; - } - delete[] aThes; - } - aThes = nullptr; - if (aCharSetInfo) - { - for (int i = 0; i < numthes; i++) - { - if (aCharSetInfo[i]) delete aCharSetInfo[i]; - aCharSetInfo[i] = nullptr; - } - delete[] aCharSetInfo; - } - aCharSetInfo = nullptr; - numthes = 0; - if (aTEncs) delete[] aTEncs; - aTEncs = nullptr; - if (aTLocs) delete[] aTLocs; - aTLocs = nullptr; - if (aTNames) delete[] aTNames; - aTNames = nullptr; - + mvThesInfo.clear(); if (pPropHelper) { pPropHelper->RemoveAsPropListener(); @@ -135,7 +102,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales() // this routine should return the locales supported by the installed // dictionaries. - if (!numthes) + if (!mvThesInfo.size()) { SvtLinguConfig aLinguCfg; @@ -163,7 +130,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales() // is not yet supported by the list od new style dictionaries MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics ); - numthes = aDics.size(); + sal_Int32 numthes = aDics.size(); if (numthes) { // get supported locales from the dictionaries-to-use... @@ -201,11 +168,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales() numthes = numthes + dict.aLocaleNames.getLength(); // add dictionary information - aThes = new MyThes* [numthes]; - aTEncs = new rtl_TextEncoding [numthes]; - aTLocs = new Locale [numthes]; - aTNames = new OUString [numthes]; - aCharSetInfo = new CharClass* [numthes]; + mvThesInfo.resize(numthes); k = 0; for (auto const& dict : aDics) @@ -222,17 +185,16 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales() for (sal_Int32 i = 0; i < nLocales; ++i) { LanguageTag aLanguageTag(dict.aLocaleNames[i]); - aThes[k] = nullptr; - aTEncs[k] = RTL_TEXTENCODING_DONTKNOW; - aTLocs[k] = aLanguageTag.getLocale(); - aCharSetInfo[k] = new CharClass( aLanguageTag ); + mvThesInfo[k].aEncoding = RTL_TEXTENCODING_DONTKNOW; + mvThesInfo[k].aLocale = aLanguageTag.getLocale(); + mvThesInfo[k].aCharSetInfo.reset( new CharClass( aLanguageTag ) ); // also both files have to be in the same directory and the // file names must only differ in the extension (.aff/.dic). // Thus we use the first location only and strip the extension part. OUString aLocation = dict.aLocations[0]; sal_Int32 nPos = aLocation.lastIndexOf( '.' ); aLocation = aLocation.copy( 0, nPos ); - aTNames[k] = aLocation; + mvThesInfo[k].aName = aLocation; ++k; } @@ -243,12 +205,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales() else { /* no dictionary found so register no dictionaries */ - numthes = 0; - aThes = nullptr; - aTEncs = nullptr; - aTLocs = nullptr; - aTNames = nullptr; - aCharSetInfo = nullptr; + mvThesInfo.clear(); aSuppLocales.realloc(0); } } @@ -319,15 +276,15 @@ Sequence < Reference < css::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryM CharClass * pCC = nullptr; // find the first thesaurus that matches the locale - for (int i =0; i < numthes; i++) + for (size_t i =0; i < mvThesInfo.size(); i++) { - if (rLocale == aTLocs[i]) + if (rLocale == mvThesInfo[i].aLocale) { // open up and initialize this thesaurus if need be - if (!aThes[i]) + if (!mvThesInfo[i].aThes) { - OUString datpath = aTNames[i] + ".dat"; - OUString idxpath = aTNames[i] + ".idx"; + OUString datpath = mvThesInfo[i].aName + ".dat"; + OUString idxpath = mvThesInfo[i].aName + ".idx"; OUString ndat; OUString nidx; osl::FileBase::getSystemPathFromFileURL(datpath,ndat); @@ -342,13 +299,12 @@ Sequence < Reference < css::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryM OString aTmpdat(OU2ENC(ndat,osl_getThreadTextEncoding())); #endif - aThes[i] = new MyThes(aTmpidx.getStr(),aTmpdat.getStr()); - if (aThes[i]) - aTEncs[i] = getTextEncodingFromCharset(aThes[i]->get_th_encoding()); + mvThesInfo[i].aThes.reset( new MyThes(aTmpidx.getStr(),aTmpdat.getStr()) ); + mvThesInfo[i].aEncoding = getTextEncodingFromCharset(mvThesInfo[i].aThes->get_th_encoding()); } - pTH = aThes[i]; - eEnc = aTEncs[i]; - pCC = aCharSetInfo[i]; + pTH = mvThesInfo[i].aThes.get(); + eEnc = mvThesInfo[i].aEncoding; + pCC = mvThesInfo[i].aCharSetInfo.get(); if (pTH) break; diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.hxx b/lingucomponent/source/thesaurus/libnth/nthesimp.hxx index f1c27822b859..34ad5ca092c9 100644 --- a/lingucomponent/source/thesaurus/libnth/nthesimp.hxx +++ b/lingucomponent/source/thesaurus/libnth/nthesimp.hxx @@ -41,6 +41,8 @@ #include <osl/file.hxx> #include <mythes.hxx> +#include <memory> +#include <vector> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; @@ -66,12 +68,15 @@ class Thesaurus : ::comphelper::OInterfaceContainerHelper2 aEvtListeners; linguistic::PropertyHelper_Thesaurus* pPropHelper; bool bDisposing; - CharClass ** aCharSetInfo; - MyThes ** aThes; - rtl_TextEncoding * aTEncs; - Locale * aTLocs; - OUString * aTNames; - sal_Int32 numthes; + struct ThesInfo + { + std::unique_ptr<CharClass> aCharSetInfo; + std::unique_ptr<MyThes> aThes; + rtl_TextEncoding aEncoding; + Locale aLocale; + OUString aName; + }; + std::vector<ThesInfo> mvThesInfo; // cache for the Thesaurus dialog Sequence < Reference < css::linguistic2::XMeaning > > prevMeanings; |