diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2023-05-12 22:07:54 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-05-13 14:56:06 +0200 |
commit | 5dc82f62d54fbd6299b4a1dc677e714e92f2f88c (patch) | |
tree | dbba9287eff7abaa32e16d9f9af1252c06ae38ee /linguistic | |
parent | 3168d1ab07239789cd36a5960cef2d13ae29c9de (diff) |
use more optional for CharClass
Change-Id: I67984321b8f38928bfab9fb0b624620e7d286a11
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151722
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'linguistic')
-rw-r--r-- | linguistic/source/spelldsp.cxx | 18 | ||||
-rw-r--r-- | linguistic/source/spelldsp.hxx | 5 |
2 files changed, 12 insertions, 11 deletions
diff --git a/linguistic/source/spelldsp.cxx b/linguistic/source/spelldsp.cxx index c1b309b00adf..92b2d4c3efbd 100644 --- a/linguistic/source/spelldsp.cxx +++ b/linguistic/source/spelldsp.cxx @@ -394,9 +394,9 @@ bool SpellCheckerDispatcher::isValid_Impl( bRes = !xTmp->isNegative(); } else { setCharClass(LanguageTag(nLanguage)); - CapType ct = capitalType(aChkWord, m_pCharClass.get()); + CapType ct = capitalType(aChkWord, m_oCharClass ? &*m_oCharClass : nullptr); if (ct == CapType::INITCAP || ct == CapType::ALLCAP) { - Reference< XDictionaryEntry > xTmp2( lcl_GetRulingDictionaryEntry( makeLowerCase(aChkWord, m_pCharClass.get()), nLanguage ) ); + Reference< XDictionaryEntry > xTmp2( lcl_GetRulingDictionaryEntry( makeLowerCase(aChkWord, m_oCharClass), nLanguage ) ); if (xTmp2.is()) { bRes = !xTmp2->isNegative(); } @@ -635,10 +635,10 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl( else { setCharClass(LanguageTag(nLanguage)); - CapType ct = capitalType(aChkWord, m_pCharClass.get()); + CapType ct = capitalType(aChkWord, m_oCharClass ? &*m_oCharClass : nullptr); if (ct == CapType::INITCAP || ct == CapType::ALLCAP) { - Reference< XDictionaryEntry > xTmp2( lcl_GetRulingDictionaryEntry( makeLowerCase(aChkWord, m_pCharClass.get()), nLanguage ) ); + Reference< XDictionaryEntry > xTmp2( lcl_GetRulingDictionaryEntry( makeLowerCase(aChkWord, m_oCharClass), nLanguage ) ); if (xTmp2.is()) { if (xTmp2->isNegative()) // negative entry found @@ -655,10 +655,10 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl( switch ( ct ) { case CapType::INITCAP: - aProposalList.Prepend( m_pCharClass->titlecase(aAddRplcTxt) ); + aProposalList.Prepend( m_oCharClass->titlecase(aAddRplcTxt) ); break; case CapType::ALLCAP: - aProposalList.Prepend( m_pCharClass->uppercase(aAddRplcTxt) ); + aProposalList.Prepend( m_oCharClass->uppercase(aAddRplcTxt) ); break; default: /* can't happen because of if ct == above */ @@ -813,13 +813,13 @@ void SpellCheckerDispatcher::FlushSpellCache() void SpellCheckerDispatcher::setCharClass(const LanguageTag& rLanguageTag) { - if (m_pCharClass && m_pCharClass->getLanguageTag() == rLanguageTag) + if (m_oCharClass && m_oCharClass->getLanguageTag() == rLanguageTag) return; - m_pCharClass.reset( new CharClass(rLanguageTag) ); + m_oCharClass.emplace( rLanguageTag ); } -OUString SpellCheckerDispatcher::makeLowerCase(const OUString& aTerm, CharClass const * pCC) +OUString SpellCheckerDispatcher::makeLowerCase(const OUString& aTerm, const std::optional<CharClass> & pCC) { if (pCC) return pCC->lowercase(aTerm); diff --git a/linguistic/source/spelldsp.hxx b/linguistic/source/spelldsp.hxx index c93560441333..73fe59579ff3 100644 --- a/linguistic/source/spelldsp.hxx +++ b/linguistic/source/spelldsp.hxx @@ -31,6 +31,7 @@ #include <map> #include <memory> +#include <optional> #include <unotools/charclass.hxx> class LngSvcMgr; @@ -53,7 +54,7 @@ class SpellCheckerDispatcher : LngSvcMgr &m_rMgr; mutable std::unique_ptr<linguistic::SpellCache> m_pCache; // Spell Cache (holds known words) - std::unique_ptr<CharClass> m_pCharClass; + std::optional<CharClass> m_oCharClass; SpellCheckerDispatcher(const SpellCheckerDispatcher &) = delete; SpellCheckerDispatcher & operator = (const SpellCheckerDispatcher &) = delete; @@ -105,7 +106,7 @@ public: private: void setCharClass(const LanguageTag& rLanguageTag); - static OUString makeLowerCase(const OUString&, CharClass const *); + static OUString makeLowerCase(const OUString&, const std::optional<CharClass> &); }; |