cws tl82: #i113293# unify encoding detection for linguistic components

This commit is contained in:
Thomas Lange [tl] 2010-07-21 16:29:56 +02:00
parent 16ae4c1524
commit c7896e24ec
10 changed files with 906 additions and 1020 deletions

View File

@ -65,7 +65,7 @@ struct HDInfo {
HyphenDict * aPtr;
OUString aName;
Locale aLoc;
rtl_TextEncoding aEnc;
rtl_TextEncoding eEnc;
CharClass * apCC;
};
@ -83,12 +83,12 @@ class Hyphenator :
>
{
Sequence< Locale > aSuppLocales;
HDInfo * aDicts;
sal_Int32 numdict;
HDInfo * aDicts;
sal_Int32 numdict;
::cppu::OInterfaceContainerHelper aEvtListeners;
Reference< XPropertyChangeListener > xPropHelper;
Reference< XMultiServiceFactory > rSMgr;
Reference< XMultiServiceFactory > rSMgr;
linguistic::PropertyHelper_Hyphen * pPropHelper;
BOOL bDisposing;
@ -108,87 +108,37 @@ public:
virtual ~Hyphenator();
// XSupportedLocales (for XHyphenator)
virtual Sequence< Locale > SAL_CALL getLocales()
throw(RuntimeException);
virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale )
throw(RuntimeException);
virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
// XHyphenator
virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL
hyphenate( const ::rtl::OUString& aWord,
const ::com::sun::star::lang::Locale& aLocale,
sal_Int16 nMaxLeading,
const ::com::sun::star::beans::PropertyValues& aProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL
queryAlternativeSpelling( const ::rtl::OUString& aWord,
const ::com::sun::star::lang::Locale& aLocale,
sal_Int16 nIndex,
const ::com::sun::star::beans::PropertyValues& aProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XPossibleHyphens > SAL_CALL
createPossibleHyphens( const ::rtl::OUString& aWord,
const ::com::sun::star::lang::Locale& aLocale,
const ::com::sun::star::beans::PropertyValues& aProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL hyphenate( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nMaxLeading, const ::com::sun::star::beans::PropertyValues& aProperties ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL queryAlternativeSpelling( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nIndex, const ::com::sun::star::beans::PropertyValues& aProperties ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XPossibleHyphens > SAL_CALL createPossibleHyphens( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, const ::com::sun::star::beans::PropertyValues& aProperties ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
// XLinguServiceEventBroadcaster
virtual sal_Bool SAL_CALL
addLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL
removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
// XServiceDisplayName
virtual OUString SAL_CALL
getServiceDisplayName( const Locale& rLocale )
throw(RuntimeException);
virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
// XInitialization
virtual void SAL_CALL
initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException);
virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
// XComponent
virtual void SAL_CALL
dispose()
throw(RuntimeException);
virtual void SAL_CALL
addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException);
virtual void SAL_CALL
removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException);
////////////////////////////////////////////////////////////
// Service specific part
//
virtual void SAL_CALL dispose() throw(RuntimeException);
virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
// XServiceInfo
virtual OUString SAL_CALL
getImplementationName()
throw(RuntimeException);
virtual sal_Bool SAL_CALL
supportsService( const OUString& rServiceName )
throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL
getSupportedServiceNames()
throw(RuntimeException);
virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
static inline OUString
getImplementationName_Static() throw();
static Sequence< OUString >
getSupportedServiceNames_Static() throw();
static inline OUString getImplementationName_Static() throw();
static Sequence< OUString > getSupportedServiceNames_Static() throw();
private:

21
lingucomponent/source/lingutil/lingutil.cxx Normal file → Executable file
View File

@ -50,6 +50,7 @@
#include <unotools/pathoptions.hxx>
#include <rtl/ustring.hxx>
#include <rtl/string.hxx>
#include <rtl/tencinfo.h>
#include <linguistic/misc.hxx>
#include <set>
@ -268,5 +269,25 @@ void MergeNewStyleDicsAndOldStyleDics(
}
}
rtl_TextEncoding getTextEncodingFromCharset(const sal_Char* pCharset)
{
// default result: used to indicate that we failed to get the proper encoding
rtl_TextEncoding eRet = RTL_TEXTENCODING_DONTKNOW;
if (pCharset)
{
eRet = rtl_getTextEncodingFromMimeCharset(pCharset);
if (eRet == RTL_TEXTENCODING_DONTKNOW)
eRet = rtl_getTextEncodingFromUnixCharset(pCharset);
if (eRet == RTL_TEXTENCODING_DONTKNOW)
{
if (strcmp("ISCII-DEVANAGARI", pCharset) == 0)
eRet = RTL_TEXTENCODING_ISCII_DEVANAGARI;
}
}
return eRet;
}
//////////////////////////////////////////////////////////////////////

View File

@ -101,5 +101,13 @@ void MergeNewStyleDicsAndOldStyleDics( std::list< SvtLinguConfigDictionaryEntry
///////////////////////////////////////////////////////////////////////////
//Find an encoding from a charset string, using
//rtl_getTextEncodingFromMimeCharset and falling back to
//rtl_getTextEncodingFromUnixCharset with the addition of
//ISCII-DEVANAGARI. On failure will return final fallback of
//RTL_TEXTENCODING_ISO_8859_1
rtl_TextEncoding getTextEncodingFromCharset(const sal_Char* pCharset);
#endif

View File

@ -75,14 +75,14 @@ class MacSpellChecker :
XServiceDisplayName
>
{
Sequence< Locale > aSuppLocales;
Sequence< Locale > aSuppLocales;
// Hunspell ** aDicts;
rtl_TextEncoding * aDEncs;
Locale * aDLocs;
OUString * aDNames;
sal_Int32 numdict;
NSSpellChecker * macSpell;
int macTag; //unique tag for this doc
rtl_TextEncoding * aDEncs;
Locale * aDLocs;
OUString * aDNames;
sal_Int32 numdict;
NSSpellChecker * macSpell;
int macTag; //unique tag for this doc
::cppu::OInterfaceContainerHelper aEvtListeners;
Reference< XPropertyChangeListener > xPropHelper;
@ -100,84 +100,43 @@ class MacSpellChecker :
}
INT16 GetSpellFailure( const OUString &rWord, const Locale &rLocale );
Reference< XSpellAlternatives >
GetProposals( const OUString &rWord, const Locale &rLocale );
Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
public:
MacSpellChecker();
virtual ~MacSpellChecker();
// XSupportedLocales (for XSpellChecker)
virtual Sequence< Locale > SAL_CALL
getLocales()
throw(RuntimeException);
virtual sal_Bool SAL_CALL
hasLocale( const Locale& rLocale )
throw(RuntimeException);
virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
// XSpellChecker
virtual sal_Bool SAL_CALL
isValid( const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties )
throw(IllegalArgumentException,
RuntimeException);
virtual Reference< XSpellAlternatives > SAL_CALL
spell( const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties )
throw(IllegalArgumentException,
RuntimeException);
virtual sal_Bool SAL_CALL isValid( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
virtual Reference< XSpellAlternatives > SAL_CALL spell( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
// XLinguServiceEventBroadcaster
virtual sal_Bool SAL_CALL
addLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL
removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
// XServiceDisplayName
virtual OUString SAL_CALL
getServiceDisplayName( const Locale& rLocale )
throw(RuntimeException);
virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
// XInitialization
virtual void SAL_CALL
initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException);
virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
// XComponent
virtual void SAL_CALL
dispose()
throw(RuntimeException);
virtual void SAL_CALL
addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException);
virtual void SAL_CALL
removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException);
////////////////////////////////////////////////////////////
// Service specific part
//
virtual void SAL_CALL dispose() throw(RuntimeException);
virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
// XServiceInfo
virtual OUString SAL_CALL
getImplementationName()
throw(RuntimeException);
virtual sal_Bool SAL_CALL
supportsService( const OUString& rServiceName )
throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL
getSupportedServiceNames()
throw(RuntimeException);
virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
static inline OUString
getImplementationName_Static() throw();
static Sequence< OUString >
getSupportedServiceNames_Static() throw();
static inline OUString getImplementationName_Static() throw();
static Sequence< OUString > getSupportedServiceNames_Static() throw();
};
inline OUString MacSpellChecker::getImplementationName_Static() throw()

296
lingucomponent/source/spellcheck/spell/sspellimp.cxx Normal file → Executable file
View File

@ -27,6 +27,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_lingucomponent.hxx"
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
@ -37,12 +38,10 @@
#include <unotools/processfactory.hxx>
#include <osl/mutex.hxx>
#include <lingutil.hxx>
#include <hunspell.hxx>
#include <dictmgr.hxx>
#ifndef _SPELLIMP_HXX
#include <sspellimp.hxx>
#endif
#include <linguistic/lngprops.hxx>
#include <linguistic/spelldta.hxx>
@ -53,8 +52,6 @@
#include <osl/file.hxx>
#include <rtl/ustrbuf.hxx>
#include <lingutil.hxx>
#include <list>
#include <set>
#include <string.h>
@ -77,35 +74,37 @@ using namespace linguistic;
SpellChecker::SpellChecker() :
aEvtListeners ( GetLinguMutex() )
{
aDicts = NULL;
aDicts = NULL;
aDEncs = NULL;
aDLocs = NULL;
aDNames = NULL;
bDisposing = FALSE;
pPropHelper = NULL;
numdict = 0;
numdict = 0;
}
SpellChecker::~SpellChecker()
{
if (aDicts) {
for (int i = 0; i < numdict; i++) {
if (aDicts)
{
for (int i = 0; i < numdict; i++)
{
if (aDicts[i]) delete aDicts[i];
aDicts[i] = NULL;
}
delete[] aDicts;
}
aDicts = NULL;
numdict = 0;
if (aDEncs) delete[] aDEncs;
aDEncs = NULL;
if (aDLocs) delete[] aDLocs;
aDLocs = NULL;
if (aDNames) delete[] aDNames;
aDNames = NULL;
if (pPropHelper)
pPropHelper->RemoveAsPropListener();
}
delete[] aDicts;
}
aDicts = NULL;
numdict = 0;
if (aDEncs) delete[] aDEncs;
aDEncs = NULL;
if (aDLocs) delete[] aDLocs;
aDLocs = NULL;
if (aDNames) delete[] aDNames;
aDNames = NULL;
if (pPropHelper)
pPropHelper->RemoveAsPropListener();
}
@ -217,7 +216,7 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
for (sal_Int32 i = 0; i < nLocales; ++i)
{
aDicts[k] = NULL;
aDEncs[k] = 0;
aDEncs[k] = RTL_TEXTENCODING_DONTKNOW;
aDLocs[k] = MsLangId::convertLanguageToLocale(
MsLangId::convertIsoStringToLanguage( aLocaleNames[i] ));
// also both files have to be in the same directory and the
@ -272,84 +271,86 @@ sal_Bool SAL_CALL SpellChecker::hasLocale(const Locale& rLocale)
return bRes;
}
INT16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocale )
{
Hunspell * pMS;
rtl_TextEncoding aEnc;
Hunspell * pMS = NULL;
rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
// initialize a myspell object for each dictionary once
// (note: mutex is held higher up in isValid)
// (note: mutex is held higher up in isValid)
INT16 nRes = -1;
// first handle smart quotes both single and double
// first handle smart quotes both single and double
OUStringBuffer rBuf(rWord);
sal_Int32 n = rBuf.getLength();
sal_Unicode c;
for (sal_Int32 ix=0; ix < n; ix++) {
sal_Int32 n = rBuf.getLength();
sal_Unicode c;
for (sal_Int32 ix=0; ix < n; ix++)
{
c = rBuf.charAt(ix);
if ((c == 0x201C) || (c == 0x201D)) rBuf.setCharAt(ix,(sal_Unicode)0x0022);
if ((c == 0x2018) || (c == 0x2019)) rBuf.setCharAt(ix,(sal_Unicode)0x0027);
}
OUString nWord(rBuf.makeStringAndClear());
if ((c == 0x201C) || (c == 0x201D))
rBuf.setCharAt(ix,(sal_Unicode)0x0022);
if ((c == 0x2018) || (c == 0x2019))
rBuf.setCharAt(ix,(sal_Unicode)0x0027);
}
OUString nWord(rBuf.makeStringAndClear());
if (n)
{
for (sal_Int32 i = 0; i < numdict; ++i) {
for (sal_Int32 i = 0; i < numdict; ++i)
{
pMS = NULL;
aEnc = 0;
eEnc = RTL_TEXTENCODING_DONTKNOW;
if (rLocale == aDLocs[i])
{
if (!aDicts[i])
{
OUString dicpath = aDNames[i] + A2OU(".dic");
OUString affpath = aDNames[i] + A2OU(".aff");
OUString dict;
OUString aff;
osl::FileBase::getSystemPathFromFileURL(dicpath,dict);
osl::FileBase::getSystemPathFromFileURL(affpath,aff);
OString aTmpaff(OU2ENC(aff,osl_getThreadTextEncoding()));
OString aTmpdict(OU2ENC(dict,osl_getThreadTextEncoding()));
if (!aDicts[i])
{
OUString dicpath = aDNames[i] + A2OU(".dic");
OUString affpath = aDNames[i] + A2OU(".aff");
OUString dict;
OUString aff;
osl::FileBase::getSystemPathFromFileURL(dicpath,dict);
osl::FileBase::getSystemPathFromFileURL(affpath,aff);
OString aTmpaff(OU2ENC(aff,osl_getThreadTextEncoding()));
OString aTmpdict(OU2ENC(dict,osl_getThreadTextEncoding()));
#if defined(WNT)
// workaround for Windows specifc problem that the
// path length in calls to 'fopen' is limted to somewhat
// about 120+ characters which will usually be exceed when
// using dictionaries as extensions.
aTmpaff = Win_GetShortPathName( aff );
aTmpdict = Win_GetShortPathName( dict );
// workaround for Windows specifc problem that the
// path length in calls to 'fopen' is limted to somewhat
// about 120+ characters which will usually be exceed when
// using dictionaries as extensions.
aTmpaff = Win_GetShortPathName( aff );
aTmpdict = Win_GetShortPathName( dict );
#endif
aDicts[i] = new Hunspell(aTmpaff.getStr(),aTmpdict.getStr());
aDEncs[i] = 0;
if (aDicts[i]) {
char * dic_encoding = aDicts[i]->get_dic_encoding();
aDEncs[i] = rtl_getTextEncodingFromUnixCharset(aDicts[i]->get_dic_encoding());
if (aDEncs[i] == RTL_TEXTENCODING_DONTKNOW) {
if (strcmp("ISCII-DEVANAGARI", dic_encoding) == 0) {
aDEncs[i] = RTL_TEXTENCODING_ISCII_DEVANAGARI;
} else if (strcmp("UTF-8", dic_encoding) == 0) {
aDEncs[i] = RTL_TEXTENCODING_UTF8;
}
}
}
}
pMS = aDicts[i];
aEnc = aDEncs[i];
}
aDicts[i] = new Hunspell(aTmpaff.getStr(),aTmpdict.getStr());
aDEncs[i] = RTL_TEXTENCODING_DONTKNOW;
if (aDicts[i])
aDEncs[i] = getTextEncodingFromCharset(aDicts[i]->get_dic_encoding());
}
pMS = aDicts[i];
eEnc = aDEncs[i];
}
// we don't want to work with a default text encoding since following incorrect
// results may occur only for specific text and thus may be hard to notice.
// Thus better always make a clean exit here if the text encoding is in question.
// Hopefully something not working at all will raise proper attention quickly. ;-)
DBG_ASSERT( eEnc != RTL_TEXTENCODING_DONTKNOW, "failed to get text encoding! (maybe incorrect encoding string in file)" );
if (eEnc == RTL_TEXTENCODING_DONTKNOW)
return -1;
if (pMS)
{
OString aWrd(OU2ENC(nWord,aEnc));
{
OString aWrd(OU2ENC(nWord,eEnc));
int rVal = pMS->spell((char*)aWrd.getStr());
if (rVal != 1)
{
nRes = SpellFailure::SPELLING_ERROR;
} else {
return -1;
}
pMS = NULL;
if (rVal != 1)
nRes = SpellFailure::SPELLING_ERROR;
else
return -1;
pMS = NULL;
}
}
}
@ -358,8 +359,7 @@ INT16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocal
}
sal_Bool SAL_CALL
SpellChecker::isValid( const OUString& rWord, const Locale& rLocale,
sal_Bool SAL_CALL SpellChecker::isValid( const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties )
throw(IllegalArgumentException, RuntimeException)
{
@ -390,11 +390,11 @@ sal_Bool SAL_CALL
{
INT16 nLang = LocaleToLanguage( rLocale );
// postprocess result for errors that should be ignored
if ( (!rHelper.IsSpellUpperCase() && IsUpper( rWord, nLang ))
|| (!rHelper.IsSpellWithDigits() && HasDigits( rWord ))
|| (!rHelper.IsSpellCapitalization()
&& nFailure == SpellFailure::CAPTION_ERROR)
)
const bool bIgnoreError =
(!rHelper.IsSpellUpperCase() && IsUpper( rWord, nLang )) ||
(!rHelper.IsSpellWithDigits() && HasDigits( rWord )) ||
(!rHelper.IsSpellCapitalization() && nFailure == SpellFailure::CAPTION_ERROR);
if (bIgnoreError)
nFailure = -1;
}
@ -410,23 +410,26 @@ Reference< XSpellAlternatives >
// Especially it may give a list of suggested (correct) words:
Reference< XSpellAlternatives > xRes;
// note: mutex is held by higher up by spell which covers both
// note: mutex is held by higher up by spell which covers both
Hunspell* pMS;
rtl_TextEncoding aEnc;
int count;
int numsug = 0;
Hunspell* pMS = NULL;
rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
int count = 0;
int numsug = 0;
// first handle smart quotes (single and double)
// first handle smart quotes (single and double)
OUStringBuffer rBuf(rWord);
sal_Int32 n = rBuf.getLength();
sal_Unicode c;
for (sal_Int32 ix=0; ix < n; ix++) {
c = rBuf.charAt(ix);
if ((c == 0x201C) || (c == 0x201D)) rBuf.setCharAt(ix,(sal_Unicode)0x0022);
if ((c == 0x2018) || (c == 0x2019)) rBuf.setCharAt(ix,(sal_Unicode)0x0027);
}
OUString nWord(rBuf.makeStringAndClear());
sal_Int32 n = rBuf.getLength();
sal_Unicode c;
for (sal_Int32 ix=0; ix < n; ix++)
{
c = rBuf.charAt(ix);
if ((c == 0x201C) || (c == 0x201D))
rBuf.setCharAt(ix,(sal_Unicode)0x0022);
if ((c == 0x2018) || (c == 0x2019))
rBuf.setCharAt(ix,(sal_Unicode)0x0027);
}
OUString nWord(rBuf.makeStringAndClear());
if (n)
{
@ -434,59 +437,57 @@ Reference< XSpellAlternatives >
Sequence< OUString > aStr( 0 );
for (int i =0; i < numdict; i++) {
for (int i =0; i < numdict; i++)
{
pMS = NULL;
aEnc = 0;
count = 0;
eEnc = RTL_TEXTENCODING_DONTKNOW;
count = 0;
if (rLocale == aDLocs[i])
{
pMS = aDicts[i];
aEnc = aDEncs[i];
}
pMS = aDicts[i];
eEnc = aDEncs[i];
}
if (pMS)
{
char ** suglst = NULL;
OString aWrd(OU2ENC(nWord,aEnc));
count = pMS->suggest(&suglst, (const char *) aWrd.getStr());
OString aWrd(OU2ENC(nWord,eEnc));
count = pMS->suggest(&suglst, (const char *) aWrd.getStr());
if (count) {
aStr.realloc( numsug + count );
OUString *pStr = aStr.getArray();
for (int ii=0; ii < count; ii++)
{
// if needed add: if (suglst[ii] == NULL) continue;
OUString cvtwrd(suglst[ii],strlen(suglst[ii]),aEnc);
pStr[numsug + ii] = cvtwrd;
free(suglst[ii]);
}
free(suglst);
numsug += count;
if (count)
{
aStr.realloc( numsug + count );
OUString *pStr = aStr.getArray();
for (int ii=0; ii < count; ii++)
{
// if needed add: if (suglst[ii] == NULL) continue;
OUString cvtwrd(suglst[ii],strlen(suglst[ii]),eEnc);
pStr[numsug + ii] = cvtwrd;
free(suglst[ii]);
}
}
free(suglst);
numsug += count;
}
}
}
// now return an empty alternative for no suggestions or the list of alternatives if some found
// now return an empty alternative for no suggestions or the list of alternatives if some found
SpellAlternatives *pAlt = new SpellAlternatives;
String aTmp(rWord);
String aTmp(rWord);
pAlt->SetWordLanguage( aTmp, nLang );
pAlt->SetFailureType( SpellFailure::SPELLING_ERROR );
pAlt->SetAlternatives( aStr );
xRes = pAlt;
return xRes;
}
return xRes;
}
return xRes;
}
Reference< XSpellAlternatives > SAL_CALL
SpellChecker::spell( const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties )
Reference< XSpellAlternatives > SAL_CALL SpellChecker::spell(
const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties )
throw(IllegalArgumentException, RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -511,7 +512,7 @@ Reference< XSpellAlternatives > SAL_CALL
Reference< XInterface > SAL_CALL SpellChecker_CreateInstance(
const Reference< XMultiServiceFactory > & /*rSMgr*/ )
const Reference< XMultiServiceFactory > & /*rSMgr*/ )
throw(Exception)
{
@ -520,9 +521,8 @@ Reference< XInterface > SAL_CALL SpellChecker_CreateInstance(
}
sal_Bool SAL_CALL
SpellChecker::addLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
sal_Bool SAL_CALL SpellChecker::addLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -536,9 +536,8 @@ sal_Bool SAL_CALL
}
sal_Bool SAL_CALL
SpellChecker::removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
sal_Bool SAL_CALL SpellChecker::removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -553,8 +552,7 @@ sal_Bool SAL_CALL
}
OUString SAL_CALL
SpellChecker::getServiceDisplayName( const Locale& /*rLocale*/ )
OUString SAL_CALL SpellChecker::getServiceDisplayName( const Locale& /*rLocale*/ )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -562,8 +560,7 @@ OUString SAL_CALL
}
void SAL_CALL
SpellChecker::initialize( const Sequence< Any >& rArguments )
void SAL_CALL SpellChecker::initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -585,16 +582,15 @@ void SAL_CALL
xPropHelper = pPropHelper;
pPropHelper->AddAsPropListener(); //! after a reference is established
}
else {
else
{
DBG_ERROR( "wrong number of arguments in sequence" );
}
}
}
void SAL_CALL
SpellChecker::dispose()
void SAL_CALL SpellChecker::dispose()
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -608,8 +604,7 @@ void SAL_CALL
}
void SAL_CALL
SpellChecker::addEventListener( const Reference< XEventListener >& rxListener )
void SAL_CALL SpellChecker::addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -619,8 +614,7 @@ void SAL_CALL
}
void SAL_CALL
SpellChecker::removeEventListener( const Reference< XEventListener >& rxListener )
void SAL_CALL SpellChecker::removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );

