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>
This commit is contained in:
Noel Grandin
2023-05-12 22:07:54 +02:00
committed by Noel Grandin
parent 3168d1ab07
commit 5dc82f62d5
10 changed files with 37 additions and 33 deletions

View File

@@ -359,7 +359,7 @@ SvxAutoCorrect::~SvxAutoCorrect()
void SvxAutoCorrect::GetCharClass_( LanguageType eLang ) void SvxAutoCorrect::GetCharClass_( LanguageType eLang )
{ {
pCharClass.reset( new CharClass( LanguageTag( eLang)) ); moCharClass.emplace( LanguageTag( eLang) );
eCharClassLang = eLang; eCharClassLang = eLang;
} }

View File

@@ -28,14 +28,15 @@
#include <tools/date.hxx> #include <tools/date.hxx>
#include <editeng/swafopt.hxx> #include <editeng/swafopt.hxx>
#include <editeng/editengdllapi.h> #include <editeng/editengdllapi.h>
#include <unotools/charclass.hxx>
#include <optional> #include <optional>
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <string_view> #include <string_view>
#include <utility> #include <utility>
class CharClass;
class SfxPoolItem; class SfxPoolItem;
class SotStorage; class SotStorage;
class SvxAutoCorrect; class SvxAutoCorrect;
@@ -255,7 +256,7 @@ class EDITENG_DLLPUBLIC SvxAutoCorrect
// all languages in a table // all languages in a table
std::map<LanguageTag, SvxAutoCorrectLanguageLists> m_aLangTable; std::map<LanguageTag, SvxAutoCorrectLanguageLists> m_aLangTable;
std::map<LanguageTag, sal_Int64> aLastFileTable; std::map<LanguageTag, sal_Int64> aLastFileTable;
std::unique_ptr<CharClass> pCharClass; std::optional<CharClass> moCharClass;
LanguageType eCharClassLang; LanguageType eCharClassLang;
@@ -440,9 +441,9 @@ public:
CharClass& GetCharClass( LanguageType eLang ) CharClass& GetCharClass( LanguageType eLang )
{ {
if( !pCharClass || eLang != eCharClassLang ) if( !moCharClass || eLang != eCharClassLang )
GetCharClass_( eLang ); GetCharClass_( eLang );
return *pCharClass; return *moCharClass;
} }
}; };

View File

