diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-02-27 10:34:12 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-03-01 14:15:46 +0000 |
commit | 14b4fcf0d8c761ad1679b0d6e765ebd7f3a90dbd (patch) | |
tree | 7024a170f16024c3f8ef02780e98cd4b0e580774 /sw | |
parent | a42d9c5b541d637dcf24086e30f341b30e03c4c7 (diff) |
reorg SwBreakIt to just create it at the start
Change-Id: Ie2b725e4e0c8d9b581ced74f9cdd08d97ab90e46
Reviewed-on: https://gerrit.libreoffice.org/34746
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/breakit.hxx | 7 | ||||
-rw-r--r-- | sw/source/core/bastyp/breakit.cxx | 36 |
2 files changed, 14 insertions, 29 deletions
diff --git a/sw/inc/breakit.hxx b/sw/inc/breakit.hxx index 6b92d8052f27..0bb13f08f8a0 100644 --- a/sw/inc/breakit.hxx +++ b/sw/inc/breakit.hxx @@ -33,7 +33,7 @@ enum class SvtScriptType; class SW_DLLPUBLIC SwBreakIt { css::uno::Reference< css::uno::XComponentContext > m_xContext; - mutable css::uno::Reference< css::i18n::XBreakIterator > xBreak; + css::uno::Reference<css::i18n::XBreakIterator> m_xBreak; std::unique_ptr<LanguageTag> m_xLanguageTag; ///< language tag of the current locale std::unique_ptr<css::i18n::ForbiddenCharacters> m_xForbidden; @@ -44,8 +44,6 @@ class SW_DLLPUBLIC SwBreakIt void GetLocale_( const LanguageTag& rLanguageTag ); void GetForbidden_( const LanguageType aLang ); - void createBreakIterator() const; - SwBreakIt(SwBreakIt const&) = delete; SwBreakIt& operator=(SwBreakIt const&) = delete; @@ -63,8 +61,7 @@ public: css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() { - createBreakIterator(); - return xBreak; + return m_xBreak; } const css::lang::Locale& GetLocale( const LanguageType aLang ) diff --git a/sw/source/core/bastyp/breakit.cxx b/sw/source/core/bastyp/breakit.cxx index 5e7a22c19271..ff955e1eacec 100644 --- a/sw/source/core/bastyp/breakit.cxx +++ b/sw/source/core/bastyp/breakit.cxx @@ -54,15 +54,9 @@ SwBreakIt * SwBreakIt::Get() SwBreakIt::SwBreakIt( const uno::Reference<uno::XComponentContext> & rxContext ) : m_xContext(rxContext) + , m_xBreak(i18n::BreakIterator::create(m_xContext)) , aForbiddenLang(LANGUAGE_DONTKNOW) { - assert(m_xContext.is() && "SwBreakIt: no MultiServiceFactory"); -} - -void SwBreakIt::createBreakIterator() const -{ - if (!xBreak.is()) - xBreak.set(i18n::BreakIterator::create(m_xContext)); } void SwBreakIt::GetLocale_( const LanguageType aLang ) @@ -91,16 +85,15 @@ void SwBreakIt::GetForbidden_( const LanguageType aLang ) sal_uInt16 SwBreakIt::GetRealScriptOfText( const OUString& rText, sal_Int32 nPos ) const { - createBreakIterator(); sal_uInt16 nScript = i18n::ScriptType::WEAK; - if( xBreak.is() && !rText.isEmpty() ) + if (!rText.isEmpty()) { if( nPos && nPos == rText.getLength() ) --nPos; else if( nPos < 0) nPos = 0; - nScript = xBreak->getScriptType( rText, nPos ); + nScript = m_xBreak->getScriptType(rText, nPos); sal_Int32 nChgPos = 0; if (i18n::ScriptType::WEAK == nScript && nPos >= 0 && nPos + 1 < rText.getLength()) { @@ -111,22 +104,22 @@ sal_uInt16 SwBreakIt::GetRealScriptOfText( const OUString& rText, sal_Int32 nPos case U_NON_SPACING_MARK: case U_ENCLOSING_MARK: case U_COMBINING_SPACING_MARK: - nScript = xBreak->getScriptType( rText, nPos+1 ); + nScript = m_xBreak->getScriptType(rText, nPos+1); break; } } if( i18n::ScriptType::WEAK == nScript && nPos && - 0 < ( nChgPos = xBreak->beginOfScript( rText, nPos, nScript ) ) ) + 0 < ( nChgPos = m_xBreak->beginOfScript(rText, nPos, nScript) ) ) { - nScript = xBreak->getScriptType( rText, nChgPos-1 ); + nScript = m_xBreak->getScriptType(rText, nChgPos-1); } if( i18n::ScriptType::WEAK == nScript && - rText.getLength() > ( nChgPos = xBreak->endOfScript( rText, nPos, nScript ) ) && + rText.getLength() > ( nChgPos = m_xBreak->endOfScript(rText, nPos, nScript) ) && 0 <= nChgPos ) { - nScript = xBreak->getScriptType( rText, nChgPos ); + nScript = m_xBreak->getScriptType(rText, nChgPos); } } if( i18n::ScriptType::WEAK == nScript ) @@ -139,19 +132,14 @@ SvtScriptType SwBreakIt::GetAllScriptsOfText( const OUString& rText ) const const SvtScriptType coAllScripts = ( SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX ); - createBreakIterator(); SvtScriptType nRet = SvtScriptType::NONE; sal_uInt16 nScript = 0; - if( !xBreak.is() ) - { - nRet = coAllScripts; - } - else if( !rText.isEmpty() ) + if (!rText.isEmpty()) { for( sal_Int32 n = 0, nEnd = rText.getLength(); n < nEnd; - n = xBreak->endOfScript(rText, n, nScript) ) + n = m_xBreak->endOfScript(rText, n, nScript) ) { - switch( nScript = xBreak->getScriptType( rText, n ) ) + switch( nScript = m_xBreak->getScriptType(rText, n) ) { case i18n::ScriptType::LATIN: nRet |= SvtScriptType::LATIN; break; case i18n::ScriptType::ASIAN: nRet |= SvtScriptType::ASIAN; break; @@ -185,7 +173,7 @@ sal_Int32 SwBreakIt::getGraphemeCount(const OUString& rText, else { sal_Int32 nCount2 = 1; - nCurPos = xBreak->nextCharacters(rText, nCurPos, lang::Locale(), + nCurPos = m_xBreak->nextCharacters(rText, nCurPos, lang::Locale(), i18n::CharacterIteratorMode::SKIPCELL, nCount2, nCount2); } ++nGraphemeCount; |