diff options
-rw-r--r-- | editeng/source/misc/svxacorr.cxx | 75 | ||||
-rw-r--r-- | include/editeng/svxacorr.hxx | 2 |
2 files changed, 40 insertions, 37 deletions
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 4ee4f61a0d33..14c4236f0d28 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -18,6 +18,7 @@ */ #include <memory> +#include <utility> #include <string_view> #include <sal/config.h> @@ -1633,14 +1634,14 @@ SvxAutoCorrectLanguageLists& SvxAutoCorrect::GetLanguageList_( LanguageTag aLanguageTag( eLang); if (m_aLangTable.find(aLanguageTag) == m_aLangTable.end()) (void)CreateLanguageFile(aLanguageTag); - return *(m_aLangTable.find(aLanguageTag)->second); + return m_aLangTable.find(aLanguageTag)->second; } void SvxAutoCorrect::SaveCplSttExceptList( LanguageType eLang ) { auto const iter = m_aLangTable.find(LanguageTag(eLang)); - if (iter != m_aLangTable.end() && iter->second) - iter->second->SaveCplSttExceptList(); + if (iter != m_aLangTable.end()) + iter->second.SaveCplSttExceptList(); else { SAL_WARN("editeng", "Save an empty list? "); @@ -1650,8 +1651,8 @@ void SvxAutoCorrect::SaveCplSttExceptList( LanguageType eLang ) void SvxAutoCorrect::SaveWordStartExceptList(LanguageType eLang) { auto const iter = m_aLangTable.find(LanguageTag(eLang)); - if (iter != m_aLangTable.end() && iter->second) - iter->second->SaveWordStartExceptList(); + if (iter != m_aLangTable.end()) + iter->second.SaveWordStartExceptList(); else { SAL_WARN("editeng", "Save an empty list? "); @@ -1666,15 +1667,15 @@ bool SvxAutoCorrect::AddCplSttException( const OUString& rNew, // either the right language is present or it will be this in the general list auto iter = m_aLangTable.find(LanguageTag(eLang)); if (iter != m_aLangTable.end()) - pLists = iter->second.get(); + pLists = &iter->second; else { LanguageTag aLangTagUndetermined( LANGUAGE_UNDETERMINED); iter = m_aLangTable.find(aLangTagUndetermined); if (iter != m_aLangTable.end()) - pLists = iter->second.get(); + pLists = &iter->second; else if(CreateLanguageFile(aLangTagUndetermined)) - pLists = m_aLangTable.find(aLangTagUndetermined)->second.get(); + pLists = &m_aLangTable.find(aLangTagUndetermined)->second; } OSL_ENSURE(pLists, "No auto correction data"); return pLists && pLists->AddToCplSttExceptList(rNew); @@ -1688,15 +1689,15 @@ bool SvxAutoCorrect::AddWordStartException( const OUString& rNew, //either the right language is present or it is set in the general list auto iter = m_aLangTable.find(LanguageTag(eLang)); if (iter != m_aLangTable.end()) - pLists = iter->second.get(); + pLists = &iter->second; else { LanguageTag aLangTagUndetermined( LANGUAGE_UNDETERMINED); iter = m_aLangTable.find(aLangTagUndetermined); if (iter != m_aLangTable.end()) - pLists = iter->second.get(); + pLists = &iter->second; else if(CreateLanguageFile(aLangTagUndetermined)) - pLists = m_aLangTable.find(aLangTagUndetermined)->second.get(); + pLists = &m_aLangTable.find(aLangTagUndetermined)->second; } OSL_ENSURE(pLists, "No auto correction file!"); return pLists && pLists->AddToWordStartExceptList(rNew); @@ -1799,9 +1800,10 @@ bool SvxAutoCorrect::CreateLanguageFile( const LanguageTag& rLanguageTag, bool b if( bNewFile ) { sShareDirFile = sUserDirFile; - pLists = new SvxAutoCorrectLanguageLists( *this, sShareDirFile, sUserDirFile ); - LanguageTag aTmp(rLanguageTag); // this insert() needs a non-const reference - m_aLangTable.insert(std::make_pair(aTmp, std::unique_ptr<SvxAutoCorrectLanguageLists>(pLists))); + auto itBool = m_aLangTable.emplace(std::piecewise_construct, + std::forward_as_tuple(rLanguageTag), + std::forward_as_tuple(*this, sShareDirFile, sUserDirFile)); + pLists = &itBool.first->second; aLastFileTable.erase(nFndPos); } } @@ -1815,9 +1817,10 @@ bool SvxAutoCorrect::CreateLanguageFile( const LanguageTag& rLanguageTag, bool b ( sShareDirFile = sUserDirFile, bNewFile ) ) { - pLists = new SvxAutoCorrectLanguageLists( *this, sShareDirFile, sUserDirFile ); - LanguageTag aTmp(rLanguageTag); // this insert() needs a non-const reference - m_aLangTable.insert(std::make_pair(aTmp, std::unique_ptr<SvxAutoCorrectLanguageLists>(pLists))); + auto itBool = m_aLangTable.emplace(std::piecewise_construct, + std::forward_as_tuple(rLanguageTag), + std::forward_as_tuple(*this, sShareDirFile, sUserDirFile)); + pLists = &itBool.first->second; if (nFndPos != aLastFileTable.end()) aLastFileTable.erase(nFndPos); } @@ -1834,9 +1837,9 @@ bool SvxAutoCorrect::PutText( const OUString& rShort, const OUString& rLong, LanguageTag aLanguageTag( eLang); auto const iter = m_aLangTable.find(aLanguageTag); if (iter != m_aLangTable.end()) - return iter->second->PutText(rShort, rLong); + return iter->second.PutText(rShort, rLong); if(CreateLanguageFile(aLanguageTag)) - return m_aLangTable.find(aLanguageTag)->second->PutText(rShort, rLong); + return m_aLangTable.find(aLanguageTag)->second.PutText(rShort, rLong); return false; } @@ -1848,11 +1851,11 @@ void SvxAutoCorrect::MakeCombinedChanges( std::vector<SvxAutocorrWord>& aNewEntr auto const iter = m_aLangTable.find(aLanguageTag); if (iter != m_aLangTable.end()) { - iter->second->MakeCombinedChanges( aNewEntries, aDeleteEntries ); + iter->second.MakeCombinedChanges( aNewEntries, aDeleteEntries ); } else if(CreateLanguageFile( aLanguageTag )) { - m_aLangTable.find( aLanguageTag )->second->MakeCombinedChanges( aNewEntries, aDeleteEntries ); + m_aLangTable.find( aLanguageTag )->second.MakeCombinedChanges( aNewEntries, aDeleteEntries ); } } @@ -1937,8 +1940,8 @@ const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList( if (m_aLangTable.find(aLanguageTag) != m_aLangTable.end() || CreateLanguageFile(aLanguageTag, false)) { //the language is available - so bring it on - std::unique_ptr<SvxAutoCorrectLanguageLists> const& pList = m_aLangTable.find(aLanguageTag)->second; - pRet = lcl_SearchWordsInList( pList.get(), rTxt, rStt, nEndPos ); + SvxAutoCorrectLanguageLists & rList = m_aLangTable.find(aLanguageTag)->second; + pRet = lcl_SearchWordsInList( &rList, rTxt, rStt, nEndPos ); if( pRet ) { rLang = aLanguageTag; @@ -1958,8 +1961,8 @@ const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList( CreateLanguageFile(aLanguageTag, false))) { //the language is available - so bring it on - std::unique_ptr<SvxAutoCorrectLanguageLists> const& pList = m_aLangTable.find(aLanguageTag)->second; - pRet = lcl_SearchWordsInList( pList.get(), rTxt, rStt, nEndPos ); + SvxAutoCorrectLanguageLists& rList = m_aLangTable.find(aLanguageTag)->second; + pRet = lcl_SearchWordsInList( &rList, rTxt, rStt, nEndPos ); if( pRet ) { rLang = aLanguageTag; @@ -1971,8 +1974,8 @@ const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList( CreateLanguageFile(aLanguageTag, false)) { //the language is available - so bring it on - std::unique_ptr<SvxAutoCorrectLanguageLists> const& pList = m_aLangTable.find(aLanguageTag)->second; - pRet = lcl_SearchWordsInList( pList.get(), rTxt, rStt, nEndPos ); + SvxAutoCorrectLanguageLists& rList = m_aLangTable.find(aLanguageTag)->second; + pRet = lcl_SearchWordsInList( &rList, rTxt, rStt, nEndPos ); if( pRet ) { rLang = aLanguageTag; @@ -1995,8 +1998,8 @@ bool SvxAutoCorrect::FindInWordStartExceptList( LanguageType eLang, if (m_aLangTable.find(aLanguageTag) != m_aLangTable.end() || CreateLanguageFile(aLanguageTag, false)) { //the language is available - so bring it on - auto const& pList = m_aLangTable.find(aLanguageTag)->second; - if(pList->GetWordStartExceptList()->find(sWord) != pList->GetWordStartExceptList()->end() ) + auto& rList = m_aLangTable.find(aLanguageTag)->second; + if(rList.GetWordStartExceptList()->find(sWord) != rList.GetWordStartExceptList()->end() ) return true; } @@ -2009,8 +2012,8 @@ bool SvxAutoCorrect::FindInWordStartExceptList( LanguageType eLang, CreateLanguageFile(aLanguageTag, false))) { //the language is available - so bring it on - auto const& pList = m_aLangTable.find(aLanguageTag)->second; - if(pList->GetWordStartExceptList()->find(sWord) != pList->GetWordStartExceptList()->end() ) + auto& rList = m_aLangTable.find(aLanguageTag)->second; + if(rList.GetWordStartExceptList()->find(sWord) != rList.GetWordStartExceptList()->end() ) return true; } @@ -2018,8 +2021,8 @@ bool SvxAutoCorrect::FindInWordStartExceptList( LanguageType eLang, CreateLanguageFile(aLanguageTag, false)) { //the language is available - so bring it on - auto const& pList = m_aLangTable.find(aLanguageTag)->second; - if(pList->GetWordStartExceptList()->find(sWord) != pList->GetWordStartExceptList()->end() ) + auto& rList = m_aLangTable.find(aLanguageTag)->second; + if(rList.GetWordStartExceptList()->find(sWord) != rList.GetWordStartExceptList()->end() ) return true; } return false; @@ -2071,7 +2074,7 @@ bool SvxAutoCorrect::FindInCplSttExceptList(LanguageType eLang, if (m_aLangTable.find(aLanguageTag) != m_aLangTable.end() || CreateLanguageFile(aLanguageTag, false)) { //the language is available - so bring it on - const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second->GetCplSttExceptList(); + const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second.GetCplSttExceptList(); if(bAbbreviation ? lcl_FindAbbreviation(pList, sWord) : pList->find(sWord) != pList->end() ) return true; } @@ -2085,7 +2088,7 @@ bool SvxAutoCorrect::FindInCplSttExceptList(LanguageType eLang, CreateLanguageFile(aLanguageTag, false))) { //the language is available - so bring it on - const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second->GetCplSttExceptList(); + const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second.GetCplSttExceptList(); if(bAbbreviation ? lcl_FindAbbreviation(pList, sWord) : pList->find(sWord) != pList->end() ) return true; } @@ -2094,7 +2097,7 @@ bool SvxAutoCorrect::FindInCplSttExceptList(LanguageType eLang, CreateLanguageFile(aLanguageTag, false)) { //the language is available - so bring it on - const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second->GetCplSttExceptList(); + const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second.GetCplSttExceptList(); if(bAbbreviation ? lcl_FindAbbreviation(pList, sWord) : pList->find(sWord) != pList->end() ) return true; } diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx index 7483e83c127a..d3d7aacbd0a9 100644 --- a/include/editeng/svxacorr.hxx +++ b/include/editeng/svxacorr.hxx @@ -252,7 +252,7 @@ class EDITENG_DLLPUBLIC SvxAutoCorrect SvxSwAutoFormatFlags aSwFlags; // StarWriter AutoFormat Flags // all languages in a table - std::map<LanguageTag, std::unique_ptr<SvxAutoCorrectLanguageLists>> m_aLangTable; + std::map<LanguageTag, SvxAutoCorrectLanguageLists> m_aLangTable; std::map<LanguageTag, sal_Int64> aLastFileTable; std::unique_ptr<CharClass> pCharClass; |