remove not used code, use glib wrappers where possible

This commit is contained in:
Evgeniy Dushistov
2013-07-07 20:12:03 +00:00
parent d05de97521
commit 5f8d2cb174
7 changed files with 202 additions and 230 deletions

View File

@@ -16,7 +16,7 @@
#include "stardict_lib.hpp"
// Notice: read src/tools/DICTFILE_FORMAT for the dictionary
// Notice: read src/tools/DICTFILE_FORMAT for the dictionary
// file's format information!
namespace {
@@ -31,19 +31,19 @@ namespace {
return( ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U' );
}
static bool bIsPureEnglish(const gchar *str)
{
static bool bIsPureEnglish(const gchar *str)
{
// i think this should work even when it is UTF8 string :).
for (int i=0; str[i]!=0; i++)
for (int i=0; str[i]!=0; i++)
//if(str[i]<0)
//if(str[i]<32 || str[i]>126) // tab equal 9,so this is not OK.
// Better use isascii() but not str[i]<0 while char is default unsigned in arm
if (!isascii(str[i]))
return false;
return true;
if (!isascii(str[i]))
return false;
return true;
}
static inline gint stardict_strcmp(const gchar *s1, const gchar *s2)
static inline gint stardict_strcmp(const gchar *s1, const gchar *s2)
{
const gint a = g_ascii_strcasecmp(s1, s2);
if (a == 0)
@@ -55,7 +55,7 @@ namespace {
static void unicode_strdown(gunichar *str)
{
while (*str) {
*str=g_unichar_tolower(*str);
*str = g_unichar_tolower(*str);
++str;
}
}
@@ -66,33 +66,29 @@ bool DictInfo::load_from_ifo_file(const std::string& ifofilename,
bool istreedict)
{
ifo_file_name = ifofilename;
gchar *buffer;
if (!g_file_get_contents(ifofilename.c_str(), &buffer, nullptr, nullptr))
glib::CharStr buffer;
if (!g_file_get_contents(ifofilename.c_str(), get_addr(buffer), nullptr, nullptr))
return false;
static const char TREEDICT_MAGIC_DATA[] = "StarDict's treedict ifo file";
static const char DICT_MAGIC_DATA[] = "StarDict's dict ifo file";
const gchar *magic_data = istreedict ? TREEDICT_MAGIC_DATA : DICT_MAGIC_DATA;
static const unsigned char utf8_bom[] = { 0xEF, 0xBB, 0xBF, '\0'};
if (!g_str_has_prefix(
g_str_has_prefix(buffer, (const gchar *)(utf8_bom)) ? buffer + 3 : buffer,
g_str_has_prefix(get_impl(buffer), (const gchar *)(utf8_bom)) ? get_impl(buffer) + 3 : get_impl(buffer),
magic_data)) {
g_free(buffer);
return false;
}
gchar *p1,*p2,*p3;
p1 = buffer + strlen(magic_data)-1;
gchar *p1 = get_impl(buffer) + strlen(magic_data)-1;
p2 = strstr(p1,"\nwordcount=");
if (!p2) {
g_free(buffer);
return false;
}
p3 = strchr(p2+ sizeof("\nwordcount=")-1,'\n');
gchar *p2 = strstr(p1, "\nwordcount=");
if (p2 == nullptr)
return false;
gchar *p3 = strchr(p2 + sizeof("\nwordcount=") - 1, '\n');
gchar *tmpstr = (gchar *)g_memdup(p2+sizeof("\nwordcount=")-1, p3-(p2+sizeof("\nwordcount=")-1)+1);
tmpstr[p3-(p2+sizeof("\nwordcount=")-1)] = '\0';
wordcount = atol(tmpstr);
@@ -100,36 +96,31 @@ bool DictInfo::load_from_ifo_file(const std::string& ifofilename,
if (istreedict) {
p2 = strstr(p1,"\ntdxfilesize=");
if (!p2) {
g_free(buffer);
if (p2 == nullptr)
return false;
}
p3 = strchr(p2+ sizeof("\ntdxfilesize=")-1,'\n');
tmpstr = (gchar *)g_memdup(p2+sizeof("\ntdxfilesize=")-1, p3-(p2+sizeof("\ntdxfilesize=")-1)+1);
tmpstr[p3-(p2+sizeof("\ntdxfilesize=")-1)] = '\0';
index_file_size = atol(tmpstr);
g_free(tmpstr);
} else {
p2 = strstr(p1,"\nidxfilesize=");
if (!p2) {
g_free(buffer);
if (p2 == nullptr)
return false;
}
p3 = strchr(p2+ sizeof("\nidxfilesize=")-1,'\n');
tmpstr = (gchar *)g_memdup(p2+sizeof("\nidxfilesize=")-1, p3-(p2+sizeof("\nidxfilesize=")-1)+1);
tmpstr[p3-(p2+sizeof("\nidxfilesize=")-1)] = '\0';
index_file_size = atol(tmpstr);
g_free(tmpstr);
}
p2 = strstr(p1,"\nbookname=");
if (!p2) {
g_free(buffer);
if (p2 == nullptr)
return false;
}
p2 = p2 + sizeof("\nbookname=") -1;
p3 = strchr(p2, '\n');
@@ -171,35 +162,33 @@ bool DictInfo::load_from_ifo_file(const std::string& ifofilename,
}
p2 = strstr(p1,"\nsametypesequence=");
if (p2) {
if (p2) {
p2+=sizeof("\nsametypesequence=")-1;
p3 = strchr(p2, '\n');
sametypesequence.assign(p2, p3-p2);
}
g_free(buffer);
return true;
return true;
}
gchar* DictBase::GetWordData(guint32 idxitem_offset, guint32 idxitem_size)
{
for (int i=0; i<WORDDATA_CACHE_NUM; i++)
for (int i=0; i<WORDDATA_CACHE_NUM; i++)
if (cache[i].data && cache[i].offset == idxitem_offset)
return cache[i].data;
if (dictfile)
fseek(dictfile, idxitem_offset, SEEK_SET);
gchar *data;
if (!sametypesequence.empty()) {
gchar *origin_data = (gchar *)g_malloc(idxitem_size);
if (dictfile)
fread(origin_data, idxitem_size, 1, dictfile);
else
dictdzfile->read(origin_data, idxitem_offset, idxitem_size);
guint32 data_size;
gint sametypesequence_len = sametypesequence.length();
//there have sametypesequence_len char being omitted.
@@ -225,7 +214,7 @@ gchar* DictBase::GetWordData(guint32 idxitem_offset, guint32 idxitem_size)
else
data_size += sizeof(gchar);
break;
}
}
data = (gchar *)g_malloc(data_size);
gchar *p1,*p2;
p1 = data + sizeof(guint32);
@@ -266,8 +255,8 @@ gchar* DictBase::GetWordData(guint32 idxitem_offset, guint32 idxitem_size)
p1+=sec_size;
p2+=sec_size;
break;
}
}
}
}
//calculate the last item 's size.
sec_size = idxitem_size - (p2-origin_data);
*p1=sametypesequence[sametypesequence_len-1];
@@ -280,7 +269,7 @@ gchar* DictBase::GetWordData(guint32 idxitem_offset, guint32 idxitem_size)
case 'g':
case 'x':
memcpy(p1, p2, sec_size);
p1 += sec_size;
p1 += sec_size;
*p1='\0';//add the end up '\0';
break;
case 'W':
@@ -301,18 +290,18 @@ gchar* DictBase::GetWordData(guint32 idxitem_offset, guint32 idxitem_size)
}
break;
}
g_free(origin_data);
g_free(origin_data);
set_uint32(data, data_size);
} else {
} else {
data = (gchar *)g_malloc(idxitem_size + sizeof(guint32));
if (dictfile)
fread(data+sizeof(guint32), idxitem_size, 1, dictfile);
fread(data+sizeof(guint32), idxitem_size, 1, dictfile);
else
dictdzfile->read(data+sizeof(guint32), idxitem_offset, idxitem_size);
set_uint32(data, idxitem_size+sizeof(guint32));
}
}
g_free(cache[cache_cur].data);
cache[cache_cur].data = data;
cache[cache_cur].offset = idxitem_offset;
cache_cur++;
@@ -351,7 +340,7 @@ bool DictBase::SearchData(std::vector<std::string> &SearchWords, guint32 idxitem
WordFind[j] = true;
++nfound;
}
if (nfound==nWord)
return true;
@@ -377,12 +366,12 @@ bool DictBase::SearchData(std::vector<std::string> &SearchWords, guint32 idxitem
case 'x':
sec_size = idxitem_size - (p-origin_data);
for (j=0; j<nWord; j++)
if (!WordFind[j] &&
if (!WordFind[j] &&
g_strstr_len(p, sec_size, SearchWords[j].c_str())) {
WordFind[j] = true;
++nfound;
}
if (nfound==nWord)
return true;
@@ -401,7 +390,7 @@ bool DictBase::SearchData(std::vector<std::string> &SearchWords, guint32 idxitem
if (!WordFind[j] && strstr(p, SearchWords[j].c_str())) {
WordFind[j] = true;
++nfound;
}
}
if (nfound==nWord)
return true;
@@ -496,7 +485,7 @@ namespace {
std::vector<gchar *> wordlist;
};
void OffsetIndex::page_t::fill(gchar *data, gint nent, glong idx_)
void OffsetIndex::page_t::fill(gchar *data, gint nent, glong idx_)
{
idx=idx_;
gchar *p=data;
@@ -547,7 +536,7 @@ namespace {
g_stat(item.c_str(), &cachestat)!=0)
continue;
if (cachestat.st_mtime<idxstat.st_mtime)
continue;
continue;
MapFile mf;
if (!mf.open(item.c_str(), cachestat.st_size))
continue;
@@ -608,7 +597,7 @@ namespace {
if (!load_cache(url)) {//map file will close after finish of block
MapFile map_file;
if (!map_file.open(url.c_str(), fsize))
return false;
return false;
const gchar *idxdatabuffer=map_file.begin();
const gchar *p1 = idxdatabuffer;
@@ -646,7 +635,7 @@ namespace {
if (page_idx==glong(wordoffset.size()-2))
if ((nentr=wordcount%ENTR_PER_PAGE)==0)
nentr=ENTR_PER_PAGE;
if (page_idx!=page.idx) {
page_data.resize(wordoffset[page_idx+1]-wordoffset[page_idx]);
@@ -691,7 +680,7 @@ namespace {
iFrom=iThisIndex+1;
else if (cmpint<0)
iTo=iThisIndex-1;
else {
else {
bFound=true;
break;
}
@@ -699,7 +688,7 @@ namespace {
if (!bFound)
idx = iTo; //prev
else
idx = iThisIndex;
idx = iThisIndex;
}
if (!bFound) {
gulong netr=load_page(idx);
@@ -732,11 +721,11 @@ namespace {
bool WordListIndex::load(const std::string& url, gulong wc, gulong fsize)
{
gzFile in = gzopen(url.c_str(), "rb");
if (in == nullptr)
return false;
if (in == nullptr)
return false;
idxdatabuf = (gchar *)g_malloc(fsize);
const int len = gzread(in, idxdatabuf, fsize);
gzclose(in);
if (len < 0)
@@ -793,23 +782,23 @@ namespace {
if (!bFound)
idx = iFrom; //next
else
idx = iThisIndex;
idx = iThisIndex;
}
return bFound;
}
}
bool Dict::load(const std::string& ifofilename)
{
{
gulong idxfilesize;
if (!load_ifofile(ifofilename, idxfilesize))
return false;
std::string fullfilename(ifofilename);
fullfilename.replace(fullfilename.length()-sizeof("ifo")+1, sizeof("ifo")-1, "dict.dz");
if (g_file_test(fullfilename.c_str(), G_FILE_TEST_EXISTS)) {
dictdzfile.reset(new dictData);
dictdzfile.reset(new DictData);
if (!dictdzfile->open(fullfilename, 0)) {
//g_print("open file %s failed!\n",fullfilename);
return false;
@@ -825,7 +814,7 @@ bool Dict::load(const std::string& ifofilename)
fullfilename=ifofilename;
fullfilename.replace(fullfilename.length()-sizeof("ifo")+1, sizeof("ifo")-1, "idx.gz");
if (g_file_test(fullfilename.c_str(), G_FILE_TEST_EXISTS)) {
idx_file.reset(new WordListIndex);
} else {
@@ -852,7 +841,7 @@ bool Dict::load_ifofile(const std::string& ifofilename, gulong &idxfilesize)
wordcount=dict_info.wordcount;
bookname=dict_info.bookname;
idxfilesize=dict_info.index_file_size;
idxfilesize=dict_info.index_file_size;
sametypesequence=dict_info.sametypesequence;
@@ -862,13 +851,13 @@ bool Dict::load_ifofile(const std::string& ifofilename, gulong &idxfilesize)
bool Dict::LookupWithRule(GPatternSpec *pspec, glong *aIndex, int iBuffLen)
{
int iIndexCount = 0;
for (guint32 i=0; i < narticles() && iIndexCount < (iBuffLen - 1); i++)
if (g_pattern_match_string(pspec, get_key(i)))
if (g_pattern_match_string(pspec, get_key(i)))
aIndex[iIndexCount++] = i;
aIndex[iIndexCount] = -1; // -1 is the end.
aIndex[iIndexCount] = -1; // -1 is the end.
return iIndexCount > 0;
}
@@ -888,25 +877,25 @@ void Libs::load_dict(const std::string& url)
}
void Libs::load(const std::list<std::string>& dicts_dirs,
const std::list<std::string>& order_list,
const std::list<std::string>& order_list,
const std::list<std::string>& disable_list)
{
for_each_file(dicts_dirs, ".ifo", order_list, disable_list,
for_each_file(dicts_dirs, ".ifo", order_list, disable_list,
[this](const std::string& url, bool disable) -> void {
if (!disable)
load_dict(url);
load_dict(url);
});
}
void Libs::reload(const std::list<std::string>& dicts_dirs,
const std::list<std::string>& order_list,
void Libs::reload(const std::list<std::string>& dicts_dirs,
const std::list<std::string>& order_list,
const std::list<std::string>& disable_list)
{
std::vector<Dict *> prev(oLib);
oLib.clear();
for_each_file(dicts_dirs, ".ifo", order_list, disable_list,
[&prev, this](const std::string& url, bool disable) -> void {
for_each_file(dicts_dirs, ".ifo", order_list, disable_list,
[&prev, this](const std::string& url, bool disable) -> void {
if (!disable) {
auto it = prev.begin();
for (; it != prev.end(); ++it)
@@ -917,14 +906,14 @@ void Libs::reload(const std::list<std::string>& dicts_dirs,
prev.erase(it);
oLib.push_back(res);
} else
load_dict(url);
load_dict(url);
}
});
for (Dict *p : prev)
delete p;
}
const gchar *Libs::poGetCurrentWord(glong * iCurrent)
{
const gchar *poCurrentWord = nullptr;
@@ -938,7 +927,7 @@ const gchar *Libs::poGetCurrentWord(glong * iCurrent)
poCurrentWord = poGetWord(iCurrent[iLib],iLib);
} else {
word = poGetWord(iCurrent[iLib],iLib);
if (stardict_strcmp(poCurrentWord, word) > 0 )
poCurrentWord = word;
}
@@ -967,7 +956,7 @@ const gchar *Libs::poGetNextWord(const gchar *sWord, glong *iCurrent)
iCurrentLib = iLib;
} else {
word = poGetWord(iCurrent[iLib],iLib);
if (stardict_strcmp(poCurrentWord, word) > 0 ) {
poCurrentWord = word;
iCurrentLib = iLib;
@@ -1018,7 +1007,7 @@ Libs::poGetPreWord(glong * iCurrent)
}
}
}
if (poCurrentWord) {
iCurrent[iCurrentLib]--;
for (std::vector<Dict *>::size_type iLib=0;iLib<oLib.size();iLib++) {
@@ -1059,7 +1048,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
bFound=true;
}
g_free(casestr);
}
}
// Upper the first character and lower others.
if (!bFound) {
gchar *nextchar = g_utf8_next_char(sWord);
@@ -1073,14 +1062,14 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
bFound=true;
}
g_free(casestr);
}
}
}
if (bIsPureEnglish(sWord)) {
if (bIsPureEnglish(sWord)) {
// If not Found , try other status of sWord.
int iWordLen=strlen(sWord);
bool isupcase;
gchar *sNewWord = (gchar *)g_malloc(iWordLen + 1);
//cut one char "s" or "d"
@@ -1101,7 +1090,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
}
}
}
//cut "ly"
if(!bFound && iWordLen>2) {
isupcase = !strncmp(&sWord[iWordLen-2],"LY",2);
@@ -1109,9 +1098,9 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
strcpy(sNewWord,sWord);
sNewWord[iWordLen-2]='\0'; // cut "ly"
if (iWordLen>5 && sNewWord[iWordLen-3]==sNewWord[iWordLen-4]
&& !bIsVowel(sNewWord[iWordLen-4]) &&
&& !bIsVowel(sNewWord[iWordLen-4]) &&
bIsVowel(sNewWord[iWordLen-5])) {//doubled
sNewWord[iWordLen-3]='\0';
if( oLib[iLib]->Lookup(sNewWord, iIndex) )
bFound=true;
@@ -1126,7 +1115,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
}
if (!bFound)
sNewWord[iWordLen-3]=sNewWord[iWordLen-4]; //restore
}
}
}
if (!bFound) {
if (oLib[iLib]->Lookup(sNewWord, iIndex))
@@ -1142,7 +1131,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
}
}
}
//cut "ing"
if(!bFound && iWordLen>3) {
isupcase = !strncmp(&sWord[iWordLen-3],"ING",3);
@@ -1150,8 +1139,8 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
strcpy(sNewWord,sWord);
sNewWord[iWordLen-3]='\0';
if ( iWordLen>6 && (sNewWord[iWordLen-4]==sNewWord[iWordLen-5])
&& !bIsVowel(sNewWord[iWordLen-5]) &&
bIsVowel(sNewWord[iWordLen-6])) { //doubled
&& !bIsVowel(sNewWord[iWordLen-5]) &&
bIsVowel(sNewWord[iWordLen-6])) { //doubled
sNewWord[iWordLen-4]='\0';
if (oLib[iLib]->Lookup(sNewWord, iIndex))
bFound=true;
@@ -1178,7 +1167,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
bFound=true;
}
g_free(casestr);
}
}
}
if(!bFound) {
if (isupcase)
@@ -1194,25 +1183,25 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
bFound=true;
}
g_free(casestr);
}
}
}
}
}
//cut two char "es"
if(!bFound && iWordLen>3) {
isupcase = (!strncmp(&sWord[iWordLen-2],"ES",2) &&
(sWord[iWordLen-3] == 'S' ||
sWord[iWordLen-3] == 'X' ||
sWord[iWordLen-3] == 'O' ||
(iWordLen >4 && sWord[iWordLen-3] == 'H' &&
(sWord[iWordLen-4] == 'C' ||
isupcase = (!strncmp(&sWord[iWordLen-2],"ES",2) &&
(sWord[iWordLen-3] == 'S' ||
sWord[iWordLen-3] == 'X' ||
sWord[iWordLen-3] == 'O' ||
(iWordLen >4 && sWord[iWordLen-3] == 'H' &&
(sWord[iWordLen-4] == 'C' ||
sWord[iWordLen-4] == 'S'))));
if (isupcase ||
(!strncmp(&sWord[iWordLen-2],"es",2) &&
(sWord[iWordLen-3] == 's' || sWord[iWordLen-3] == 'x' ||
sWord[iWordLen-3] == 'o' ||
(iWordLen >4 && sWord[iWordLen-3] == 'h' &&
if (isupcase ||
(!strncmp(&sWord[iWordLen-2],"es",2) &&
(sWord[iWordLen-3] == 's' || sWord[iWordLen-3] == 'x' ||
sWord[iWordLen-3] == 'o' ||
(iWordLen >4 && sWord[iWordLen-3] == 'h' &&
(sWord[iWordLen-4] == 'c' || sWord[iWordLen-4] == 's'))))) {
strcpy(sNewWord,sWord);
sNewWord[iWordLen-2]='\0';
@@ -1228,7 +1217,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
}
}
}
//cut "ed"
if (!bFound && iWordLen>3) {
isupcase = !strncmp(&sWord[iWordLen-2],"ED",2);
@@ -1236,8 +1225,8 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
strcpy(sNewWord,sWord);
sNewWord[iWordLen-2]='\0';
if (iWordLen>5 && (sNewWord[iWordLen-3]==sNewWord[iWordLen-4])
&& !bIsVowel(sNewWord[iWordLen-4]) &&
bIsVowel(sNewWord[iWordLen-5])) {//doubled
&& !bIsVowel(sNewWord[iWordLen-4]) &&
bIsVowel(sNewWord[iWordLen-5])) {//doubled
sNewWord[iWordLen-3]='\0';
if (oLib[iLib]->Lookup(sNewWord, iIndex))
bFound=true;
@@ -1268,7 +1257,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
}
}
}
// cut "ied" , add "y".
if (!bFound && iWordLen>3) {
isupcase = !strncmp(&sWord[iWordLen-3],"IED",3);
@@ -1291,7 +1280,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
}
}
}
// cut "ies" , add "y".
if (!bFound && iWordLen>3) {
isupcase = !strncmp(&sWord[iWordLen-3],"IES",3);
@@ -1333,7 +1322,7 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
}
}
}
// cut "est".
if (!bFound && iWordLen>3) {
isupcase = !strncmp(&sWord[iWordLen-3], "EST", 3);
@@ -1352,10 +1341,10 @@ bool Libs::LookupSimilarWord(const gchar* sWord, glong & iWordIndex, int iLib)
}
}
}
g_free(sNewWord);
}
}
if (bFound)
iWordIndex = iIndex;
#if 0
@@ -1381,7 +1370,7 @@ bool Libs::LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_si
if (sWord[0] == '\0')
return false;
Fuzzystruct oFuzzystruct[reslist_size];
Fuzzystruct oFuzzystruct[reslist_size];
for (int i = 0; i < reslist_size; i++) {
oFuzzystruct[i].pMatchWord = nullptr;
@@ -1412,13 +1401,13 @@ bool Libs::LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_si
sCheck = poGetWord(index,iLib);
// tolower and skip too long or too short words
iCheckWordLen = g_utf8_strlen(sCheck, -1);
if (iCheckWordLen-ucs4_str2_len>=iMaxDistance ||
if (iCheckWordLen-ucs4_str2_len>=iMaxDistance ||
ucs4_str2_len-iCheckWordLen>=iMaxDistance)
continue;
ucs4_str1 = g_utf8_to_ucs4_fast(sCheck, -1, nullptr);
if (iCheckWordLen > ucs4_str2_len)
ucs4_str1[ucs4_str2_len]=0;
unicode_strdown(ucs4_str1);
unicode_strdown(ucs4_str1);
iDistance = oEditDistance.CalEditDistance(ucs4_str1, ucs4_str2, iMaxDistance);
g_free(ucs4_str1);
@@ -1428,7 +1417,7 @@ bool Libs::LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_si
bool bAlreadyInList = false;
int iMaxDistanceAt=0;
for (int j=0; j<reslist_size; j++) {
if (oFuzzystruct[j].pMatchWord &&
if (oFuzzystruct[j].pMatchWord &&
strcmp(oFuzzystruct[j].pMatchWord,sCheck)==0 ) {//already in list
bAlreadyInList = true;
break;
@@ -1455,7 +1444,7 @@ bool Libs::LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_si
} // each lib
g_free(ucs4_str2);
if (Found)// sort with distance
std::sort(oFuzzystruct, oFuzzystruct + reslist_size, [](const Fuzzystruct& lh, const Fuzzystruct& rh) -> bool {
if (lh.iMatchWordDistance!=rh.iMatchWordDistance)
@@ -1463,26 +1452,26 @@ bool Libs::LookupWithFuzzy(const gchar *sWord, gchar *reslist[], gint reslist_si
if (lh.pMatchWord && rh.pMatchWord)
return stardict_strcmp(lh.pMatchWord, rh.pMatchWord)<0;
return false;
});
for (gint i = 0; i < reslist_size; ++i)
reslist[i] = oFuzzystruct[i].pMatchWord;
return Found;
}
gint Libs::LookupWithRule(const gchar *word, gchar **ppMatchWord)
{
{
glong aiIndex[MAX_MATCH_ITEM_PER_LIB+1];
gint iMatchCount = 0;
GPatternSpec *pspec = g_pattern_spec_new(word);
for (std::vector<Dict *>::size_type iLib=0; iLib<oLib.size(); iLib++) {
//if(oLibs.LookdupWordsWithRule(pspec,aiIndex,MAX_MATCH_ITEM_PER_LIB+1-iMatchCount,iLib))
//if(oLibs.LookdupWordsWithRule(pspec,aiIndex,MAX_MATCH_ITEM_PER_LIB+1-iMatchCount,iLib))
// -iMatchCount,so save time,but may got less result and the word may repeat.
if (oLib[iLib]->LookupWithRule(pspec,aiIndex, MAX_MATCH_ITEM_PER_LIB+1)) {
if (progress_func)
progress_func();
@@ -1501,12 +1490,12 @@ gint Libs::LookupWithRule(const gchar *word, gchar **ppMatchWord)
}
}
g_pattern_spec_free(pspec);
if (iMatchCount)// sort it.
std::sort(ppMatchWord, ppMatchWord+iMatchCount, [](const char *lh, const char *rh) -> bool {
return stardict_strcmp(lh, rh)<0;
});
});
return iMatchCount;
}
@@ -1577,7 +1566,7 @@ bool Libs::LookupData(const gchar *sWord, std::vector<gchar *> *reslist)
for (i = 0; i < oLib.size(); ++i)
if (!reslist[i].empty())
break;
return i != oLib.size();
}