Several dictionnaries may be defined for Spell checking feature. Patch from Semen Panevin 2:5025/121

This commit is contained in:
Stas Degteff 2011-03-14 02:56:12 +00:00
parent 16dc90cfd8
commit 39bccb92ba
6 changed files with 184 additions and 23 deletions

View File

@ -402,7 +402,7 @@ public:
gstrarray robotname;
#if defined(GCFG_SPELL_INCLUDED)
int scheckerenabled;
char scheckerdeflang[100];
char scheckerdeflang[10240];
Path scheckeruserdic;
Path scheckerdicpath;
#endif

View File

@ -2094,7 +2094,7 @@ void IEclass::SaveMsg() {
#if defined(GCFG_SPELL_INCLUDED)
void IEclass::SCheckerMenu()
{
if (!schecker.IsLoaded())
if (!schecker.IsInited())
return;
const char *txt = currline->txt.c_str();
@ -2852,7 +2852,15 @@ int IEclass::Start(int __mode, uint* __position, GMsg* __msg) {
if (CFG->scheckerenabled)
{
schecker.Init(CFG->xlatlocalset, CFG->scheckerdicpath);
schecker.Load(AA->adat->scheckerdeflang, CFG->scheckeruserdic);
char str[sizeof(AA->adat->scheckerdeflang)];
strncpy(str, AA->adat->scheckerdeflang, sizeof(str));
char *token = strtok(str, " ");
while(token != NULL)
{
schecker.Load(token, CFG->scheckeruserdic);
/* Get next token: */
token = strtok(NULL, " ");
}
}
#endif

View File

@ -1113,7 +1113,7 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word)
size_t numrows = 7;
CSpellLangV &langs = schecker.GetLangs();
const char *lcode = schecker.GetLangCode();
std::vector<const char*> lcodes = schecker.GetLangCodes();
std::vector<std::string> langstr;
size_t langcount = langs.size();
@ -1126,7 +1126,19 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word)
const char *code = langs[idx]->GetLangCode();
std::string buff = " ";
buff += streql(lcode, code) ? '\x10' : ' ';
bool loaded = false;
std::vector<const char*>::iterator langit;
for (langit = lcodes.begin(); langit != lcodes.end(); langit++)
{
if (streql(*langit, code))
{
loaded = true;
break;
}
}
buff += loaded ? '\x10' : ' ';
#if !(defined(GCFG_NO_MSSPELL) || defined(GCFG_NO_MYSPELL))
if (type == SCHECKET_TYPE_MSSPELL)
@ -1224,7 +1236,14 @@ int GMenuSChecker::Run(CSpellChecker &schecker, const char *word)
}
else if ((finaltag > TAG_LANG) && (finaltag < TAG_MORE))
{
schecker.Load(langs[finaltag-TAG_LANG-1]->GetLangCode(), CFG->scheckeruserdic);
if (!schecker.IsLoaded(langs[finaltag-TAG_LANG-1]->GetLangCode()))
{
schecker.Load(langs[finaltag-TAG_LANG-1]->GetLangCode(), CFG->scheckeruserdic);
}
else
{
schecker.UnLoad(langs[finaltag-TAG_LANG-1]->GetLangCode());
}
return -2;
}

View File

@ -384,7 +384,7 @@ struct AreaData
GPlay play;
int replyre;
#if defined(GCFG_SPELL_INCLUDED)
char scheckerdeflang[100];
char scheckerdeflang[10240];
#endif
char tagline[76];
char taglinechar;

View File