86
lingucomponent/source/spellcheck/spell/sspellimp.hxx Normal file → Executable file
View File

@ -69,11 +69,11 @@ class SpellChecker :
>
{
Sequence< Locale > aSuppLocales;
Hunspell ** aDicts;
rtl_TextEncoding * aDEncs;
Locale * aDLocs;
OUString * aDNames;
sal_Int32 numdict;
Hunspell ** aDicts;
rtl_TextEncoding * aDEncs;
Locale * aDLocs;
OUString * aDNames;
sal_Int32 numdict;
::cppu::OInterfaceContainerHelper aEvtListeners;
Reference< XPropertyChangeListener > xPropHelper;
@ -91,84 +91,43 @@ class SpellChecker :
}
INT16 GetSpellFailure( const OUString &rWord, const Locale &rLocale );
Reference< XSpellAlternatives >
GetProposals( const OUString &rWord, const Locale &rLocale );
Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
public:
SpellChecker();
virtual ~SpellChecker();
// XSupportedLocales (for XSpellChecker)
virtual Sequence< Locale > SAL_CALL
getLocales()
throw(RuntimeException);
virtual sal_Bool SAL_CALL
hasLocale( const Locale& rLocale )
throw(RuntimeException);
virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
// XSpellChecker
virtual sal_Bool SAL_CALL
isValid( const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties )
throw(IllegalArgumentException,
RuntimeException);
virtual Reference< XSpellAlternatives > SAL_CALL
spell( const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties )
throw(IllegalArgumentException,
RuntimeException);
virtual sal_Bool SAL_CALL isValid( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
virtual Reference< XSpellAlternatives > SAL_CALL spell( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
// XLinguServiceEventBroadcaster
virtual sal_Bool SAL_CALL
addLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL
removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
// XServiceDisplayName
virtual OUString SAL_CALL
getServiceDisplayName( const Locale& rLocale )
throw(RuntimeException);
virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
// XInitialization
virtual void SAL_CALL
initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException);
virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
// XComponent
virtual void SAL_CALL
dispose()
throw(RuntimeException);
virtual void SAL_CALL
addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException);
virtual void SAL_CALL
removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException);
////////////////////////////////////////////////////////////
// Service specific part
//
virtual void SAL_CALL dispose() throw(RuntimeException);
virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
// XServiceInfo
virtual OUString SAL_CALL
getImplementationName()
throw(RuntimeException);
virtual sal_Bool SAL_CALL
supportsService( const OUString& rServiceName )
throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL
getSupportedServiceNames()
throw(RuntimeException);
virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
static inline OUString
getImplementationName_Static() throw();
static Sequence< OUString >
getSupportedServiceNames_Static() throw();
static inline OUString getImplementationName_Static() throw();
static Sequence< OUString > getSupportedServiceNames_Static() throw();
};
inline OUString SpellChecker::getImplementationName_Static() throw()
@ -177,7 +136,6 @@ inline OUString SpellChecker::getImplementationName_Static() throw()
}
///////////////////////////////////////////////////////////////////////////
#endif

