use more concrete UNO classes in linguistic
Change-Id: Iae9dc3c7dadc21e3d92192a197f42c55e590fab1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182434 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <cppuhelper/implbase.hxx>
|
||||
#include <i18nlangtag/lang.h>
|
||||
#include <rtl/ustring.hxx>
|
||||
#include <rtl/ref.hxx>
|
||||
#include <linguistic/lngdllapi.h>
|
||||
|
||||
#include <vector>
|
||||
@@ -45,7 +46,6 @@ namespace osl { class Mutex; }
|
||||
class CharClass;
|
||||
class LocaleDataWrapper;
|
||||
|
||||
|
||||
inline constexpr OUString SN_GRAMMARCHECKER = u"com.sun.star.linguistic2.Proofreader"_ustr;
|
||||
inline constexpr OUString SN_SPELLCHECKER = u"com.sun.star.linguistic2.SpellChecker"_ustr;
|
||||
inline constexpr OUString SN_HYPHENATOR = u"com.sun.star.linguistic2.Hyphenator"_ustr;
|
||||
@@ -54,6 +54,7 @@ inline constexpr OUString SN_THESAURUS = u"com.sun.star.linguistic2.Thesaurus"_u
|
||||
|
||||
namespace linguistic
|
||||
{
|
||||
class HyphenatedWord;
|
||||
|
||||
|
||||
// AddEntryToDic return values
|
||||
@@ -122,7 +123,7 @@ LNG_DLLPUBLIC OUString GetWritableDictionaryURL( std::u16string_view rDicName )
|
||||
|
||||
LNG_DLLPUBLIC sal_Int32 GetPosInWordToCheck( std::u16string_view rTxt, sal_Int32 nPos );
|
||||
|
||||
css::uno::Reference< css::linguistic2::XHyphenatedWord >
|
||||
rtl::Reference< HyphenatedWord >
|
||||
RebuildHyphensAndControlChars(
|
||||
const OUString &rOrigWord,
|
||||
css::uno::Reference< css::linguistic2::XHyphenatedWord > const &rxHyphWord );
|
||||
|
@@ -72,23 +72,23 @@ void HyphenatorDispatcher::ClearSvcList()
|
||||
}
|
||||
|
||||
|
||||
Reference<XHyphenatedWord> HyphenatorDispatcher::buildHyphWord(
|
||||
rtl::Reference< HyphenatedWord > HyphenatorDispatcher::buildHyphWord(
|
||||
const OUString& rOrigWord,
|
||||
const Reference<XDictionaryEntry> &xEntry,
|
||||
LanguageType nLang, sal_Int16 nMaxLeading )
|
||||
{
|
||||
MutexGuard aGuard( GetLinguMutex() );
|
||||
|
||||
Reference< XHyphenatedWord > xRes;
|
||||
if (!xEntry.is())
|
||||
return nullptr;
|
||||
|
||||
if (xEntry.is())
|
||||
{
|
||||
OUString aText( xEntry->getDictionaryWord() );
|
||||
sal_Int32 nTextLen = aText.getLength();
|
||||
|
||||
// trailing '=' means "hyphenation should not be possible"
|
||||
if (nTextLen > 0 && aText[ nTextLen - 1 ] != '=' && aText[ nTextLen - 1 ] != '[')
|
||||
{
|
||||
if (nTextLen <= 0 || aText[ nTextLen - 1 ] == '=' || aText[ nTextLen - 1 ] == '[')
|
||||
return nullptr;
|
||||
|
||||
sal_Int16 nHyphenationPos = -1;
|
||||
sal_Int16 nOrigHyphPos = -1;
|
||||
|
||||
@@ -122,8 +122,9 @@ Reference<XHyphenatedWord> HyphenatorDispatcher::buildHyphWord(
|
||||
}
|
||||
}
|
||||
|
||||
if (nHyphenationPos > 0)
|
||||
{
|
||||
if (nHyphenationPos <= 0)
|
||||
return nullptr;
|
||||
|
||||
#if OSL_DEBUG_LEVEL > 0
|
||||
{
|
||||
if (std::u16string_view(aTmp) != rOrigWord)
|
||||
@@ -168,32 +169,30 @@ Reference<XHyphenatedWord> HyphenatorDispatcher::buildHyphWord(
|
||||
if (nHyphenPos == -1)
|
||||
aText = rOrigWord;
|
||||
|
||||
xRes = new HyphenatedWord( rOrigWord, nLang, nHyphenationPos,
|
||||
rtl::Reference< HyphenatedWord > xRes = new HyphenatedWord( rOrigWord, nLang, nHyphenationPos,
|
||||
aText, (nHyphenPos > -1) ? nHyphenPos - 1 : nHyphenationPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return xRes;
|
||||
}
|
||||
|
||||
|
||||
Reference< XPossibleHyphens > HyphenatorDispatcher::buildPossHyphens(
|
||||
rtl::Reference<PossibleHyphens> HyphenatorDispatcher::buildPossHyphens(
|
||||
const Reference< XDictionaryEntry > &xEntry, LanguageType nLanguage )
|
||||
{
|
||||
MutexGuard aGuard( GetLinguMutex() );
|
||||
|
||||
Reference<XPossibleHyphens> xRes;
|
||||
if (!xEntry.is())
|
||||
return nullptr;
|
||||
|
||||
if (xEntry.is())
|
||||
{
|
||||
// text with hyphenation info
|
||||
OUString aText( xEntry->getDictionaryWord() );
|
||||
sal_Int32 nTextLen = aText.getLength();
|
||||
|
||||
// trailing '=' means "hyphenation should not be possible"
|
||||
if (nTextLen > 0 && aText[ nTextLen - 1 ] != '=' && aText[ nTextLen - 1 ] != '[')
|
||||
{
|
||||
if (nTextLen <= 0 || aText[ nTextLen - 1 ] == '=' || aText[ nTextLen - 1 ] == '[')
|
||||
return nullptr;
|
||||
|
||||
// sequence to hold hyphenation positions
|
||||
Sequence< sal_Int16 > aHyphPos( nTextLen );
|
||||
sal_Int16 *pPos = aHyphPos.getArray();
|
||||
@@ -229,14 +228,12 @@ Reference< XPossibleHyphens > HyphenatorDispatcher::buildPossHyphens(
|
||||
}
|
||||
DBG_ASSERT( nHyphCount >= 0, "lng : invalid hyphenation count");
|
||||
|
||||
if (nHyphCount > 0)
|
||||
{
|
||||
if (nHyphCount <= 0)
|
||||
return nullptr;
|
||||
|
||||
aHyphPos.realloc( nHyphCount );
|
||||
xRes = new PossibleHyphens( aTmp.makeStringAndClear(), nLanguage,
|
||||
rtl::Reference<PossibleHyphens> xRes = new PossibleHyphens( aTmp.makeStringAndClear(), nLanguage,
|
||||
aText, aHyphPos );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return xRes;
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@
|
||||
#include "defs.hxx"
|
||||
|
||||
class LngSvcMgr;
|
||||
|
||||
namespace linguistic { class HyphenatedWord; class PossibleHyphens; }
|
||||
|
||||
class HyphenatorDispatcher :
|
||||
public cppu::WeakImplHelper
|
||||
@@ -60,12 +60,12 @@ class HyphenatorDispatcher :
|
||||
|
||||
void ClearSvcList();
|
||||
|
||||
static css::uno::Reference< css::linguistic2::XHyphenatedWord>
|
||||
static rtl::Reference< linguistic::HyphenatedWord >
|
||||
buildHyphWord( const OUString& rOrigWord,
|
||||
const css::uno::Reference< css::linguistic2::XDictionaryEntry> &xEntry,
|
||||
LanguageType nLang, sal_Int16 nMaxLeading );
|
||||
|
||||
static css::uno::Reference< css::linguistic2::XPossibleHyphens >
|
||||
static rtl::Reference< linguistic::PossibleHyphens >
|
||||
buildPossHyphens( const css::uno::Reference< css::linguistic2::XDictionaryEntry > &xEntry,
|
||||
LanguageType nLanguage );
|
||||
|
||||
|
@@ -498,13 +498,13 @@ sal_Int32 GetPosInWordToCheck( std::u16string_view rTxt, sal_Int32 nPos )
|
||||
return nRes;
|
||||
}
|
||||
|
||||
uno::Reference< XHyphenatedWord > RebuildHyphensAndControlChars(
|
||||
rtl::Reference< HyphenatedWord > RebuildHyphensAndControlChars(
|
||||
const OUString &rOrigWord,
|
||||
uno::Reference< XHyphenatedWord > const &rxHyphWord )
|
||||
{
|
||||
uno::Reference< XHyphenatedWord > xRes;
|
||||
if (!rOrigWord.isEmpty() && rxHyphWord.is())
|
||||
{
|
||||
if (rOrigWord.isEmpty() || !rxHyphWord.is())
|
||||
return nullptr;
|
||||
|
||||
sal_Int16 nChgPos = 0,
|
||||
nChgLen = 0;
|
||||
OUString aRplc;
|
||||
@@ -541,20 +541,17 @@ uno::Reference< XHyphenatedWord > RebuildHyphensAndControlChars(
|
||||
nOrigHyphenationPos = GetOrigWordPos( rOrigWord, nHyphenationPos );
|
||||
}
|
||||
|
||||
if (nOrigHyphenPos == -1 || nOrigHyphenationPos == -1)
|
||||
if (nOrigHyphenPos != -1 && nOrigHyphenationPos != -1)
|
||||
{
|
||||
SAL_WARN( "linguistic", "failed to get nOrigHyphenPos or nOrigHyphenationPos" );
|
||||
}
|
||||
else
|
||||
{
|
||||
LanguageType nLang = LinguLocaleToLanguage( rxHyphWord->getLocale() );
|
||||
xRes = new HyphenatedWord(
|
||||
rOrigWord, nLang, nOrigHyphenationPos,
|
||||
aOrigHyphenatedWord, nOrigHyphenPos );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
return xRes;
|
||||
LanguageType nLang = LinguLocaleToLanguage( rxHyphWord->getLocale() );
|
||||
return new HyphenatedWord(
|
||||
rOrigWord, nLang, nOrigHyphenationPos,
|
||||
aOrigHyphenatedWord, nOrigHyphenPos );
|
||||
|
||||
}
|
||||
|
||||
bool IsUpper( const OUString &rText, sal_Int32 nPos, sal_Int32 nLen, LanguageType nLanguage )
|
||||
|
@@ -424,17 +424,18 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl(
|
||||
{
|
||||
MutexGuard aGuard( GetLinguMutex() );
|
||||
|
||||
Reference< XSpellAlternatives > xRes;
|
||||
|
||||
if (LinguIsUnspecified( nLanguage) || rWord.isEmpty())
|
||||
return xRes;
|
||||
return nullptr;
|
||||
|
||||
// search for entry with that language
|
||||
SpellSvcByLangMap_t::iterator aIt( m_aSvcMap.find( nLanguage ) );
|
||||
LangSvcEntries_Spell *pEntry = aIt != m_aSvcMap.end() ? aIt->second.get() : nullptr;
|
||||
|
||||
if (pEntry)
|
||||
{
|
||||
if (!pEntry)
|
||||
return nullptr;
|
||||
|
||||
Reference< XSpellAlternatives > xRes;
|
||||
|
||||
OUString aChkWord( rWord );
|
||||
Locale aLocale( LanguageTag::convertToLocale( nLanguage ) );
|
||||
|
||||
@@ -719,7 +720,6 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return xRes;
|
||||
}
|
||||
|
Reference in New Issue
Block a user