@ -583,7 +583,6 @@ void CSpellLang::RecodeText(const char *srcText, char *dstText, bool flag)
CSpellChecker::CSpellChecker()
{
mInited = false;
mLang = NULL;
mText[0] = 0;
}
@ -671,20 +670,22 @@ bool CSpellChecker::Load(const char *langId, const char *userDic)
{
if (!IsInited()) return false;
if (IsLoaded() && streql(mLang->GetLangCode(), langId)) return true;
if (IsLoaded(langId))
{
return true;
}
CSpellLangV::iterator it;
for (it = mLangs.begin(); it != mLangs.end(); it++)
{
if (streql((*it)->GetLangCode(), langId) && (*it)->Load(mXlatLocalset, userDic))
{
UnLoad();
mLang = *it;
break;
mLangsLoaded.push_back(*it);
return true;
}
}
return IsLoaded();
return false;
}
@ -693,8 +694,32 @@ bool CSpellChecker::Load(const char *langId, const char *userDic)
void CSpellChecker::UnLoad()
{
if (!IsLoaded()) return;
mLang->UnLoad();
mLang = NULL;
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
(*it)->UnLoad();
}
mLangsLoaded.clear();
}
// ------------------------------------------------------------------
void CSpellChecker::UnLoad(const char *langId)
{
if (!IsLoaded()) return;
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
if (streql((*it)->GetLangCode(), langId))
{
(*it)->UnLoad();
mLangsLoaded.erase(it);
return;
}
}
}
@ -704,8 +729,16 @@ bool CSpellChecker::Check(const char *text)
{
if (!IsLoaded()) return true;
mLang->RecodeText(text, mText, true);
return mLang->SpellCheck(mText);
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
(*it)->RecodeText(text, mText, true);
if ((*it)->SpellCheck(mText))
{
return true;
}
}
return false;
}
@ -716,12 +749,110 @@ CSpellSuggestV &CSpellChecker::Suggest()
mSuggest.clear();
if (!IsLoaded()) return mSuggest;
mLang->BuildSuggest(mText, mSuggest);
CSpellSuggestV allSuggests;
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
(*it)->BuildSuggest(mText, allSuggests);
}
CSpellSuggestV::iterator all;
for (all = allSuggests.begin(); all != allSuggests.end(); all++)
{
CSpellSuggestV::iterator distinct;
bool exists = false;
for (distinct = mSuggest.begin(); distinct != mSuggest.end(); distinct++)
{
if ((*distinct).second.compare((*all).second) == 0)
{
exists = true;
break;
}
}
if (!exists)
{
mSuggest.push_back(*all);
}
}
return mSuggest;
}
// ------------------------------------------------------------------
bool CSpellChecker::AddWord()
{
if (IsLoaded())
{
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
if ((*it)->GetSpellType() == SCHECKET_TYPE_MSSPELL)
{
return (*it)->AddWord(mText);
}
}
}
return false;
}
// ------------------------------------------------------------------
const std::vector<const char*> CSpellChecker::GetLangCodes()
{
std::vector<const char*> codes;
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
codes.push_back((*it)->GetLangCode());
}
return codes;
}
// ------------------------------------------------------------------
bool CSpellChecker::IsUdrLoaded()
{
if (IsLoaded())
{
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
if ((*it)->GetSpellType() == SCHECKET_TYPE_MSSPELL)
{
return (*it)->IsUdrLoaded();
}
}
}
return false;
}
// ------------------------------------------------------------------
bool CSpellChecker::IsLoaded(const char *langId)
{
CSpellLangV::iterator it;
for (it = mLangsLoaded.begin(); it != mLangsLoaded.end(); it++)
{
if (streql((*it)->GetLangCode(), langId))
{
return true;
}
}
return false;
}
// ------------------------------------------------------------------
#if !defined(GCFG_NO_MSSPELL)

View File

@ -291,7 +291,7 @@ private:
char mXlatLocalset[256];
CSpellLang *mLang;
CSpellLangV mLangsLoaded;
CSpellLangV mLangs;
CSpellSuggestV mSuggest;
@ -303,22 +303,25 @@ public:
void Close();
bool Load(const char *langId, const char *userDic);
void UnLoad(const char *langId);
void UnLoad();
bool Check(const char *text);
CSpellSuggestV &Suggest();
bool Check(std::string &text) { return Check(text.c_str()); }
bool AddWord() { return IsLoaded() ? mLang->AddWord(mText) : false; };
bool AddWord();
CSpellSuggestV &GetSuggest() { return mSuggest; }
CSpellLangV &GetLangs() { return mLangs; }
CSpellLangV &GetLangsLoaded() { return mLangsLoaded; }
const std::vector<const char*> GetLangCodes();
const char *GetLangCode() { return IsLoaded() ? mLang->GetLangCode() : "?*N/A*?"; }
bool IsUdrLoaded() { return IsLoaded() ? mLang->IsUdrLoaded() : false; }
bool IsUdrLoaded();
bool IsInited() { return mInited; }
bool IsLoaded() { return mLang != NULL; }
bool IsLoaded() { return !mLangsLoaded.empty(); }
bool IsLoaded(const char *langId);
};