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

@@ -32,7 +32,6 @@
#include <com/sun/star/uno/Reference.h> #include <com/sun/star/uno/Reference.h>
#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp> #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
//#include <com/sun/star/linguistic2/SpellFailure.hpp>
#include <cppuhelper/factory.hxx> // helper for factories #include <cppuhelper/factory.hxx> // helper for factories
#include <com/sun/star/registry/XRegistryKey.hpp> #include <com/sun/star/registry/XRegistryKey.hpp>
#include <i18npool/mslangid.hxx> #include <i18npool/mslangid.hxx>
@@ -43,10 +42,7 @@
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <hyphen.h> #include <hyphen.h>
#ifndef _HYPHENIMP_HXX
#include <hyphenimp.hxx> #include <hyphenimp.hxx>
#endif
#include <linguistic/hyphdta.hxx> #include <linguistic/hyphdta.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
@@ -99,7 +95,6 @@ Hyphenator::Hyphenator() :
pPropHelper = NULL; pPropHelper = NULL;
aDicts = NULL; aDicts = NULL;
numdict = 0; numdict = 0;
} }
@@ -108,8 +103,10 @@ Hyphenator::~Hyphenator()
if (pPropHelper) if (pPropHelper)
pPropHelper->RemoveAsPropListener(); pPropHelper->RemoveAsPropListener();
if ((numdict) && (aDicts)) { if ((numdict) && (aDicts))
for (int i=0; i < numdict; i++) { {
for (int i=0; i < numdict; i++)
{
if (aDicts[i].apCC) delete aDicts[i].apCC; if (aDicts[i].apCC) delete aDicts[i].apCC;
aDicts[i].apCC = NULL; aDicts[i].apCC = NULL;
} }
@@ -122,7 +119,6 @@ Hyphenator::~Hyphenator()
PropertyHelper_Hyphen & Hyphenator::GetPropHelper_Impl() PropertyHelper_Hyphen & Hyphenator::GetPropHelper_Impl()
{ {
if (!pPropHelper) if (!pPropHelper)
{ {
Reference< XPropertySet > xPropSet( GetLinguProperties(), UNO_QUERY ); Reference< XPropertySet > xPropSet( GetLinguProperties(), UNO_QUERY );
@@ -212,12 +208,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
// add dictionary information // add dictionary information
aDicts = new HDInfo[numdict]; aDicts = new HDInfo[numdict];
/*
aTEncs = new rtl_TextEncoding [numdict];
aTLocs = new Locale [numdict];
aTNames = new OUString [numdict];
aCharSetInfo = new CharClass* [numdict];
*/
k = 0; k = 0;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt) for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
{ {
@@ -233,7 +224,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
for (sal_Int32 i = 0; i < nLocales; ++i) for (sal_Int32 i = 0; i < nLocales; ++i)
{ {
aDicts[k].aPtr = NULL; aDicts[k].aPtr = NULL;
aDicts[k].aEnc = 0; aDicts[k].eEnc = RTL_TEXTENCODING_DONTKNOW;
aDicts[k].aLoc = MsLangId::convertLanguageToLocale( aDicts[k].aLoc = MsLangId::convertLanguageToLocale(
MsLangId::convertIsoStringToLanguage( aDictIt->aLocaleNames[i] )); MsLangId::convertIsoStringToLanguage( aDictIt->aLocaleNames[i] ));
aDicts[k].apCC = new CharClass( aDicts[k].aLoc ); aDicts[k].apCC = new CharClass( aDicts[k].aLoc );
@@ -288,13 +279,11 @@ sal_Bool SAL_CALL Hyphenator::hasLocale(const Locale& rLocale)
} }
Reference< XHyphenatedWord > SAL_CALL Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const ::rtl::OUString& aWord,
Hyphenator::hyphenate( const ::rtl::OUString& aWord,
const ::com::sun::star::lang::Locale& aLocale, const ::com::sun::star::lang::Locale& aLocale,
sal_Int16 nMaxLeading, sal_Int16 nMaxLeading,
const ::com::sun::star::beans::PropertyValues& aProperties ) const ::com::sun::star::beans::PropertyValues& aProperties )
throw (com::sun::star::uno::RuntimeException, throw (com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
com::sun::star::lang::IllegalArgumentException)
{ {
int nHyphenationPos = -1; int nHyphenationPos = -1;
int nHyphenationPosAlt = -1; int nHyphenationPosAlt = -1;
@@ -311,22 +300,24 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
sal_Int16 minLen = rHelper.GetMinWordLength(); sal_Int16 minLen = rHelper.GetMinWordLength();
HyphenDict *dict = NULL; HyphenDict *dict = NULL;
rtl_TextEncoding aEnc = 0; rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
CharClass * pCC = NULL; CharClass * pCC = NULL;
Reference< XHyphenatedWord > xRes; Reference< XHyphenatedWord > xRes;
k = -1; k = -1;
for (int j = 0; j < numdict; j++) for (int j = 0; j < numdict; j++)
if (aLocale == aDicts[j].aLoc) k = j; {
if (aLocale == aDicts[j].aLoc)
k = j;
}
// if we have a hyphenation dictionary matching this locale // if we have a hyphenation dictionary matching this locale
if (k != -1) { if (k != -1)
{
// if this dictinary has not been loaded yet do that // if this dictinary has not been loaded yet do that
if (!aDicts[k].aPtr) { if (!aDicts[k].aPtr)
{
OUString DictFN = aDicts[k].aName + A2OU(".dic"); OUString DictFN = aDicts[k].aName + A2OU(".dic");
OUString dictpath; OUString dictpath;
@@ -347,21 +338,22 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
return NULL; return NULL;
} }
aDicts[k].aPtr = dict; aDicts[k].aPtr = dict;
aDicts[k].aEnc = rtl_getTextEncodingFromUnixCharset(dict->cset); aDicts[k].eEnc = getTextEncodingFromCharset(dict->cset);
if (aDicts[k].aEnc == RTL_TEXTENCODING_DONTKNOW) {
if (strcmp("ISCII-DEVANAGARI", dict->cset) == 0) {
aDicts[k].aEnc = RTL_TEXTENCODING_ISCII_DEVANAGARI;
} else if (strcmp("UTF-8", dict->cset) == 0) {
aDicts[k].aEnc = RTL_TEXTENCODING_UTF8;
}
}
} }
// other wise hyphenate the word with that dictionary // other wise hyphenate the word with that dictionary
dict = aDicts[k].aPtr; dict = aDicts[k].aPtr;
aEnc = aDicts[k].aEnc; eEnc = aDicts[k].eEnc;
pCC = aDicts[k].apCC; pCC = aDicts[k].apCC;
// 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 NULL;
sal_uInt16 ct = CAPTYPE_UNKNOWN; sal_uInt16 ct = CAPTYPE_UNKNOWN;
ct = capitalType(aWord, pCC); ct = capitalType(aWord, pCC);
@@ -369,10 +361,13 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
OUStringBuffer rBuf(aWord); OUStringBuffer rBuf(aWord);
sal_Int32 nc = rBuf.getLength(); sal_Int32 nc = rBuf.getLength();
sal_Unicode ch; sal_Unicode ch;
for (sal_Int32 ix=0; ix < nc; ix++) { for (sal_Int32 ix=0; ix < nc; ix++)
{
ch = rBuf.charAt(ix); ch = rBuf.charAt(ix);
if ((ch == 0x201C) || (ch == 0x201D)) rBuf.setCharAt(ix,(sal_Unicode)0x0022); if ((ch == 0x201C) || (ch == 0x201D))
if ((ch == 0x2018) || (ch == 0x2019)) rBuf.setCharAt(ix,(sal_Unicode)0x0027); rBuf.setCharAt(ix,(sal_Unicode)0x0022);
if ((ch == 0x2018) || (ch == 0x2019))
rBuf.setCharAt(ix,(sal_Unicode)0x0027);
} }
OUString nWord(rBuf.makeStringAndClear()); OUString nWord(rBuf.makeStringAndClear());
@@ -380,7 +375,7 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
OUString nTerm(makeLowerCase(nWord, pCC)); OUString nTerm(makeLowerCase(nWord, pCC));
// now convert word to needed encoding // now convert word to needed encoding
OString encWord(OU2ENC(nTerm,aEnc)); OString encWord(OU2ENC(nTerm,eEnc));
wordlen = encWord.getLength(); wordlen = encWord.getLength();
lcword = new char[wordlen + 1]; lcword = new char[wordlen + 1];
@@ -395,18 +390,24 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
// now strip off any ending periods // now strip off any ending periods
int n = wordlen-1; int n = wordlen-1;
while((n >=0) && (lcword[n] == '.')) n--; while((n >=0) && (lcword[n] == '.'))
n--;
n++; n++;
if (n > 0) { if (n > 0)
if (hnj_hyphen_hyphenate3(dict, lcword, n, hyphens, NULL, &rep, &pos, &cut, {
minLead, minTrail, Max(dict->clhmin, Max(dict->clhmin, 2) + Max(0, minLead - Max(dict->lhmin, 2))), const bool bFailed = 0 != hnj_hyphen_hyphenate3( dict, lcword, n, hyphens, NULL,
Max(dict->crhmin, Max(dict->crhmin, 2) + Max(0, minTrail - Max(dict->rhmin, 2))))) &rep, &pos, &cut, minLead, minTrail,
Max(dict->clhmin, Max(dict->clhmin, 2) + Max(0, minLead - Max(dict->lhmin, 2))),
Max(dict->crhmin, Max(dict->crhmin, 2) + Max(0, minTrail - Max(dict->rhmin, 2))) );
if (bFailed)
{ {
//whoops something did not work //whoops something did not work
delete[] hyphens; delete[] hyphens;
delete[] lcword; delete[] lcword;
if (rep) { if (rep)
for(int j = 0; j < n; j++) { {
for(int j = 0; j < n; j++)
{
if (rep[j]) free(rep[j]); if (rep[j]) free(rep[j]);
} }
free(rep); free(rep);
@@ -427,44 +428,60 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
{ {
int leftrep = 0; int leftrep = 0;
BOOL hit = (n >= minLen); BOOL hit = (n >= minLen);
if (!rep || !rep[i] || (i >= n)) { if (!rep || !rep[i] || (i >= n))
{
hit = hit && (hyphens[i]&1) && (i < Leading); hit = hit && (hyphens[i]&1) && (i < Leading);
hit = hit && (i >= (minLead-1) ); hit = hit && (i >= (minLead-1) );
hit = hit && ((n - i - 1) >= minTrail); hit = hit && ((n - i - 1) >= minTrail);
} else { }
else
{
// calculate change character length before hyphenation point signed with '=' // calculate change character length before hyphenation point signed with '='
for (char * c = rep[i]; *c && (*c != '='); c++) { for (char * c = rep[i]; *c && (*c != '='); c++)
if (aEnc == RTL_TEXTENCODING_UTF8) { {
if (((unsigned char) *c) >> 6 != 2) leftrep++; if (eEnc == RTL_TEXTENCODING_UTF8)
} else leftrep++; {
if (((unsigned char) *c) >> 6 != 2)
leftrep++;
}
else
leftrep++;
} }
hit = hit && (hyphens[i]&1) && ((i + leftrep - pos[i]) < Leading); hit = hit && (hyphens[i]&1) && ((i + leftrep - pos[i]) < Leading);
hit = hit && ((i + leftrep - pos[i]) >= (minLead-1) ); hit = hit && ((i + leftrep - pos[i]) >= (minLead-1) );
hit = hit && ((n - i - 1 + sal::static_int_cast< sal_sSize >(strlen(rep[i])) - leftrep - 1) >= minTrail); hit = hit && ((n - i - 1 + sal::static_int_cast< sal_sSize >(strlen(rep[i])) - leftrep - 1) >= minTrail);
} }
if (hit) { if (hit)
{
nHyphenationPos = i; nHyphenationPos = i;
if (rep && (i < n) && rep[i]) { if (rep && (i < n) && rep[i])
{
nHyphenationPosAlt = i - pos[i]; nHyphenationPosAlt = i - pos[i];
nHyphenationPosAltHyph = i + leftrep - pos[i]; nHyphenationPosAltHyph = i + leftrep - pos[i];
} }
} }
} }
if (nHyphenationPos == -1) { if (nHyphenationPos == -1)
{
xRes = NULL; xRes = NULL;
} else { }
if (rep && rep[nHyphenationPos]) { else
{
if (rep && rep[nHyphenationPos])
{
// remove equal sign // remove equal sign
char * s = rep[nHyphenationPos]; char * s = rep[nHyphenationPos];
int eq = 0; int eq = 0;
for (; *s; s++) { for (; *s; s++)
{
if (*s == '=') eq = 1; if (*s == '=') eq = 1;
if (eq) *s = *(s + 1); if (eq) *s = *(s + 1);
} }
OUString repHyphlow(rep[nHyphenationPos], strlen(rep[nHyphenationPos]), aEnc); OUString repHyphlow(rep[nHyphenationPos], strlen(rep[nHyphenationPos]), eEnc);
OUString repHyph; OUString repHyph;
switch (ct) { switch (ct)
{
case CAPTYPE_ALLCAP: case CAPTYPE_ALLCAP:
{ {
repHyph = makeUpperCase(repHyphlow, pCC); repHyph = makeUpperCase(repHyphlow, pCC);
@@ -472,11 +489,10 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
} }
case CAPTYPE_INITCAP: case CAPTYPE_INITCAP:
{ {
if (nHyphenationPosAlt == 0) { if (nHyphenationPosAlt == 0)
repHyph = makeInitCap(repHyphlow, pCC); repHyph = makeInitCap(repHyphlow, pCC);
} else { else
repHyph = repHyphlow; repHyph = repHyphlow;
}
break; break;
} }
default: default:
@@ -493,7 +509,9 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
xRes = new HyphenatedWord( aWord, LocaleToLanguage( aLocale ), nPos, xRes = new HyphenatedWord( aWord, LocaleToLanguage( aLocale ), nPos,
aWord.replaceAt(nHyphenationPosAlt + 1, cut[nHyphenationPos], repHyph), aWord.replaceAt(nHyphenationPosAlt + 1, cut[nHyphenationPos], repHyph),
(INT16) nHyphenationPosAltHyph); (INT16) nHyphenationPosAltHyph);
} else { }
else
{
xRes = new HyphenatedWord( aWord, LocaleToLanguage( aLocale ), xRes = new HyphenatedWord( aWord, LocaleToLanguage( aLocale ),
(INT16)nHyphenationPos, aWord, (INT16) nHyphenationPos); (INT16)nHyphenationPos, aWord, (INT16) nHyphenationPos);
} }
@@ -501,8 +519,10 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
delete[] lcword; delete[] lcword;
delete[] hyphens; delete[] hyphens;
if (rep) { if (rep)
for(int j = 0; j < n; j++) { {
for(int j = 0; j < n; j++)
{
if (rep[j]) free(rep[j]); if (rep[j]) free(rep[j]);
} }
free(rep); free(rep);
@@ -515,13 +535,12 @@ Hyphenator::hyphenate( const ::rtl::OUString& aWord,
} }
Reference < XHyphenatedWord > SAL_CALL Reference < XHyphenatedWord > SAL_CALL Hyphenator::queryAlternativeSpelling(
Hyphenator::queryAlternativeSpelling( const ::rtl::OUString& /*aWord*/, const ::rtl::OUString& /*aWord*/,
const ::com::sun::star::lang::Locale& /*aLocale*/, const ::com::sun::star::lang::Locale& /*aLocale*/,
sal_Int16 /*nIndex*/, sal_Int16 /*nIndex*/,
const ::com::sun::star::beans::PropertyValues& /*aProperties*/ ) const ::com::sun::star::beans::PropertyValues& /*aProperties*/ )
throw(::com::sun::star::lang::IllegalArgumentException, throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
::com::sun::star::uno::RuntimeException)
{ {
/* alternative spelling isn't supported by tex dictionaries */ /* alternative spelling isn't supported by tex dictionaries */
/* XXX: OOo's extended libhjn algorithm can support alternative spellings with extended TeX dic. */ /* XXX: OOo's extended libhjn algorithm can support alternative spellings with extended TeX dic. */
@@ -529,13 +548,10 @@ Reference < XHyphenatedWord > SAL_CALL
return NULL; return NULL;
} }
Reference< XPossibleHyphens > SAL_CALL Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const ::rtl::OUString& aWord,
Hyphenator::createPossibleHyphens( const ::rtl::OUString& aWord,
const ::com::sun::star::lang::Locale& aLocale, const ::com::sun::star::lang::Locale& aLocale,
const ::com::sun::star::beans::PropertyValues& aProperties ) const ::com::sun::star::beans::PropertyValues& aProperties )
throw(::com::sun::star::lang::IllegalArgumentException, throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
::com::sun::star::uno::RuntimeException)
{ {
int wordlen; int wordlen;
char *hyphens; char *hyphens;
@@ -548,22 +564,23 @@ Reference< XPossibleHyphens > SAL_CALL
sal_Int16 minLead = rHelper.GetMinLeading(); sal_Int16 minLead = rHelper.GetMinLeading();
HyphenDict *dict = NULL; HyphenDict *dict = NULL;
rtl_TextEncoding aEnc = 0; rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
CharClass* pCC = NULL; CharClass* pCC = NULL;
Reference< XPossibleHyphens > xRes; Reference< XPossibleHyphens > xRes;
k = -1; k = -1;
for (int j = 0; j < numdict; j++) for (int j = 0; j < numdict; j++)
{
if (aLocale == aDicts[j].aLoc) k = j; if (aLocale == aDicts[j].aLoc) k = j;
}
// if we have a hyphenation dictionary matching this locale // if we have a hyphenation dictionary matching this locale
if (k != -1) { if (k != -1)
{
// if this dictioanry has not been loaded yet do that // if this dictioanry has not been loaded yet do that
if (!aDicts[k].aPtr) { if (!aDicts[k].aPtr)
{
OUString DictFN = aDicts[k].aName + A2OU(".dic"); OUString DictFN = aDicts[k].aName + A2OU(".dic");
OUString dictpath; OUString dictpath;
@@ -584,29 +601,33 @@ Reference< XPossibleHyphens > SAL_CALL
return NULL; return NULL;
} }
aDicts[k].aPtr = dict; aDicts[k].aPtr = dict;
aDicts[k].aEnc = rtl_getTextEncodingFromUnixCharset(dict->cset); aDicts[k].eEnc = getTextEncodingFromCharset(dict->cset);
if (aDicts[k].aEnc == RTL_TEXTENCODING_DONTKNOW) {
if (strcmp("ISCII-DEVANAGARI", dict->cset) == 0) {
aDicts[k].aEnc = RTL_TEXTENCODING_ISCII_DEVANAGARI;
} else if (strcmp("UTF-8", dict->cset) == 0) {
aDicts[k].aEnc = RTL_TEXTENCODING_UTF8;
}
}
} }
// other wise hyphenate the word with that dictionary // other wise hyphenate the word with that dictionary
dict = aDicts[k].aPtr; dict = aDicts[k].aPtr;
aEnc = aDicts[k].aEnc; eEnc = aDicts[k].eEnc;
pCC = aDicts[k].apCC; pCC = aDicts[k].apCC;
// 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 NULL;
// first handle smart quotes both single and double // first handle smart quotes both single and double
OUStringBuffer rBuf(aWord); OUStringBuffer rBuf(aWord);
sal_Int32 nc = rBuf.getLength(); sal_Int32 nc = rBuf.getLength();
sal_Unicode ch; sal_Unicode ch;
for (sal_Int32 ix=0; ix < nc; ix++) { for (sal_Int32 ix=0; ix < nc; ix++)
{
ch = rBuf.charAt(ix); ch = rBuf.charAt(ix);
if ((ch == 0x201C) || (ch == 0x201D)) rBuf.setCharAt(ix,(sal_Unicode)0x0022); if ((ch == 0x201C) || (ch == 0x201D))
if ((ch == 0x2018) || (ch == 0x2019)) rBuf.setCharAt(ix,(sal_Unicode)0x0027); rBuf.setCharAt(ix,(sal_Unicode)0x0022);
if ((ch == 0x2018) || (ch == 0x2019))
rBuf.setCharAt(ix,(sal_Unicode)0x0027);
} }
OUString nWord(rBuf.makeStringAndClear()); OUString nWord(rBuf.makeStringAndClear());
@@ -614,7 +635,7 @@ Reference< XPossibleHyphens > SAL_CALL
OUString nTerm(makeLowerCase(nWord, pCC)); OUString nTerm(makeLowerCase(nWord, pCC));
// now convert word to needed encoding // now convert word to needed encoding
OString encWord(OU2ENC(nTerm,aEnc)); OString encWord(OU2ENC(nTerm,eEnc));
wordlen = encWord.getLength(); wordlen = encWord.getLength();
lcword = new char[wordlen+1]; lcword = new char[wordlen+1];
@@ -628,19 +649,25 @@ Reference< XPossibleHyphens > SAL_CALL
// first remove any trailing periods // first remove any trailing periods
int n = wordlen-1; int n = wordlen-1;
while((n >=0) && (lcword[n] == '.')) n--; while((n >=0) && (lcword[n] == '.'))
n--;
n++; n++;
// fprintf(stderr,"hyphenate... %s\n",lcword); fflush(stderr); // fprintf(stderr,"hyphenate... %s\n",lcword); fflush(stderr);
if (n > 0) { if (n > 0)
if (hnj_hyphen_hyphenate3(dict, lcword, n, hyphens, NULL, &rep, &pos, &cut, {
minLead, minTrail, Max(dict->clhmin, Max(dict->clhmin, 2) + Max(0, minLead - Max(dict->lhmin, 2))), const bool bFailed = 0 != hnj_hyphen_hyphenate3(dict, lcword, n, hyphens, NULL,
Max(dict->crhmin, Max(dict->crhmin, 2) + Max(0, minTrail - Max(dict->rhmin, 2))))) &rep, &pos, &cut, minLead, minTrail,
Max(dict->clhmin, Max(dict->clhmin, 2) + Max(0, minLead - Max(dict->lhmin, 2))),
Max(dict->crhmin, Max(dict->crhmin, 2) + Max(0, minTrail - Max(dict->rhmin, 2))) );
if (bFailed)
{ {
delete[] hyphens; delete[] hyphens;
delete[] lcword; delete[] lcword;
if (rep) { if (rep)
for(int j = 0; j < n; j++) { {
for(int j = 0; j < n; j++)
{
if (rep[j]) free(rep[j]); if (rep[j]) free(rep[j]);
} }
free(rep); free(rep);
@@ -652,7 +679,8 @@ Reference< XPossibleHyphens > SAL_CALL
} }
} }
// now backfill hyphens[] for any removed periods // now backfill hyphens[] for any removed periods
for (int c = n; c < wordlen; c++) hyphens[c] = '0'; for (int c = n; c < wordlen; c++)
hyphens[c] = '0';
hyphens[wordlen] = '\0'; hyphens[wordlen] = '\0';
// fprintf(stderr,"... %s\n",hyphens); fflush(stderr); // fprintf(stderr,"... %s\n",hyphens); fflush(stderr);
@@ -660,8 +688,10 @@ Reference< XPossibleHyphens > SAL_CALL
INT16 i; INT16 i;
for ( i = 0; i < encWord.getLength(); i++) for ( i = 0; i < encWord.getLength(); i++)
{
if (hyphens[i]&1 && (!rep || !rep[i])) if (hyphens[i]&1 && (!rep || !rep[i]))
nHyphCount++; nHyphCount++;
}
Sequence< INT16 > aHyphPos(nHyphCount); Sequence< INT16 > aHyphPos(nHyphCount);
INT16 *pPos = aHyphPos.getArray(); INT16 *pPos = aHyphPos.getArray();
@@ -669,10 +699,12 @@ Reference< XPossibleHyphens > SAL_CALL
OUString hyphenatedWord; OUString hyphenatedWord;
nHyphCount = 0; nHyphCount = 0;
for (i = 0; i < nWord.getLength(); i++) { for (i = 0; i < nWord.getLength(); i++)
{
hyphenatedWordBuffer.append(aWord[i]); hyphenatedWordBuffer.append(aWord[i]);
// hyphenation position (not alternative) // hyphenation position (not alternative)
if (hyphens[i]&1 && (!rep || !rep[i])) { if (hyphens[i]&1 && (!rep || !rep[i]))
{
pPos[nHyphCount] = i; pPos[nHyphCount] = i;
hyphenatedWordBuffer.append(sal_Unicode('=')); hyphenatedWordBuffer.append(sal_Unicode('='));
nHyphCount++; nHyphCount++;
@@ -689,8 +721,10 @@ Reference< XPossibleHyphens > SAL_CALL
delete[] hyphens; delete[] hyphens;
delete[] lcword; delete[] lcword;
if (rep) { if (rep)
for(int j = 0; j < n; j++) { {
for(int j = 0; j < n; j++)
{
if (rep[j]) free(rep[j]); if (rep[j]) free(rep[j]);
} }
free(rep); free(rep);
@@ -702,26 +736,26 @@ Reference< XPossibleHyphens > SAL_CALL
} }
return NULL; return NULL;
} }
sal_uInt16 SAL_CALL Hyphenator::capitalType(const OUString& aTerm, CharClass * pCC) sal_uInt16 SAL_CALL Hyphenator::capitalType(const OUString& aTerm, CharClass * pCC)
{ {
sal_Int32 tlen = aTerm.getLength(); sal_Int32 tlen = aTerm.getLength();
if ((pCC) && (tlen)) { if ((pCC) && (tlen))
{
String aStr(aTerm); String aStr(aTerm);
sal_Int32 nc = 0; sal_Int32 nc = 0;
for (xub_StrLen tindex = 0; tindex < tlen; tindex++) { for (xub_StrLen tindex = 0; tindex < tlen; tindex++)
if (pCC->getCharacterType(aStr,tindex) & {
::com::sun::star::i18n::KCharacterType::UPPER) nc++; 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 == tlen)
return (sal_uInt16) CAPTYPE_ALLCAP;
if ((nc == 1) && (pCC->getCharacterType(aStr,0) & if ((nc == 1) && (pCC->getCharacterType(aStr,0) & ::com::sun::star::i18n::KCharacterType::UPPER))
::com::sun::star::i18n::KCharacterType::UPPER))
return (sal_uInt16) CAPTYPE_INITCAP; return (sal_uInt16) CAPTYPE_INITCAP;
return (sal_uInt16) CAPTYPE_MIXED; return (sal_uInt16) CAPTYPE_MIXED;
@@ -747,11 +781,11 @@ OUString SAL_CALL Hyphenator::makeUpperCase(const OUString& aTerm, CharClass * p
OUString SAL_CALL Hyphenator::makeInitCap(const OUString& aTerm, CharClass * pCC) OUString SAL_CALL Hyphenator::makeInitCap(const OUString& aTerm, CharClass * pCC)
{ {
sal_Int32 tlen = aTerm.getLength(); sal_Int32 tlen = aTerm.getLength();
if ((pCC) && (tlen)) { if ((pCC) && (tlen))
{
OUString bTemp = aTerm.copy(0,1); OUString bTemp = aTerm.copy(0,1);
if (tlen > 1) if (tlen > 1)
return ( pCC->toUpper_rtl(bTemp, 0, 1) return ( pCC->toUpper_rtl(bTemp, 0, 1) + pCC->toLower_rtl(aTerm,1,(tlen-1)) );
+ pCC->toLower_rtl(aTerm,1,(tlen-1)) );
return pCC->toUpper_rtl(bTemp, 0, 1); return pCC->toUpper_rtl(bTemp, 0, 1);
} }
@@ -759,20 +793,16 @@ OUString SAL_CALL Hyphenator::makeInitCap(const OUString& aTerm, CharClass * pCC
} }
Reference< XInterface > SAL_CALL Hyphenator_CreateInstance( Reference< XInterface > SAL_CALL Hyphenator_CreateInstance(
const Reference< XMultiServiceFactory > & /*rSMgr*/ ) const Reference< XMultiServiceFactory > & /*rSMgr*/ )
throw(Exception) throw(Exception)
{ {
Reference< XInterface > xService = (cppu::OWeakObject*) new Hyphenator; Reference< XInterface > xService = (cppu::OWeakObject*) new Hyphenator;
return xService; return xService;
} }
sal_Bool SAL_CALL sal_Bool SAL_CALL Hyphenator::addLinguServiceEventListener(
Hyphenator::addLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr ) const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException) throw(RuntimeException)
{ {
@@ -787,8 +817,7 @@ sal_Bool SAL_CALL
} }
sal_Bool SAL_CALL sal_Bool SAL_CALL Hyphenator::removeLinguServiceEventListener(
Hyphenator::removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr ) const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException) throw(RuntimeException)
{ {
@@ -804,8 +833,7 @@ sal_Bool SAL_CALL
} }
OUString SAL_CALL OUString SAL_CALL Hyphenator::getServiceDisplayName( const Locale& /*rLocale*/ )
Hyphenator::getServiceDisplayName( const Locale& /*rLocale*/ )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -813,8 +841,7 @@ OUString SAL_CALL
} }
void SAL_CALL void SAL_CALL Hyphenator::initialize( const Sequence< Any >& rArguments )
Hyphenator::initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException) throw(Exception, RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -836,16 +863,15 @@ void SAL_CALL
xPropHelper = pPropHelper; xPropHelper = pPropHelper;
pPropHelper->AddAsPropListener(); //! after a reference is established pPropHelper->AddAsPropListener(); //! after a reference is established
} }
else { else
{
DBG_ERROR( "wrong number of arguments in sequence" ); DBG_ERROR( "wrong number of arguments in sequence" );
} }
} }
} }
void SAL_CALL void SAL_CALL Hyphenator::dispose()
Hyphenator::dispose()
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -859,8 +885,7 @@ void SAL_CALL
} }
void SAL_CALL void SAL_CALL Hyphenator::addEventListener( const Reference< XEventListener >& rxListener )
Hyphenator::addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -870,8 +895,7 @@ void SAL_CALL
} }
void SAL_CALL void SAL_CALL Hyphenator::removeEventListener( const Reference< XEventListener >& rxListener )
Hyphenator::removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -931,7 +955,6 @@ Sequence< OUString > Hyphenator::getSupportedServiceNames_Static()
sal_Bool SAL_CALL Hyphenator_writeInfo( sal_Bool SAL_CALL Hyphenator_writeInfo(
void * /*pServiceManager*/, registry::XRegistryKey * pRegistryKey ) void * /*pServiceManager*/, registry::XRegistryKey * pRegistryKey )
{ {
try try
{ {
String aImpl( '/' ); String aImpl( '/' );

View File

@@ -65,7 +65,7 @@ struct HDInfo {
HyphenDict * aPtr; HyphenDict * aPtr;
OUString aName; OUString aName;
Locale aLoc; Locale aLoc;
rtl_TextEncoding aEnc; rtl_TextEncoding eEnc;
CharClass * apCC; CharClass * apCC;
}; };
@@ -108,87 +108,37 @@ public:
virtual ~Hyphenator(); virtual ~Hyphenator();
// XSupportedLocales (for XHyphenator) // XSupportedLocales (for XHyphenator)
virtual Sequence< Locale > SAL_CALL getLocales() virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
throw(RuntimeException); virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale )
throw(RuntimeException);
// XHyphenator // XHyphenator
virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL 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);
hyphenate( const ::rtl::OUString& aWord, 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);
const ::com::sun::star::lang::Locale& aLocale, 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);
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 // XLinguServiceEventBroadcaster
virtual sal_Bool SAL_CALL virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
addLinguServiceEventListener( virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL
removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
// XServiceDisplayName // XServiceDisplayName
virtual OUString SAL_CALL virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
getServiceDisplayName( const Locale& rLocale )
throw(RuntimeException);
// XInitialization // XInitialization
virtual void SAL_CALL virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException);
// XComponent // XComponent
virtual void SAL_CALL virtual void SAL_CALL dispose() throw(RuntimeException);
dispose() virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
throw(RuntimeException); virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) 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
//
// XServiceInfo // XServiceInfo
virtual OUString SAL_CALL virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
getImplementationName() virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
throw(RuntimeException); virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
virtual sal_Bool SAL_CALL
supportsService( const OUString& rServiceName )
throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL
getSupportedServiceNames()
throw(RuntimeException);
static inline OUString static inline OUString getImplementationName_Static() throw();
getImplementationName_Static() throw(); static Sequence< OUString > getSupportedServiceNames_Static() throw();
static Sequence< OUString >
getSupportedServiceNames_Static() throw();
private: private:

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

@@ -50,6 +50,7 @@
#include <unotools/pathoptions.hxx> #include <unotools/pathoptions.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <rtl/string.hxx> #include <rtl/string.hxx>
#include <rtl/tencinfo.h>
#include <linguistic/misc.hxx> #include <linguistic/misc.hxx>
#include <set> #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 #endif

View File

@@ -100,84 +100,43 @@ class MacSpellChecker :
} }
INT16 GetSpellFailure( const OUString &rWord, const Locale &rLocale ); INT16 GetSpellFailure( const OUString &rWord, const Locale &rLocale );
Reference< XSpellAlternatives > Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
GetProposals( const OUString &rWord, const Locale &rLocale );
public: public:
MacSpellChecker(); MacSpellChecker();
virtual ~MacSpellChecker(); virtual ~MacSpellChecker();
// XSupportedLocales (for XSpellChecker) // XSupportedLocales (for XSpellChecker)
virtual Sequence< Locale > SAL_CALL virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
getLocales() virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
throw(RuntimeException);
virtual sal_Bool SAL_CALL
hasLocale( const Locale& rLocale )
throw(RuntimeException);
// XSpellChecker // XSpellChecker
virtual sal_Bool SAL_CALL virtual sal_Bool SAL_CALL isValid( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
isValid( const OUString& rWord, const Locale& rLocale, virtual Reference< XSpellAlternatives > SAL_CALL spell( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
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 // XLinguServiceEventBroadcaster
virtual sal_Bool SAL_CALL virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
addLinguServiceEventListener( virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL
removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
// XServiceDisplayName // XServiceDisplayName
virtual OUString SAL_CALL virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
getServiceDisplayName( const Locale& rLocale )
throw(RuntimeException);
// XInitialization // XInitialization
virtual void SAL_CALL virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException);
// XComponent // XComponent
virtual void SAL_CALL virtual void SAL_CALL dispose() throw(RuntimeException);
dispose() virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
throw(RuntimeException); virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) 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
//
// XServiceInfo // XServiceInfo
virtual OUString SAL_CALL virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
getImplementationName() virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
throw(RuntimeException); virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
virtual sal_Bool SAL_CALL
supportsService( const OUString& rServiceName )
throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL
getSupportedServiceNames()
throw(RuntimeException);
static inline OUString static inline OUString getImplementationName_Static() throw();
getImplementationName_Static() throw(); static Sequence< OUString > getSupportedServiceNames_Static() throw();
static Sequence< OUString >
getSupportedServiceNames_Static() throw();
}; };
inline OUString MacSpellChecker::getImplementationName_Static() throw() inline OUString MacSpellChecker::getImplementationName_Static() throw()

142
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 // MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_lingucomponent.hxx" #include "precompiled_lingucomponent.hxx"
#include <com/sun/star/uno/Reference.h> #include <com/sun/star/uno/Reference.h>
#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp> #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
@@ -37,12 +38,10 @@
#include <unotools/processfactory.hxx> #include <unotools/processfactory.hxx>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <lingutil.hxx>
#include <hunspell.hxx> #include <hunspell.hxx>
#include <dictmgr.hxx> #include <dictmgr.hxx>
#ifndef _SPELLIMP_HXX
#include <sspellimp.hxx> #include <sspellimp.hxx>
#endif
#include <linguistic/lngprops.hxx> #include <linguistic/lngprops.hxx>
#include <linguistic/spelldta.hxx> #include <linguistic/spelldta.hxx>
@@ -53,8 +52,6 @@
#include <osl/file.hxx> #include <osl/file.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <lingutil.hxx>
#include <list> #include <list>
#include <set> #include <set>
#include <string.h> #include <string.h>
@@ -89,8 +86,10 @@ SpellChecker::SpellChecker() :
SpellChecker::~SpellChecker() SpellChecker::~SpellChecker()
{ {
if (aDicts) { if (aDicts)
for (int i = 0; i < numdict; i++) { {
for (int i = 0; i < numdict; i++)
{
if (aDicts[i]) delete aDicts[i]; if (aDicts[i]) delete aDicts[i];
aDicts[i] = NULL; aDicts[i] = NULL;
} }
@@ -217,7 +216,7 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
for (sal_Int32 i = 0; i < nLocales; ++i) for (sal_Int32 i = 0; i < nLocales; ++i)
{ {
aDicts[k] = NULL; aDicts[k] = NULL;
aDEncs[k] = 0; aDEncs[k] = RTL_TEXTENCODING_DONTKNOW;
aDLocs[k] = MsLangId::convertLanguageToLocale( aDLocs[k] = MsLangId::convertLanguageToLocale(
MsLangId::convertIsoStringToLanguage( aLocaleNames[i] )); MsLangId::convertIsoStringToLanguage( aLocaleNames[i] ));
// also both files have to be in the same directory and the // also both files have to be in the same directory and the
@@ -272,33 +271,37 @@ sal_Bool SAL_CALL SpellChecker::hasLocale(const Locale& rLocale)
return bRes; return bRes;
} }
INT16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocale ) INT16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocale )
{ {
Hunspell * pMS; Hunspell * pMS = NULL;
rtl_TextEncoding aEnc; rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
// initialize a myspell object for each dictionary once // 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; INT16 nRes = -1;
// first handle smart quotes both single and double // first handle smart quotes both single and double
OUStringBuffer rBuf(rWord); OUStringBuffer rBuf(rWord);
sal_Int32 n = rBuf.getLength(); sal_Int32 n = rBuf.getLength();
sal_Unicode c; sal_Unicode c;
for (sal_Int32 ix=0; ix < n; ix++) { for (sal_Int32 ix=0; ix < n; ix++)
{
c = rBuf.charAt(ix); c = rBuf.charAt(ix);
if ((c == 0x201C) || (c == 0x201D)) rBuf.setCharAt(ix,(sal_Unicode)0x0022); if ((c == 0x201C) || (c == 0x201D))
if ((c == 0x2018) || (c == 0x2019)) rBuf.setCharAt(ix,(sal_Unicode)0x0027); rBuf.setCharAt(ix,(sal_Unicode)0x0022);
if ((c == 0x2018) || (c == 0x2019))
rBuf.setCharAt(ix,(sal_Unicode)0x0027);
} }
OUString nWord(rBuf.makeStringAndClear()); OUString nWord(rBuf.makeStringAndClear());
if (n) if (n)
{ {
for (sal_Int32 i = 0; i < numdict; ++i) { for (sal_Int32 i = 0; i < numdict; ++i)
{
pMS = NULL; pMS = NULL;
aEnc = 0; eEnc = RTL_TEXTENCODING_DONTKNOW;
if (rLocale == aDLocs[i]) if (rLocale == aDLocs[i])
{ {
@@ -323,32 +326,30 @@ INT16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocal
#endif #endif
aDicts[i] = new Hunspell(aTmpaff.getStr(),aTmpdict.getStr()); aDicts[i] = new Hunspell(aTmpaff.getStr(),aTmpdict.getStr());
aDEncs[i] = 0; aDEncs[i] = RTL_TEXTENCODING_DONTKNOW;
if (aDicts[i]) { if (aDicts[i])
char * dic_encoding = aDicts[i]->get_dic_encoding(); aDEncs[i] = getTextEncodingFromCharset(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]; pMS = aDicts[i];
aEnc = aDEncs[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) if (pMS)
{ {
OString aWrd(OU2ENC(nWord,aEnc)); OString aWrd(OU2ENC(nWord,eEnc));
int rVal = pMS->spell((char*)aWrd.getStr()); int rVal = pMS->spell((char*)aWrd.getStr());
if (rVal != 1) if (rVal != 1)
{
nRes = SpellFailure::SPELLING_ERROR; nRes = SpellFailure::SPELLING_ERROR;
} else { else
return -1; return -1;
}
pMS = NULL; pMS = NULL;
} }
} }
@@ -358,8 +359,7 @@ INT16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocal
} }
sal_Bool SAL_CALL sal_Bool SAL_CALL SpellChecker::isValid( const OUString& rWord, const Locale& rLocale,
SpellChecker::isValid( const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties ) const PropertyValues& rProperties )
throw(IllegalArgumentException, RuntimeException) throw(IllegalArgumentException, RuntimeException)
{ {
@@ -390,11 +390,11 @@ sal_Bool SAL_CALL
{ {
INT16 nLang = LocaleToLanguage( rLocale ); INT16 nLang = LocaleToLanguage( rLocale );
// postprocess result for errors that should be ignored // postprocess result for errors that should be ignored
if ( (!rHelper.IsSpellUpperCase() && IsUpper( rWord, nLang )) const bool bIgnoreError =
|| (!rHelper.IsSpellWithDigits() && HasDigits( rWord )) (!rHelper.IsSpellUpperCase() && IsUpper( rWord, nLang )) ||
|| (!rHelper.IsSpellCapitalization() (!rHelper.IsSpellWithDigits() && HasDigits( rWord )) ||
&& nFailure == SpellFailure::CAPTION_ERROR) (!rHelper.IsSpellCapitalization() && nFailure == SpellFailure::CAPTION_ERROR);
) if (bIgnoreError)
nFailure = -1; nFailure = -1;
} }
@@ -412,19 +412,22 @@ Reference< XSpellAlternatives >
Reference< XSpellAlternatives > xRes; 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; Hunspell* pMS = NULL;
rtl_TextEncoding aEnc; rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
int count; int count = 0;
int numsug = 0; int numsug = 0;
// first handle smart quotes (single and double) // first handle smart quotes (single and double)
OUStringBuffer rBuf(rWord); OUStringBuffer rBuf(rWord);
sal_Int32 n = rBuf.getLength(); sal_Int32 n = rBuf.getLength();
sal_Unicode c; sal_Unicode c;
for (sal_Int32 ix=0; ix < n; ix++) { for (sal_Int32 ix=0; ix < n; ix++)
{
c = rBuf.charAt(ix); c = rBuf.charAt(ix);
if ((c == 0x201C) || (c == 0x201D)) rBuf.setCharAt(ix,(sal_Unicode)0x0022); if ((c == 0x201C) || (c == 0x201D))
if ((c == 0x2018) || (c == 0x2019)) rBuf.setCharAt(ix,(sal_Unicode)0x0027); rBuf.setCharAt(ix,(sal_Unicode)0x0022);
if ((c == 0x2018) || (c == 0x2019))
rBuf.setCharAt(ix,(sal_Unicode)0x0027);
} }
OUString nWord(rBuf.makeStringAndClear()); OUString nWord(rBuf.makeStringAndClear());
@@ -434,31 +437,32 @@ Reference< XSpellAlternatives >
Sequence< OUString > aStr( 0 ); Sequence< OUString > aStr( 0 );
for (int i =0; i < numdict; i++) { for (int i =0; i < numdict; i++)
{
pMS = NULL; pMS = NULL;
aEnc = 0; eEnc = RTL_TEXTENCODING_DONTKNOW;
count = 0; count = 0;
if (rLocale == aDLocs[i]) if (rLocale == aDLocs[i])
{ {
pMS = aDicts[i]; pMS = aDicts[i];
aEnc = aDEncs[i]; eEnc = aDEncs[i];
} }
if (pMS) if (pMS)
{ {
char ** suglst = NULL; char ** suglst = NULL;
OString aWrd(OU2ENC(nWord,aEnc)); OString aWrd(OU2ENC(nWord,eEnc));
count = pMS->suggest(&suglst, (const char *) aWrd.getStr()); count = pMS->suggest(&suglst, (const char *) aWrd.getStr());
if (count) { if (count)
{
aStr.realloc( numsug + count ); aStr.realloc( numsug + count );
OUString *pStr = aStr.getArray(); OUString *pStr = aStr.getArray();
for (int ii=0; ii < count; ii++) for (int ii=0; ii < count; ii++)
{ {
// if needed add: if (suglst[ii] == NULL) continue; // if needed add: if (suglst[ii] == NULL) continue;
OUString cvtwrd(suglst[ii],strlen(suglst[ii]),aEnc); OUString cvtwrd(suglst[ii],strlen(suglst[ii]),eEnc);
pStr[numsug + ii] = cvtwrd; pStr[numsug + ii] = cvtwrd;
free(suglst[ii]); free(suglst[ii]);
} }
@@ -476,16 +480,13 @@ Reference< XSpellAlternatives >
pAlt->SetAlternatives( aStr ); pAlt->SetAlternatives( aStr );
xRes = pAlt; xRes = pAlt;
return xRes; return xRes;
} }
return xRes; return xRes;
} }
Reference< XSpellAlternatives > SAL_CALL SpellChecker::spell(
const OUString& rWord, const Locale& rLocale,
Reference< XSpellAlternatives > SAL_CALL
SpellChecker::spell( const OUString& rWord, const Locale& rLocale,
const PropertyValues& rProperties ) const PropertyValues& rProperties )
throw(IllegalArgumentException, RuntimeException) throw(IllegalArgumentException, RuntimeException)
{ {
@@ -520,8 +521,7 @@ Reference< XInterface > SAL_CALL SpellChecker_CreateInstance(
} }
sal_Bool SAL_CALL sal_Bool SAL_CALL SpellChecker::addLinguServiceEventListener(
SpellChecker::addLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr ) const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException) throw(RuntimeException)
{ {
@@ -536,8 +536,7 @@ sal_Bool SAL_CALL
} }
sal_Bool SAL_CALL sal_Bool SAL_CALL SpellChecker::removeLinguServiceEventListener(
SpellChecker::removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr ) const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException) throw(RuntimeException)
{ {
@@ -553,8 +552,7 @@ sal_Bool SAL_CALL
} }
OUString SAL_CALL OUString SAL_CALL SpellChecker::getServiceDisplayName( const Locale& /*rLocale*/ )
SpellChecker::getServiceDisplayName( const Locale& /*rLocale*/ )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -562,8 +560,7 @@ OUString SAL_CALL
} }
void SAL_CALL void SAL_CALL SpellChecker::initialize( const Sequence< Any >& rArguments )
SpellChecker::initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException) throw(Exception, RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -585,16 +582,15 @@ void SAL_CALL
xPropHelper = pPropHelper; xPropHelper = pPropHelper;
pPropHelper->AddAsPropListener(); //! after a reference is established pPropHelper->AddAsPropListener(); //! after a reference is established
} }
else { else
{
DBG_ERROR( "wrong number of arguments in sequence" ); DBG_ERROR( "wrong number of arguments in sequence" );
} }
} }
} }
void SAL_CALL void SAL_CALL SpellChecker::dispose()
SpellChecker::dispose()
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -608,8 +604,7 @@ void SAL_CALL
} }
void SAL_CALL void SAL_CALL SpellChecker::addEventListener( const Reference< XEventListener >& rxListener )
SpellChecker::addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -619,8 +614,7 @@ void SAL_CALL
} }
void SAL_CALL void SAL_CALL SpellChecker::removeEventListener( const Reference< XEventListener >& rxListener )
SpellChecker::removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );

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

@@ -91,84 +91,43 @@ class SpellChecker :
} }
INT16 GetSpellFailure( const OUString &rWord, const Locale &rLocale ); INT16 GetSpellFailure( const OUString &rWord, const Locale &rLocale );
Reference< XSpellAlternatives > Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
GetProposals( const OUString &rWord, const Locale &rLocale );
public: public:
SpellChecker(); SpellChecker();
virtual ~SpellChecker(); virtual ~SpellChecker();
// XSupportedLocales (for XSpellChecker) // XSupportedLocales (for XSpellChecker)
virtual Sequence< Locale > SAL_CALL virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
getLocales() virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
throw(RuntimeException);
virtual sal_Bool SAL_CALL
hasLocale( const Locale& rLocale )
throw(RuntimeException);
// XSpellChecker // XSpellChecker
virtual sal_Bool SAL_CALL virtual sal_Bool SAL_CALL isValid( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
isValid( const OUString& rWord, const Locale& rLocale, virtual Reference< XSpellAlternatives > SAL_CALL spell( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
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 // XLinguServiceEventBroadcaster
virtual sal_Bool SAL_CALL virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
addLinguServiceEventListener( virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
virtual sal_Bool SAL_CALL
removeLinguServiceEventListener(
const Reference< XLinguServiceEventListener >& rxLstnr )
throw(RuntimeException);
// XServiceDisplayName // XServiceDisplayName
virtual OUString SAL_CALL virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
getServiceDisplayName( const Locale& rLocale )
throw(RuntimeException);
// XInitialization // XInitialization
virtual void SAL_CALL virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException);
// XComponent // XComponent
virtual void SAL_CALL virtual void SAL_CALL dispose() throw(RuntimeException);
dispose() virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
throw(RuntimeException); virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) 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
//
// XServiceInfo // XServiceInfo
virtual OUString SAL_CALL virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
getImplementationName() virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
throw(RuntimeException); virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
virtual sal_Bool SAL_CALL
supportsService( const OUString& rServiceName )
throw(RuntimeException);
virtual Sequence< OUString > SAL_CALL
getSupportedServiceNames()
throw(RuntimeException);
static inline OUString static inline OUString getImplementationName_Static() throw();
getImplementationName_Static() throw(); static Sequence< OUString > getSupportedServiceNames_Static() throw();
static Sequence< OUString >
getSupportedServiceNames_Static() throw();
}; };
inline OUString SpellChecker::getImplementationName_Static() throw() inline OUString SpellChecker::getImplementationName_Static() throw()
@@ -177,7 +136,6 @@ inline OUString SpellChecker::getImplementationName_Static() throw()
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#endif #endif

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

@@ -68,22 +68,12 @@ public:
virtual ~Meaning(); virtual ~Meaning();
// XMeaning // XMeaning
virtual ::rtl::OUString SAL_CALL virtual ::rtl::OUString SAL_CALL getMeaning() throw(::com::sun::star::uno::RuntimeException);
getMeaning() virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL querySynonyms() throw(::com::sun::star::uno::RuntimeException);
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 // non-interface specific functions
void SetSynonyms( void SetSynonyms( const ::com::sun::star::uno::Sequence< ::rtl::OUString > &rSyn );
const ::com::sun::star::uno::Sequence< ::rtl::OUString >
&rSyn );
void SetMeaning( const ::rtl::OUString &rTerm ); void SetMeaning( const ::rtl::OUString &rTerm );
}; };

186
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 // MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_lingucomponent.hxx" #include "precompiled_lingucomponent.hxx"
// include <stdio.h>
#include <com/sun/star/uno/Reference.h> #include <com/sun/star/uno/Reference.h>
#include <cppuhelper/factory.hxx> // helper for factories #include <cppuhelper/factory.hxx> // helper for factories
#include <com/sun/star/registry/XRegistryKey.hpp> #include <com/sun/star/registry/XRegistryKey.hpp>
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
@@ -107,16 +105,20 @@ Thesaurus::Thesaurus() :
Thesaurus::~Thesaurus() Thesaurus::~Thesaurus()
{ {
if (aThes) { if (aThes)
for (int i = 0; i < numthes; i++) { {
for (int i = 0; i < numthes; i++)
{
if (aThes[i]) delete aThes[i]; if (aThes[i]) delete aThes[i];
aThes[i] = NULL; aThes[i] = NULL;
} }
delete[] aThes; delete[] aThes;
} }
aThes = NULL; aThes = NULL;
if (aCharSetInfo) { if (aCharSetInfo)
for (int i = 0; i < numthes; i++) { {
for (int i = 0; i < numthes; i++)
{
if (aCharSetInfo[i]) delete aCharSetInfo[i]; if (aCharSetInfo[i]) delete aCharSetInfo[i];
aCharSetInfo[i] = NULL; aCharSetInfo[i] = NULL;
} }
@@ -244,7 +246,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
for (sal_Int32 i = 0; i < nLocales; ++i) for (sal_Int32 i = 0; i < nLocales; ++i)
{ {
aThes[k] = NULL; aThes[k] = NULL;
aTEncs[k] = 0; aTEncs[k] = RTL_TEXTENCODING_DONTKNOW;
aTLocs[k] = MsLangId::convertLanguageToLocale( aTLocs[k] = MsLangId::convertLanguageToLocale(
MsLangId::convertIsoStringToLanguage( aDictIt->aLocaleNames[i] )); MsLangId::convertIsoStringToLanguage( aDictIt->aLocaleNames[i] ));
aCharSetInfo[k] = new CharClass( aTLocs[k] ); aCharSetInfo[k] = new CharClass( aTLocs[k] );
@@ -302,8 +304,8 @@ sal_Bool SAL_CALL Thesaurus::hasLocale(const Locale& rLocale)
} }
Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryMeanings(
Thesaurus::queryMeanings( const OUString& qTerm, const Locale& rLocale, const OUString& qTerm, const Locale& rLocale,
const PropertyValues& rProperties) const PropertyValues& rProperties)
throw(IllegalArgumentException, RuntimeException) throw(IllegalArgumentException, RuntimeException)
{ {
@@ -332,7 +334,8 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
return noMeanings; return noMeanings;
#endif #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; sal_Int32 nmean = 0;
@@ -341,11 +344,12 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
rHelper.SetTmpPropVals( rProperties ); rHelper.SetTmpPropVals( rProperties );
MyThes * pTH = NULL; MyThes * pTH = NULL;
rtl_TextEncoding aEnc = 0; rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
CharClass * pCC = NULL; CharClass * pCC = NULL;
// find the first thesaurus that matches the locale // find the first thesaurus that matches the locale
for (int i =0; i < numthes; i++) { for (int i =0; i < numthes; i++)
{
if (rLocale == aTLocs[i]) if (rLocale == aTLocs[i])
{ {
// open up and intialize this thesaurus if need be // open up and intialize this thesaurus if need be
@@ -370,24 +374,11 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
#endif #endif
aThes[i] = new MyThes(aTmpidx.getStr(),aTmpdat.getStr()); aThes[i] = new MyThes(aTmpidx.getStr(),aTmpdat.getStr());
if (aThes[i]) { if (aThes[i])
const char * enc_string = aThes[i]->get_th_encoding(); aTEncs[i] = getTextEncodingFromCharset(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]; pTH = aThes[i];
aEnc = aTEncs[i]; eEnc = aTEncs[i];
pCC = aCharSetInfo[i]; pCC = aCharSetInfo[i];
if (pTH) if (pTH)
@@ -395,89 +386,103 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
} }
} }
while (pTH) { // 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;
while (pTH)
{
// convert word to all lower case for searching // convert word to all lower case for searching
if (!stem) ct = capitalType(rTerm, pCC); if (!stem)
ct = capitalType(rTerm, pCC);
OUString nTerm(makeLowerCase(rTerm, pCC)); OUString nTerm(makeLowerCase(rTerm, pCC));
OString aTmp( OU2ENC(nTerm, aEnc) ); OString aTmp( OU2ENC(nTerm, eEnc) );
nmean = pTH->Lookup(aTmp.getStr(),aTmp.getLength(),&pmean); nmean = pTH->Lookup(aTmp.getStr(),aTmp.getLength(),&pmean);
if (nmean) aMeanings.realloc( nmean ); if (nmean)
aMeanings.realloc( nmean );
mentry * pe = pmean; mentry * pe = pmean;
OUString codeTerm = qTerm; OUString codeTerm = qTerm;
Reference< XSpellAlternatives > xTmpRes2; Reference< XSpellAlternatives > xTmpRes2;
if (stem) { if (stem)
{
xTmpRes2 = xSpell->spell( A2OU("<?xml?><query type='analyze'><word>") + xTmpRes2 = xSpell->spell( A2OU("<?xml?><query type='analyze'><word>") +
pTerm + A2OU("</word></query>"), nLanguage, rProperties ); pTerm + A2OU("</word></query>"), nLanguage, rProperties );
if (xTmpRes2.is()) { if (xTmpRes2.is())
{
Sequence<OUString>seq = xTmpRes2->getAlternatives(); Sequence<OUString>seq = xTmpRes2->getAlternatives();
if (seq.getLength() > 0) { if (seq.getLength() > 0)
{
codeTerm = seq[0]; codeTerm = seq[0];
stem2 = 1; stem2 = 1;
} }
#if 0 #if 0
OString o = OUStringToOString(codeTerm, rtl_getTextEncodingFromUnixCharset("UTF-8")); OString o = OUStringToOString(codeTerm, RTL_TEXTENCODING_UTF8);
fprintf(stderr, "CODETERM: %s\n", o.pData->buffer); fprintf(stderr, "CODETERM: %s\n", o.pData->buffer);
#endif #endif
} }
} }
for (int j = 0; j < nmean; j++) { for (int j = 0; j < nmean; j++)
{
int count = pe->count; int count = pe->count;
if (count) { if (count)
{
Sequence< OUString > aStr( count ); Sequence< OUString > aStr( count );
OUString *pStr = aStr.getArray(); OUString *pStr = aStr.getArray();
for (int i=0; i < count; i++) { for (int i=0; i < count; i++)
OUString sTerm(pe->psyns[i],strlen(pe->psyns[i]),aEnc ); {
OUString sTerm(pe->psyns[i],strlen(pe->psyns[i]),eEnc );
sal_Int32 catpos = sTerm.indexOf('('); sal_Int32 catpos = sTerm.indexOf('(');
sal_Int32 catpos2 = 0; sal_Int32 catpos2 = 0;
OUString catst; OUString catst;
OUString catst2; OUString catst2;
if (catpos > 2) { if (catpos > 2)
{
// remove category name for affixation and casing // remove category name for affixation and casing
catst = A2OU(" ") + sTerm.copy(catpos); catst = A2OU(" ") + sTerm.copy(catpos);
sTerm = sTerm.copy(0, catpos); sTerm = sTerm.copy(0, catpos);
sTerm = sTerm.trim(); sTerm = sTerm.trim();
} }
// generate synonyms with affixes // generate synonyms with affixes
if (stem && stem2) { if (stem && stem2)
{
Reference< XSpellAlternatives > xTmpRes; Reference< XSpellAlternatives > xTmpRes;
xTmpRes = xSpell->spell( A2OU("<?xml?><query type='generate'><word>") + xTmpRes = xSpell->spell( A2OU("<?xml?><query type='generate'><word>") +
sTerm + A2OU("</word>") + codeTerm + A2OU("</query>"), nLanguage, rProperties ); sTerm + A2OU("</word>") + codeTerm + A2OU("</query>"), nLanguage, rProperties );
if (xTmpRes.is()) { if (xTmpRes.is())
{
Sequence<OUString>seq = xTmpRes->getAlternatives(); Sequence<OUString>seq = xTmpRes->getAlternatives();
for (int k = 0; k < seq.getLength(); k++) { if (seq.getLength() > 0)
OString o = OUStringToOString(seq[k], rtl_getTextEncodingFromUnixCharset("UTF-8")); sTerm = seq[0];
}
if (seq.getLength() > 0) sTerm = seq[0];
} }
} }
if (catpos2) sTerm = catst2 + sTerm; if (catpos2)
sTerm = catst2 + sTerm;
sal_uInt16 ct1 = capitalType(sTerm, pCC); sal_uInt16 ct1 = capitalType(sTerm, pCC);
if (CAPTYPE_MIXED == ct1) if (CAPTYPE_MIXED == ct1)
ct = ct1; ct = ct1;
OUString cTerm; OUString cTerm;
switch (ct) { switch (ct)
case CAPTYPE_ALLCAP:
{ {
case CAPTYPE_ALLCAP:
cTerm = makeUpperCase(sTerm, pCC); cTerm = makeUpperCase(sTerm, pCC);
break; break;
}
case CAPTYPE_INITCAP: case CAPTYPE_INITCAP:
{
cTerm = makeInitCap(sTerm, pCC); cTerm = makeInitCap(sTerm, pCC);
break; break;
}
default: default:
{
cTerm = sTerm; cTerm = sTerm;
break; break;
} }
}
OUString aAlt( cTerm + catst); OUString aAlt( cTerm + catst);
pStr[i] = aAlt; pStr[i] = aAlt;
} }
@@ -485,7 +490,7 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
Meaning * pMn = new Meaning(rTerm,nLanguage,rHelper); Meaning * pMn = new Meaning(rTerm,nLanguage,rHelper);
#endif #endif
Meaning * pMn = new Meaning(rTerm,nLanguage); Meaning * pMn = new Meaning(rTerm,nLanguage);
OUString dTerm(pe->defn,strlen(pe->defn),aEnc ); OUString dTerm(pe->defn,strlen(pe->defn),eEnc );
pMn->SetMeaning(dTerm); pMn->SetMeaning(dTerm);
pMn->SetSynonyms(aStr); pMn->SetSynonyms(aStr);
Reference<XMeaning>* pMeaning = aMeanings.getArray(); Reference<XMeaning>* pMeaning = aMeanings.getArray();
@@ -495,32 +500,36 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
} }
pTH->CleanUpAfterLookup(&pmean,nmean); pTH->CleanUpAfterLookup(&pmean,nmean);
if (nmean) { if (nmean)
{
prevTerm = qTerm; prevTerm = qTerm;
prevMeanings = aMeanings; prevMeanings = aMeanings;
prevLocale = nLanguage; prevLocale = nLanguage;
return aMeanings; return aMeanings;
} }
if (stem || !xLngSvcMgr.is()) return noMeanings; if (stem || !xLngSvcMgr.is())
return noMeanings;
stem = 1; stem = 1;
xSpell = uno::Reference< XSpellChecker1 >( xLngSvcMgr->getSpellChecker(), UNO_QUERY ); 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; return noMeanings;
}
Reference< XSpellAlternatives > xTmpRes; Reference< XSpellAlternatives > xTmpRes;
xTmpRes = xSpell->spell( A2OU("<?xml?><query type='stem'><word>") + xTmpRes = xSpell->spell( A2OU("<?xml?><query type='stem'><word>") +
rTerm + A2OU("</word></query>"), nLanguage, rProperties ); rTerm + A2OU("</word></query>"), nLanguage, rProperties );
if (xTmpRes.is()) { if (xTmpRes.is())
{
Sequence<OUString>seq = xTmpRes->getAlternatives(); Sequence<OUString>seq = xTmpRes->getAlternatives();
#if 0 #if 0
for (int i = 0; i < seq.getLength(); i++) { for (int i = 0; i < seq.getLength(); i++)
OString o = OUStringToOString(seq[i], rtl_getTextEncodingFromUnixCharset("UTF-8")); {
OString o = OUStringToOString(seq[i], RTL_TEXTENCODING_UTF8);
fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer); fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer);
} }
#endif #endif
if (seq.getLength() > 0) { if (seq.getLength() > 0)
{
rTerm = seq[0]; // XXX Use only the first stem rTerm = seq[0]; // XXX Use only the first stem
continue; 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) // stem the last word of the synonym (for categories after affixation)
rTerm = rTerm.trim(); rTerm = rTerm.trim();
sal_Int32 pos = rTerm.lastIndexOf(' '); sal_Int32 pos = rTerm.lastIndexOf(' ');
if (!pos) return noMeanings; if (!pos)
return noMeanings;
xTmpRes = xSpell->spell( A2OU("<?xml?><query type='stem'><word>") + xTmpRes = xSpell->spell( A2OU("<?xml?><query type='stem'><word>") +
rTerm.copy(pos + 1) + A2OU("</word></query>"), nLanguage, rProperties ); rTerm.copy(pos + 1) + A2OU("</word></query>"), nLanguage, rProperties );
if (xTmpRes.is()) { if (xTmpRes.is())
{
Sequence<OUString>seq = xTmpRes->getAlternatives(); Sequence<OUString>seq = xTmpRes->getAlternatives();
if (seq.getLength() > 0) { if (seq.getLength() > 0)
{
pTerm = rTerm.copy(pos + 1); pTerm = rTerm.copy(pos + 1);
rTerm = rTerm.copy(0, pos + 1) + seq[0]; rTerm = rTerm.copy(0, pos + 1) + seq[0];
#if 0 #if 0
for (int i = 0; i < seq.getLength(); i++) { for (int i = 0; i < seq.getLength(); i++)
OString o = OUStringToOString(seq[i], rtl_getTextEncodingFromUnixCharset("UTF-8")); {
OString o = OUStringToOString(seq[i], RTL_TEXTENCODING_UTF8);
fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer); fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer);
} }
#endif #endif
@@ -552,7 +565,6 @@ Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
} }
Reference< XInterface > SAL_CALL Thesaurus_CreateInstance( Reference< XInterface > SAL_CALL Thesaurus_CreateInstance(
const Reference< XMultiServiceFactory > & /*rSMgr*/ ) const Reference< XMultiServiceFactory > & /*rSMgr*/ )
throw(Exception) throw(Exception)
@@ -562,8 +574,7 @@ Reference< XInterface > SAL_CALL Thesaurus_CreateInstance(
} }
OUString SAL_CALL OUString SAL_CALL Thesaurus::getServiceDisplayName( const Locale& /*rLocale*/ )
Thesaurus::getServiceDisplayName( const Locale& /*rLocale*/ )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -571,8 +582,7 @@ OUString SAL_CALL
} }
void SAL_CALL void SAL_CALL Thesaurus::initialize( const Sequence< Any >& rArguments )
Thesaurus::initialize( const Sequence< Any >& rArguments )
throw(Exception, RuntimeException) throw(Exception, RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -603,18 +613,20 @@ void SAL_CALL
sal_uInt16 SAL_CALL Thesaurus::capitalType(const OUString& aTerm, CharClass * pCC) sal_uInt16 SAL_CALL Thesaurus::capitalType(const OUString& aTerm, CharClass * pCC)
{ {
sal_Int32 tlen = aTerm.getLength(); sal_Int32 tlen = aTerm.getLength();
if ((pCC) && (tlen)) { if ((pCC) && (tlen))
{
String aStr(aTerm); String aStr(aTerm);
sal_Int32 nc = 0; sal_Int32 nc = 0;
for (USHORT tindex = 0; tindex < tlen; tindex++) { for (USHORT tindex = 0; tindex < tlen; tindex++)
{
if (pCC->getCharacterType(aStr,tindex) & if (pCC->getCharacterType(aStr,tindex) &
::com::sun::star::i18n::KCharacterType::UPPER) nc++; ::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 == tlen)
return (sal_uInt16) CAPTYPE_ALLCAP;
if ((nc == 1) && (pCC->getCharacterType(aStr,0) & if ((nc == 1) && (pCC->getCharacterType(aStr,0) &
::com::sun::star::i18n::KCharacterType::UPPER)) ::com::sun::star::i18n::KCharacterType::UPPER))
return (sal_uInt16) CAPTYPE_INITCAP; return (sal_uInt16) CAPTYPE_INITCAP;
@@ -645,11 +657,14 @@ OUString SAL_CALL Thesaurus::makeUpperCase(const OUString& aTerm, CharClass * pC
OUString SAL_CALL Thesaurus::makeInitCap(const OUString& aTerm, CharClass * pCC) OUString SAL_CALL Thesaurus::makeInitCap(const OUString& aTerm, CharClass * pCC)
{ {
sal_Int32 tlen = aTerm.getLength(); sal_Int32 tlen = aTerm.getLength();
if ((pCC) && (tlen)) { if ((pCC) && (tlen))
{
OUString bTemp = aTerm.copy(0,1); OUString bTemp = aTerm.copy(0,1);
if (tlen > 1) if (tlen > 1)
{
return ( pCC->toUpper_rtl(bTemp, 0, 1) return ( pCC->toUpper_rtl(bTemp, 0, 1)
+ pCC->toLower_rtl(aTerm,1,(tlen-1)) ); + pCC->toLower_rtl(aTerm,1,(tlen-1)) );
}
return pCC->toUpper_rtl(bTemp, 0, 1); return pCC->toUpper_rtl(bTemp, 0, 1);
} }
@@ -658,8 +673,7 @@ OUString SAL_CALL Thesaurus::makeInitCap(const OUString& aTerm, CharClass * pCC)
void SAL_CALL void SAL_CALL Thesaurus::dispose()
Thesaurus::dispose()
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -673,8 +687,7 @@ void SAL_CALL
} }
void SAL_CALL void SAL_CALL Thesaurus::addEventListener( const Reference< XEventListener >& rxListener )
Thesaurus::addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
@@ -684,8 +697,7 @@ void SAL_CALL
} }
void SAL_CALL void SAL_CALL Thesaurus::removeEventListener( const Reference< XEventListener >& rxListener )
Thesaurus::removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );

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

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