fdo#37954, #i18737# accept capitalized lowercase custom words
Change-Id: I3f8a7d1912952730151e2444f426aff8b2ba4c97 Reviewed-on: https://gerrit.libreoffice.org/1162 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com> Reviewed-by: Németh László <nemeth@numbertext.org>
This commit is contained in:
parent
cf71223c32
commit
4d160f28b5
@ -37,6 +37,13 @@
|
||||
#include "lngsvcmgr.hxx"
|
||||
#include "linguistic/lngprops.hxx"
|
||||
|
||||
// values asigned to capitalization types
|
||||
#define CAPTYPE_UNKNOWN 0
|
||||
#define CAPTYPE_NOCAP 1
|
||||
#define CAPTYPE_INITCAP 2
|
||||
#define CAPTYPE_ALLCAP 3
|
||||
#define CAPTYPE_MIXED 4
|
||||
|
||||
using namespace osl;
|
||||
using namespace com::sun::star;
|
||||
using namespace com::sun::star::beans;
|
||||
@ -180,6 +187,7 @@ SpellCheckerDispatcher::SpellCheckerDispatcher( LngSvcMgr &rLngSvcMgr ) :
|
||||
rMgr (rLngSvcMgr)
|
||||
{
|
||||
pCache = NULL;
|
||||
pCharClass = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -187,6 +195,7 @@ SpellCheckerDispatcher::~SpellCheckerDispatcher()
|
||||
{
|
||||
ClearSvcList();
|
||||
delete pCache;
|
||||
delete pCharClass;
|
||||
}
|
||||
|
||||
|
||||
@ -428,8 +437,18 @@ sal_Bool SpellCheckerDispatcher::isValid_Impl(
|
||||
GetDicList().is() && IsUseDicList( rProperties, GetPropSet() ))
|
||||
{
|
||||
Reference< XDictionaryEntry > xTmp( lcl_GetRulingDictionaryEntry( aChkWord, nLanguage ) );
|
||||
if (xTmp.is())
|
||||
if (xTmp.is()) {
|
||||
bRes = !xTmp->isNegative();
|
||||
} else {
|
||||
setCharClass(LanguageTag(nLanguage));
|
||||
sal_uInt16 ct = capitalType(aChkWord, pCharClass);
|
||||
if (ct == CAPTYPE_INITCAP || ct == CAPTYPE_ALLCAP) {
|
||||
Reference< XDictionaryEntry > xTmp2( lcl_GetRulingDictionaryEntry( makeLowerCase(aChkWord, pCharClass), nLanguage ) );
|
||||
if (xTmp2.is()) {
|
||||
bRes = !xTmp2->isNegative();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -811,4 +830,52 @@ void SpellCheckerDispatcher::FlushSpellCache()
|
||||
pCache->Flush();
|
||||
}
|
||||
|
||||
void SpellCheckerDispatcher::setCharClass(const LanguageTag& rLanguageTag)
|
||||
{
|
||||
if (!pCharClass)
|
||||
pCharClass = new CharClass(rLanguageTag);
|
||||
pCharClass->setLanguageTag(rLanguageTag);
|
||||
}
|
||||
|
||||
sal_uInt16 SAL_CALL SpellCheckerDispatcher::capitalType(const OUString& aTerm, CharClass * pCC)
|
||||
{
|
||||
sal_Int32 tlen = aTerm.getLength();
|
||||
if ((pCC) && (tlen))
|
||||
{
|
||||
String aStr(aTerm);
|
||||
sal_Int32 nc = 0;
|
||||
for (sal_uInt16 tindex = 0; tindex < tlen; tindex++)
|
||||
{
|
||||
if (pCC->getCharacterType(aStr,tindex) &
|
||||
::com::sun::star::i18n::KCharacterType::UPPER) nc++;
|
||||
}
|
||||
|
||||
if (nc == 0)
|
||||
return (sal_uInt16) CAPTYPE_NOCAP;
|
||||
if (nc == tlen)
|
||||
return (sal_uInt16) CAPTYPE_ALLCAP;
|
||||
if ((nc == 1) && (pCC->getCharacterType(aStr,0) &
|
||||
::com::sun::star::i18n::KCharacterType::UPPER))
|
||||
return (sal_uInt16) CAPTYPE_INITCAP;
|
||||
|
||||
return (sal_uInt16) CAPTYPE_MIXED;
|
||||
}
|
||||
return (sal_uInt16) CAPTYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OUString SAL_CALL SpellCheckerDispatcher::makeLowerCase(const OUString& aTerm, CharClass * pCC)
|
||||
{
|
||||
if (pCC)
|
||||
return pCC->lowercase(aTerm);
|
||||
return aTerm;
|
||||
}
|
||||
|
||||
#undef CAPTYPE_UNKNOWN
|
||||
#undef CAPTYPE_NOCAP
|
||||
#undef CAPTYPE_INITCAP
|
||||
#undef CAPTYPE_ALLCAP
|
||||
#undef CAPTYPE_MIXED
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <map>
|
||||
#include <unotools/charclass.hxx>
|
||||
|
||||
class LngSvcMgr;
|
||||
|
||||
@ -65,6 +66,7 @@ class SpellCheckerDispatcher :
|
||||
|
||||
LngSvcMgr &rMgr;
|
||||
mutable linguistic::SpellCache *pCache; // Spell Cache (holds known words)
|
||||
CharClass * pCharClass;
|
||||
|
||||
// disallow copy-constructor and assignment-operator for now
|
||||
SpellCheckerDispatcher(const SpellCheckerDispatcher &);
|
||||
@ -119,8 +121,13 @@ public:
|
||||
virtual DspType GetDspType() const;
|
||||
|
||||
void FlushSpellCache();
|
||||
};
|
||||
|
||||
private:
|
||||
void setCharClass(const LanguageTag& rLanguageTag);
|
||||
sal_uInt16 SAL_CALL capitalType(const OUString&, CharClass *);
|
||||
OUString SAL_CALL makeLowerCase(const OUString&, CharClass *);
|
||||
|
||||
};
|
||||
|
||||
inline linguistic::SpellCache & SpellCheckerDispatcher::GetCache() const
|
||||
{
|
||||
@ -148,7 +155,6 @@ inline ::com::sun::star::uno::Reference<
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
Loading…
x
Reference in New Issue
Block a user