@@ -394,9 +394,9 @@ bool SpellCheckerDispatcher::isValid_Impl(
bRes = !xTmp->isNegative(); bRes = !xTmp->isNegative();
} else { } else {
setCharClass(LanguageTag(nLanguage)); 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) { 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.is()) {
bRes = !xTmp2->isNegative(); bRes = !xTmp2->isNegative();
} }
@@ -635,10 +635,10 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl(
else else
{ {
setCharClass(LanguageTag(nLanguage)); 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) 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.is())
{ {
if (xTmp2->isNegative()) // negative entry found if (xTmp2->isNegative()) // negative entry found
@@ -655,10 +655,10 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl(
switch ( ct ) switch ( ct )
{ {
case CapType::INITCAP: case CapType::INITCAP:
aProposalList.Prepend( m_pCharClass->titlecase(aAddRplcTxt) ); aProposalList.Prepend( m_oCharClass->titlecase(aAddRplcTxt) );
break; break;
case CapType::ALLCAP: case CapType::ALLCAP:
aProposalList.Prepend( m_pCharClass->uppercase(aAddRplcTxt) ); aProposalList.Prepend( m_oCharClass->uppercase(aAddRplcTxt) );
break; break;
default: default:
/* can't happen because of if ct == above */ /* can't happen because of if ct == above */
@@ -813,13 +813,13 @@ void SpellCheckerDispatcher::FlushSpellCache()
void SpellCheckerDispatcher::setCharClass(const LanguageTag& rLanguageTag) void SpellCheckerDispatcher::setCharClass(const LanguageTag& rLanguageTag)
{ {
if (m_pCharClass && m_pCharClass->getLanguageTag() == rLanguageTag) if (m_oCharClass && m_oCharClass->getLanguageTag() == rLanguageTag)
return; 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) if (pCC)
return pCC->lowercase(aTerm); return pCC->lowercase(aTerm);

View File

@@ -31,6 +31,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <unotools/charclass.hxx> #include <unotools/charclass.hxx>
class LngSvcMgr; class LngSvcMgr;
@@ -53,7 +54,7 @@ class SpellCheckerDispatcher :
LngSvcMgr &m_rMgr; LngSvcMgr &m_rMgr;
mutable std::unique_ptr<linguistic::SpellCache> m_pCache; // Spell Cache (holds known words) 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(const SpellCheckerDispatcher &) = delete;
SpellCheckerDispatcher & operator = (const SpellCheckerDispatcher &) = delete; SpellCheckerDispatcher & operator = (const SpellCheckerDispatcher &) = delete;
@@ -105,7 +106,7 @@ public:
private: private:
void setCharClass(const LanguageTag& rLanguageTag); void setCharClass(const LanguageTag& rLanguageTag);
static OUString makeLowerCase(const OUString&, CharClass const *); static OUString makeLowerCase(const OUString&, const std::optional<CharClass> &);
}; };

View File

@@ -22,11 +22,13 @@
#include <com/sun/star/text/WritingMode.hpp> #include <com/sun/star/text/WritingMode.hpp>
#include <svl/style.hxx> #include <svl/style.hxx>
#include <svx/fmmodel.hxx> #include <svx/fmmodel.hxx>
#include <unotools/charclass.hxx>
#include <vcl/prntypes.hxx> #include <vcl/prntypes.hxx>
#include <xmloff/autolayout.hxx> #include <xmloff/autolayout.hxx>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <optional>
#include <string_view> #include <string_view>
#include "sddllapi.h" #include "sddllapi.h"
@@ -51,7 +53,6 @@ struct SpellCallbackInfo;
class SdCustomShowList; class SdCustomShowList;
class SdUndoGroup; class SdUndoGroup;
class SdrObject; class SdrObject;
class CharClass;
class Idle; class Idle;
class ImageMap; class ImageMap;
class Outliner; class Outliner;
@@ -162,8 +163,8 @@ private:
::sd::DrawDocShellRef mxAllocedDocShRef; // => AllocModel() ::sd::DrawDocShellRef mxAllocedDocShRef; // => AllocModel()
bool mbAllocDocSh; // => AllocModel() bool mbAllocDocSh; // => AllocModel()
DocumentType meDocType; DocumentType meDocType;
std::unique_ptr<CharClass> std::optional<CharClass>
mpCharClass; moCharClass;
::std::unique_ptr<ImpDrawPageListWatcher> mpDrawPageListWatcher; ::std::unique_ptr<ImpDrawPageListWatcher> mpDrawPageListWatcher;
::std::unique_ptr<ImpMasterPageListWatcher> mpMasterPageListWatcher; ::std::unique_ptr<ImpMasterPageListWatcher> mpMasterPageListWatcher;
@@ -464,7 +465,7 @@ public:
static SdAnimationInfo* GetShapeUserData(SdrObject& rObject, bool bCreate = false ); static SdAnimationInfo* GetShapeUserData(SdrObject& rObject, bool bCreate = false );
SAL_DLLPRIVATE CharClass* GetCharClass() const { return mpCharClass.get(); } SAL_DLLPRIVATE const std::optional<CharClass>& GetCharClass() const { return moCharClass; }
SAL_DLLPRIVATE void UpdateAllLinks(); SAL_DLLPRIVATE void UpdateAllLinks();

View File

@@ -199,7 +199,7 @@ SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh)
} }
LanguageType eRealLanguage = MsLangId::getRealLanguage( meLanguage ); LanguageType eRealLanguage = MsLangId::getRealLanguage( meLanguage );
mpCharClass.reset(new CharClass( LanguageTag( eRealLanguage) )); moCharClass.emplace(LanguageTag( eRealLanguage));
// If the current application language is a language that uses right-to-left text... // If the current application language is a language that uses right-to-left text...
LanguageType eRealCTLLanguage = Application::GetSettings().GetLanguageTag().getLanguageType(); LanguageType eRealCTLLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
@@ -367,7 +367,7 @@ SdDrawDocument::~SdDrawDocument()
mpCustomShowList.reset(); mpCustomShowList.reset();
mpOutliner.reset(); mpOutliner.reset();
mpInternalOutliner.reset(); mpInternalOutliner.reset();
mpCharClass.reset(); moCharClass.reset();
} }
void SdDrawDocument::adaptSizeAndBorderForAllPages( void SdDrawDocument::adaptSizeAndBorderForAllPages(

View File

@@ -195,7 +195,7 @@ void SdCustomShowDlg::SelectHdl(void const *p)
{ {
// replace number by a number increased by 1 // replace number by a number increased by 1
const CharClass* pCharClass = rDoc.GetCharClass(); const std::optional<CharClass>& pCharClass = rDoc.GetCharClass();
while( pCharClass->isDigit( aStr, nStrPos ) ) while( pCharClass->isDigit( aStr, nStrPos ) )
aStr = aStr.replaceAt( nStrPos, 1, u"" ); aStr = aStr.replaceAt( nStrPos, 1, u"" );
aStr = aStr.subView( 0, nStrPos) + OUString::number( ++nNum ) + aStr.subView( nStrPos); aStr = aStr.subView( 0, nStrPos) + OUString::number( ++nNum ) + aStr.subView( nStrPos);

View File

@@ -98,7 +98,7 @@ class SwAutoFormat
SwTextFrame* m_pCurTextFrame; // frame of the current TextNode SwTextFrame* m_pCurTextFrame; // frame of the current TextNode
bool m_bIsRightToLeft; // text direction of the current frame bool m_bIsRightToLeft; // text direction of the current frame
SwNodeOffset m_nEndNdIdx; // for the percentage-display SwNodeOffset m_nEndNdIdx; // for the percentage-display
mutable std::unique_ptr<CharClass> m_pCharClass; // Character classification mutable std::optional<CharClass> m_oCharClass; // Character classification
mutable LanguageType m_eCharClassLang; mutable LanguageType m_eCharClassLang;
sal_uInt16 m_nRedlAutoFormatSeqId; sal_uInt16 m_nRedlAutoFormatSeqId;
@@ -121,12 +121,12 @@ class SwAutoFormat
CharClass& GetCharClass( LanguageType eLang ) const CharClass& GetCharClass( LanguageType eLang ) const
{ {
if( !m_pCharClass || eLang != m_eCharClassLang ) if( !m_oCharClass || eLang != m_eCharClassLang )
{ {
m_pCharClass.reset( new CharClass( LanguageTag( eLang ) ) ); m_oCharClass.emplace( LanguageTag( eLang ) );
m_eCharClassLang = eLang; m_eCharClassLang = eLang;
} }
return *m_pCharClass; return *m_oCharClass;
} }
static bool IsSpace( const sal_Unicode c ) static bool IsSpace( const sal_Unicode c )

View File

@@ -20,13 +20,14 @@
#define INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX #define INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
#include <i18nlangtag/lang.h> #include <i18nlangtag/lang.h>
#include <unotools/charclass.hxx>
#include <nodeoffset.hxx> #include <nodeoffset.hxx>
#include <tox.hxx> #include <tox.hxx>
#include <com/sun/star/lang/Locale.hpp> #include <com/sun/star/lang/Locale.hpp>
#include <optional>
#include <utility> #include <utility>
class CharClass;
class SwContentNode; class SwContentNode;
class SwTextNode; class SwTextNode;
class SwTextTOXMark; class SwTextTOXMark;
@@ -73,7 +74,7 @@ struct TextAndReading
class SwTOXInternational class SwTOXInternational
{ {
std::unique_ptr<IndexEntrySupplierWrapper> m_pIndexWrapper; std::unique_ptr<IndexEntrySupplierWrapper> m_pIndexWrapper;
std::unique_ptr<CharClass> m_pCharClass; std::optional<CharClass> m_oCharClass;
LanguageType m_eLang; LanguageType m_eLang;
OUString m_sSortAlgorithm; OUString m_sSortAlgorithm;
SwTOIOptions m_nOptions; SwTOIOptions m_nOptions;

View File

@@ -91,24 +91,24 @@ void SwTOXInternational::Init()
else else
m_pIndexWrapper->LoadAlgorithm( aLcl, m_sSortAlgorithm, SW_COLLATOR_IGNORES ); m_pIndexWrapper->LoadAlgorithm( aLcl, m_sSortAlgorithm, SW_COLLATOR_IGNORES );
m_pCharClass.reset( new CharClass( LanguageTag( aLcl )) ); m_oCharClass.emplace( LanguageTag( aLcl ) );
} }
SwTOXInternational::~SwTOXInternational() SwTOXInternational::~SwTOXInternational()
{ {
m_pCharClass.reset(); m_oCharClass.reset();
m_pIndexWrapper.reset(); m_pIndexWrapper.reset();
} }
OUString SwTOXInternational::ToUpper( const OUString& rStr, sal_Int32 nPos ) const OUString SwTOXInternational::ToUpper( const OUString& rStr, sal_Int32 nPos ) const
{ {
return m_pCharClass->uppercase( rStr, nPos, 1 ); return m_oCharClass->uppercase( rStr, nPos, 1 );
} }
bool SwTOXInternational::IsNumeric( const OUString& rStr ) const bool SwTOXInternational::IsNumeric( const OUString& rStr ) const
{ {
return m_pCharClass->isNumeric( rStr ); return m_oCharClass->isNumeric( rStr );
} }
sal_Int32 SwTOXInternational::Compare( const TextAndReading& rTaR1, sal_Int32 SwTOXInternational::Compare( const TextAndReading& rTaR1,