22
lingucomponent/source/thesaurus/libnth/nthesdta.hxx Normal file → Executable file
View File

@ -48,11 +48,11 @@ class Meaning :
{
::com::sun::star::uno::Sequence< ::rtl::OUString > aSyn; // list of synonyms, may be empty.
::rtl::OUString aTerm;
INT16 nLanguage;
INT16 nLanguage;
#if 0
// this is for future use by a German thesaurus
BOOL bIsGermanPreReform;
BOOL bIsGermanPreReform;
#endif
// disallow copy-constructor and assignment-operator for now
@ -68,22 +68,12 @@ public:
virtual ~Meaning();
// XMeaning
virtual ::rtl::OUString SAL_CALL
getMeaning()
throw(::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
querySynonyms()
throw(::com::sun::star::uno::RuntimeException);
virtual ::rtl::OUString SAL_CALL getMeaning() throw(::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL querySynonyms() throw(::com::sun::star::uno::RuntimeException);
// non-interface specific functions
void SetSynonyms(
const ::com::sun::star::uno::Sequence< ::rtl::OUString >
&rSyn );
void SetMeaning(const ::rtl::OUString &rTerm );
void SetSynonyms( const ::com::sun::star::uno::Sequence< ::rtl::OUString > &rSyn );
void SetMeaning( const ::rtl::OUString &rTerm );
};

446
lingucomponent/source/thesaurus/libnth/nthesimp.cxx Normal file → Executable file
View File

@ -28,9 +28,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_lingucomponent.hxx"
// include <stdio.h>
#include <com/sun/star/uno/Reference.h>
#include <cppuhelper/factory.hxx> // helper for factories
#include <com/sun/star/registry/XRegistryKey.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
@ -100,23 +98,27 @@ Thesaurus::Thesaurus() :
aTEncs = NULL;
aTLocs = NULL;
aTNames = NULL;
numthes = 0;
numthes = 0;
}
Thesaurus::~Thesaurus()
{
if (aThes) {
for (int i = 0; i < numthes; i++) {
if (aThes)
{
for (int i = 0; i < numthes; i++)
{
if (aThes[i]) delete aThes[i];
aThes[i] = NULL;
}
delete[] aThes;
}
aThes = NULL;
if (aCharSetInfo) {
for (int i = 0; i < numthes; i++) {
if (aCharSetInfo)
{
for (int i = 0; i < numthes; i++)
{
if (aCharSetInfo[i]) delete aCharSetInfo[i];
aCharSetInfo[i] = NULL;
}
@ -244,7 +246,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
for (sal_Int32 i = 0; i < nLocales; ++i)
{
aThes[k] = NULL;
aTEncs[k] = 0;
aTEncs[k] = RTL_TEXTENCODING_DONTKNOW;
aTLocs[k] = MsLangId::convertLanguageToLocale(
MsLangId::convertIsoStringToLanguage( aDictIt->aLocaleNames[i] ));
aCharSetInfo[k] = new CharClass( aTLocs[k] );
@ -302,28 +304,28 @@ sal_Bool SAL_CALL Thesaurus::hasLocale(const Locale& rLocale)
}
Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
Thesaurus::queryMeanings( const OUString& qTerm, const Locale& rLocale,
const PropertyValues& rProperties)
throw(IllegalArgumentException, RuntimeException)
Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryMeanings(
const OUString& qTerm, const Locale& rLocale,
const PropertyValues& rProperties)
throw(IllegalArgumentException, RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
MutexGuard aGuard( GetLinguMutex() );
uno::Sequence< Reference< XMeaning > > aMeanings( 1 );
uno::Sequence< Reference< XMeaning > > noMeanings( 0 );
uno::Reference< XLinguServiceManager > xLngSvcMgr( GetLngSvcMgr_Impl() );
uno::Reference< XSpellChecker1 > xSpell;
uno::Sequence< Reference< XMeaning > > aMeanings( 1 );
uno::Sequence< Reference< XMeaning > > noMeanings( 0 );
uno::Reference< XLinguServiceManager > xLngSvcMgr( GetLngSvcMgr_Impl() );
uno::Reference< XSpellChecker1 > xSpell;
OUString rTerm(qTerm);
OUString pTerm(qTerm);
sal_uInt16 ct = CAPTYPE_UNKNOWN;
sal_Int32 stem = 0;
sal_Int32 stem2 = 0;
OUString rTerm(qTerm);
OUString pTerm(qTerm);
sal_uInt16 ct = CAPTYPE_UNKNOWN;
sal_Int32 stem = 0;
sal_Int32 stem2 = 0;
INT16 nLanguage = LocaleToLanguage( rLocale );
INT16 nLanguage = LocaleToLanguage( rLocale );
if (nLanguage == LANGUAGE_NONE || !rTerm.getLength())
return noMeanings;
if (nLanguage == LANGUAGE_NONE || !rTerm.getLength())
return noMeanings;
if (!hasLocale( rLocale ))
#ifdef LINGU_EXCEPTIONS
@ -332,195 +334,202 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
return noMeanings;
#endif
if (prevTerm == qTerm && prevLocale == nLanguage) return prevMeanings;
if (prevTerm == qTerm && prevLocale == nLanguage)
return prevMeanings;
mentry * pmean = NULL;
mentry * pmean = NULL;
sal_Int32 nmean = 0;
PropertyHelper_Thes &rHelper = GetPropHelper();
rHelper.SetTmpPropVals( rProperties );
PropertyHelper_Thes &rHelper = GetPropHelper();
rHelper.SetTmpPropVals( rProperties );
MyThes * pTH = NULL;
rtl_TextEncoding aEnc = 0;
CharClass * pCC = NULL;
MyThes * pTH = NULL;
rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
CharClass * pCC = NULL;
// find the first thesaurus that matches the locale
for (int i =0; i < numthes; i++) {
if (rLocale == aTLocs[i])
// find the first thesaurus that matches the locale
for (int i =0; i < numthes; i++)
{
if (rLocale == aTLocs[i])
{
// open up and intialize this thesaurus if need be
if (!aThes[i])
{
// open up and intialize this thesaurus if need be
if (!aThes[i])
{
OUString datpath = aTNames[i] + A2OU(".dat");
OUString idxpath = aTNames[i] + A2OU(".idx");
OUString ndat;
OUString nidx;
osl::FileBase::getSystemPathFromFileURL(datpath,ndat);
osl::FileBase::getSystemPathFromFileURL(idxpath,nidx);
OString aTmpidx(OU2ENC(nidx,osl_getThreadTextEncoding()));
OString aTmpdat(OU2ENC(ndat,osl_getThreadTextEncoding()));
OUString datpath = aTNames[i] + A2OU(".dat");
OUString idxpath = aTNames[i] + A2OU(".idx");
OUString ndat;
OUString nidx;
osl::FileBase::getSystemPathFromFileURL(datpath,ndat);
osl::FileBase::getSystemPathFromFileURL(idxpath,nidx);
OString aTmpidx(OU2ENC(nidx,osl_getThreadTextEncoding()));
OString aTmpdat(OU2ENC(ndat,osl_getThreadTextEncoding()));
#if defined(WNT)
// workaround for Windows specifc problem that the
// path length in calls to 'fopen' is limted to somewhat
// about 120+ characters which will usually be exceed when
// using dictionaries as extensions.
aTmpidx = Win_GetShortPathName( nidx );
aTmpdat = Win_GetShortPathName( ndat );
// workaround for Windows specifc problem that the
// path length in calls to 'fopen' is limted to somewhat
// about 120+ characters which will usually be exceed when
// using dictionaries as extensions.
aTmpidx = Win_GetShortPathName( nidx );
aTmpdat = Win_GetShortPathName( ndat );
#endif
aThes[i] = new MyThes(aTmpidx.getStr(),aTmpdat.getStr());
if (aThes[i]) {
const char * enc_string = aThes[i]->get_th_encoding();
if (!enc_string) {
aTEncs[i] = rtl_getTextEncodingFromUnixCharset("ISO8859-1");
} else {
aTEncs[i] = rtl_getTextEncodingFromUnixCharset(enc_string);
if (aTEncs[i] == RTL_TEXTENCODING_DONTKNOW) {
if (strcmp("ISCII-DEVANAGARI", enc_string) == 0) {
aTEncs[i] = RTL_TEXTENCODING_ISCII_DEVANAGARI;
} else if (strcmp("UTF-8", enc_string) == 0) {
aTEncs[i] = RTL_TEXTENCODING_UTF8;
}
}
}
}
}
pTH = aThes[i];
aEnc = aTEncs[i];
pCC = aCharSetInfo[i];
aThes[i] = new MyThes(aTmpidx.getStr(),aTmpdat.getStr());
if (aThes[i])
aTEncs[i] = getTextEncodingFromCharset(aThes[i]->get_th_encoding());
}
pTH = aThes[i];
eEnc = aTEncs[i];
pCC = aCharSetInfo[i];
if (pTH)
break;
if (pTH)
break;
}
}
while (pTH) {
// convert word to all lower case for searching
if (!stem) ct = capitalType(rTerm, pCC);
OUString nTerm(makeLowerCase(rTerm, pCC));
OString aTmp( OU2ENC(nTerm, aEnc) );
nmean = pTH->Lookup(aTmp.getStr(),aTmp.getLength(),&pmean);
// we don't want to work with a default text encoding since following incorrect
// results may occur only for specific text and thus may be hard to notice.
// Thus better always make a clean exit here if the text encoding is in question.
// Hopefully something not working at all will raise proper attention quickly. ;-)
DBG_ASSERT( eEnc != RTL_TEXTENCODING_DONTKNOW, "failed to get text encoding! (maybe incorrect encoding string in file)" );
if (eEnc == RTL_TEXTENCODING_DONTKNOW)
return noMeanings;
if (nmean) aMeanings.realloc( nmean );
while (pTH)
{
// convert word to all lower case for searching
if (!stem)
ct = capitalType(rTerm, pCC);
OUString nTerm(makeLowerCase(rTerm, pCC));
OString aTmp( OU2ENC(nTerm, eEnc) );
nmean = pTH->Lookup(aTmp.getStr(),aTmp.getLength(),&pmean);
mentry * pe = pmean;
OUString codeTerm = qTerm;
Reference< XSpellAlternatives > xTmpRes2;
if (nmean)
aMeanings.realloc( nmean );
if (stem) {
xTmpRes2 = xSpell->spell( A2OU("<?xml?><query type='analyze'><word>") +
mentry * pe = pmean;
OUString codeTerm = qTerm;
Reference< XSpellAlternatives > xTmpRes2;
if (stem)
{
xTmpRes2 = xSpell->spell( A2OU("<?xml?><query type='analyze'><word>") +
pTerm + A2OU("</word></query>"), nLanguage, rProperties );
if (xTmpRes2.is()) {
Sequence<OUString>seq = xTmpRes2->getAlternatives();
if (seq.getLength() > 0) {
if (xTmpRes2.is())
{
Sequence<OUString>seq = xTmpRes2->getAlternatives();
if (seq.getLength() > 0)
{
codeTerm = seq[0];
stem2 = 1;
}
}
#if 0
OString o = OUStringToOString(codeTerm, rtl_getTextEncodingFromUnixCharset("UTF-8"));
fprintf(stderr, "CODETERM: %s\n", o.pData->buffer);
OString o = OUStringToOString(codeTerm, RTL_TEXTENCODING_UTF8);
fprintf(stderr, "CODETERM: %s\n", o.pData->buffer);
#endif
}
}
}
}
for (int j = 0; j < nmean; j++) {
int count = pe->count;
if (count) {
Sequence< OUString > aStr( count );
OUString *pStr = aStr.getArray();
for (int j = 0; j < nmean; j++)
{
int count = pe->count;
if (count)
{
Sequence< OUString > aStr( count );
OUString *pStr = aStr.getArray();
for (int i=0; i < count; i++) {
OUString sTerm(pe->psyns[i],strlen(pe->psyns[i]),aEnc );
sal_Int32 catpos = sTerm.indexOf('(');
sal_Int32 catpos2 = 0;
OUString catst;
OUString catst2;
if (catpos > 2) {
// remove category name for affixation and casing
catst = A2OU(" ") + sTerm.copy(catpos);
sTerm = sTerm.copy(0, catpos);
sTerm = sTerm.trim();
}
// generate synonyms with affixes
if (stem && stem2) {
Reference< XSpellAlternatives > xTmpRes;
xTmpRes = xSpell->spell( A2OU("<?xml?><query type='generate'><word>") +
sTerm + A2OU("</word>") + codeTerm + A2OU("</query>"), nLanguage, rProperties );
if (xTmpRes.is()) {
Sequence<OUString>seq = xTmpRes->getAlternatives();
for (int k = 0; k < seq.getLength(); k++) {
OString o = OUStringToOString(seq[k], rtl_getTextEncodingFromUnixCharset("UTF-8"));
}
if (seq.getLength() > 0) sTerm = seq[0];
}
}
if (catpos2) sTerm = catst2 + sTerm;
for (int i=0; i < count; i++)
{
OUString sTerm(pe->psyns[i],strlen(pe->psyns[i]),eEnc );
sal_Int32 catpos = sTerm.indexOf('(');
sal_Int32 catpos2 = 0;
OUString catst;
OUString catst2;
if (catpos > 2)
{
// remove category name for affixation and casing
catst = A2OU(" ") + sTerm.copy(catpos);
sTerm = sTerm.copy(0, catpos);
sTerm = sTerm.trim();
}
// generate synonyms with affixes
if (stem && stem2)
{
Reference< XSpellAlternatives > xTmpRes;
xTmpRes = xSpell->spell( A2OU("<?xml?><query type='generate'><word>") +
sTerm + A2OU("</word>") + codeTerm + A2OU("</query>"), nLanguage, rProperties );
if (xTmpRes.is())
{
Sequence<OUString>seq = xTmpRes->getAlternatives();
if (seq.getLength() > 0)
sTerm = seq[0];
}
}
if (catpos2)
sTerm = catst2 + sTerm;
sal_uInt16 ct1 = capitalType(sTerm, pCC);
if (CAPTYPE_MIXED == ct1)
ct = ct1;
OUString cTerm;
switch (ct) {
case CAPTYPE_ALLCAP:
{
cTerm = makeUpperCase(sTerm, pCC);
break;
}
case CAPTYPE_INITCAP:
{
cTerm = makeInitCap(sTerm, pCC);
break;
}
default:
{
cTerm = sTerm;
break;
}
}
OUString aAlt( cTerm + catst);
pStr[i] = aAlt;
}
sal_uInt16 ct1 = capitalType(sTerm, pCC);
if (CAPTYPE_MIXED == ct1)
ct = ct1;
OUString cTerm;
switch (ct)
{
case CAPTYPE_ALLCAP:
cTerm = makeUpperCase(sTerm, pCC);
break;
case CAPTYPE_INITCAP:
cTerm = makeInitCap(sTerm, pCC);
break;
default:
cTerm = sTerm;
break;
}
OUString aAlt( cTerm + catst);
pStr[i] = aAlt;
}
#if 0
Meaning * pMn = new Meaning(rTerm,nLanguage,rHelper);
Meaning * pMn = new Meaning(rTerm,nLanguage,rHelper);
#endif
Meaning * pMn = new Meaning(rTerm,nLanguage);
OUString dTerm(pe->defn,strlen(pe->defn),aEnc );
pMn->SetMeaning(dTerm);
pMn->SetSynonyms(aStr);
Reference<XMeaning>* pMeaning = aMeanings.getArray();
pMeaning[j] = pMn;
}
pe++;
}
pTH->CleanUpAfterLookup(&pmean,nmean);
Meaning * pMn = new Meaning(rTerm,nLanguage);
OUString dTerm(pe->defn,strlen(pe->defn),eEnc );
pMn->SetMeaning(dTerm);
pMn->SetSynonyms(aStr);
Reference<XMeaning>* pMeaning = aMeanings.getArray();
pMeaning[j] = pMn;
}
pe++;
}
pTH->CleanUpAfterLookup(&pmean,nmean);
if (nmean) {
if (nmean)
{
prevTerm = qTerm;
prevMeanings = aMeanings;
prevLocale = nLanguage;
return aMeanings;
}
}
if (stem || !xLngSvcMgr.is()) return noMeanings;
if (stem || !xLngSvcMgr.is())
return noMeanings;
stem = 1;
xSpell = uno::Reference< XSpellChecker1 >( xLngSvcMgr->getSpellChecker(), UNO_QUERY );
if (!xSpell.is() || !xSpell->isValid( A2OU(SPELLML_SUPPORT), nLanguage, rProperties )) {
if (!xSpell.is() || !xSpell->isValid( A2OU(SPELLML_SUPPORT), nLanguage, rProperties ))
return noMeanings;
}
Reference< XSpellAlternatives > xTmpRes;
xTmpRes = xSpell->spell( A2OU("<?xml?><query type='stem'><word>") +
rTerm + A2OU("</word></query>"), nLanguage, rProperties );
if (xTmpRes.is()) {
if (xTmpRes.is())
{
Sequence<OUString>seq = xTmpRes->getAlternatives();
#if 0
for (int i = 0; i < seq.getLength(); i++) {
OString o = OUStringToOString(seq[i], rtl_getTextEncodingFromUnixCharset("UTF-8"));
for (int i = 0; i < seq.getLength(); i++)
{
OString o = OUStringToOString(seq[i], RTL_TEXTENCODING_UTF8);
fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer);
}
#endif
if (seq.getLength() > 0) {
if (seq.getLength() > 0)
{
rTerm = seq[0]; // XXX Use only the first stem
continue;
}
@ -529,17 +538,21 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
// stem the last word of the synonym (for categories after affixation)
rTerm = rTerm.trim();
sal_Int32 pos = rTerm.lastIndexOf(' ');
if (!pos) return noMeanings;
if (!pos)
return noMeanings;
xTmpRes = xSpell->spell( A2OU("<?xml?><query type='stem'><word>") +
rTerm.copy(pos + 1) + A2OU("</word></query>"), nLanguage, rProperties );
if (xTmpRes.is()) {
if (xTmpRes.is())
{
Sequence<OUString>seq = xTmpRes->getAlternatives();
if (seq.getLength() > 0) {
if (seq.getLength() > 0)
{
pTerm = rTerm.copy(pos + 1);
rTerm = rTerm.copy(0, pos + 1) + seq[0];
#if 0
for (int i = 0; i < seq.getLength(); i++) {
OString o = OUStringToOString(seq[i], rtl_getTextEncodingFromUnixCharset("UTF-8"));
#if 0
for (int i = 0; i < seq.getLength(); i++)
{
OString o = OUStringToOString(seq[i], RTL_TEXTENCODING_UTF8);
fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer);
}
#endif
@ -547,12 +560,11 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
}
}
break;
}
}
return noMeanings;
}
Reference< XInterface > SAL_CALL Thesaurus_CreateInstance(
const Reference< XMultiServiceFactory > & /*rSMgr*/ )
throw(Exception)
@ -562,8 +574,7 @@ Reference< XInterface > SAL_CALL Thesaurus_CreateInstance(
}
OUString SAL_CALL
Thesaurus::getServiceDisplayName( const Locale& /*rLocale*/ )
OUString SAL_CALL Thesaurus::getServiceDisplayName( const Locale& /*rLocale*/ )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -571,8 +582,7 @@ OUString SAL_CALL
}
void SAL_CALL
Thesaurus::initialize( const Sequence< Any >& rArguments )
void SAL_CALL Thesaurus::initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -603,24 +613,26 @@ void SAL_CALL
sal_uInt16 SAL_CALL Thesaurus::capitalType(const OUString& aTerm, CharClass * pCC)
{
sal_Int32 tlen = aTerm.getLength();
if ((pCC) && (tlen)) {
String aStr(aTerm);
sal_Int32 nc = 0;
for (USHORT tindex = 0; tindex < tlen; tindex++) {
if (pCC->getCharacterType(aStr,tindex) &
::com::sun::star::i18n::KCharacterType::UPPER) nc++;
}
if ((pCC) && (tlen))
{
String aStr(aTerm);
sal_Int32 nc = 0;
for (USHORT 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 == 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;
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_MIXED;
}
return (sal_uInt16) CAPTYPE_UNKNOWN;
}
@ -628,38 +640,40 @@ sal_uInt16 SAL_CALL Thesaurus::capitalType(const OUString& aTerm, CharClass * pC
OUString SAL_CALL Thesaurus::makeLowerCase(const OUString& aTerm, CharClass * pCC)
{
if (pCC)
return pCC->toLower_rtl(aTerm, 0, aTerm.getLength());
return aTerm;
if (pCC)
return pCC->toLower_rtl(aTerm, 0, aTerm.getLength());
return aTerm;
}
OUString SAL_CALL Thesaurus::makeUpperCase(const OUString& aTerm, CharClass * pCC)
{
if (pCC)
return pCC->toUpper_rtl(aTerm, 0, aTerm.getLength());
return aTerm;
if (pCC)
return pCC->toUpper_rtl(aTerm, 0, aTerm.getLength());
return aTerm;
}
OUString SAL_CALL Thesaurus::makeInitCap(const OUString& aTerm, CharClass * pCC)
{
sal_Int32 tlen = aTerm.getLength();
if ((pCC) && (tlen)) {
OUString bTemp = aTerm.copy(0,1);
if (tlen > 1)
return ( pCC->toUpper_rtl(bTemp, 0, 1)
+ pCC->toLower_rtl(aTerm,1,(tlen-1)) );
sal_Int32 tlen = aTerm.getLength();
if ((pCC) && (tlen))
{
OUString bTemp = aTerm.copy(0,1);
if (tlen > 1)
{
return ( pCC->toUpper_rtl(bTemp, 0, 1)
+ pCC->toLower_rtl(aTerm,1,(tlen-1)) );
}
return pCC->toUpper_rtl(bTemp, 0, 1);
return pCC->toUpper_rtl(bTemp, 0, 1);
}
return aTerm;
return aTerm;
}
void SAL_CALL
Thesaurus::dispose()
void SAL_CALL Thesaurus::dispose()
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -673,8 +687,7 @@ void SAL_CALL
}
void SAL_CALL
Thesaurus::addEventListener( const Reference< XEventListener >& rxListener )
void SAL_CALL Thesaurus::addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
@ -684,8 +697,7 @@ void SAL_CALL
}
void SAL_CALL
Thesaurus::removeEventListener( const Reference< XEventListener >& rxListener )
void SAL_CALL Thesaurus::removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );

53
lingucomponent/source/thesaurus/libnth/nthesimp.hxx Normal file → Executable file
View File

@ -116,55 +116,27 @@ public:
virtual ~Thesaurus();
// XSupportedLocales (for XThesaurus)
virtual Sequence< Locale > SAL_CALL
getLocales()
throw(RuntimeException);
virtual sal_Bool SAL_CALL
hasLocale( const Locale& rLocale )
throw(RuntimeException);
virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
// XThesaurus
virtual Sequence< Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
queryMeanings( const OUString& rTerm, const Locale& rLocale,
const PropertyValues& rProperties )
throw(IllegalArgumentException,
RuntimeException);
virtual Sequence< Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL queryMeanings( const OUString& rTerm, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
// XServiceDisplayName
virtual OUString SAL_CALL
getServiceDisplayName( const Locale& rLocale )
throw(RuntimeException);
virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
// XInitialization
virtual void SAL_CALL
initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException);
virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
// XComponent
virtual void SAL_CALL
dispose()
throw(RuntimeException);
virtual void SAL_CALL
addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException);
virtual void SAL_CALL
removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException);
////////////////////////////////////////////////////////////
// Service specific part
//
virtual void SAL_CALL dispose() throw(RuntimeException);
virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
// XServiceInfo
virtual OUString SAL_CALL
getImplementationName()
throw(RuntimeException);
virtual sal_Bool SAL_CALL
supportsService( const OUString& rServiceName )
throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL
getSupportedServiceNames()
throw(RuntimeException);
virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
static inline OUString
@ -183,8 +155,7 @@ private:
static ::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XSpellChecker1 > xSpell;
*/
static ::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XLinguServiceManager > GetLngSvcMgr();
static ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLinguServiceManager > GetLngSvcMgr();
};