readed += max_length;
buffer = b;
already = 0;
+ gchar* tmp = NULL;
while(already < max_length) {
memcpy(&record_length, buffer, sizeof(guint));
memcpy(&trans_offset,
sizeof(guint)
);
buffer[record_length-sizeof(guint)*2] = '\0';
+ tmp = g_utf8_casefold(buffer+sizeof(guint), -1);
if(((record_length - 3*sizeof(guint)) == word_length) &&
- (g_utf8_collate(word,buffer+sizeof(guint)) == 0)) {
+ (g_utf8_collate(word,tmp) == 0)) {
FilePart translation = {0,0};
translation.offset = trans_offset;
memcpy(&(translation.length),
already += record_length;
buffer += record_length;
};
+ g_free(tmp);
if( ( bytes_readed < DICT_SEARCHING_WORD_TRAN_BUFF_SIZE ) ||
- ( readed > (file_size - 3) )) {
+ ( readed > (file_size - 3) ))
+ {
break;
- };
- gnome_vfs_seek(data->cache,
- GNOME_VFS_SEEK_CURRENT,
- ((gint)max_length) -
- DICT_SEARCHING_WORD_TRAN_BUFF_SIZE
- );
+ };
+ gnome_vfs_seek(data->cache,
+ GNOME_VFS_SEEK_CURRENT,
+ ((gint)max_length) -DICT_SEARCHING_WORD_TRAN_BUFF_SIZE
+ );
}
return trans;
}
//------------------------------------------------------------------------------
// searching word translation in xdxf dictionary
static gchar* word_translation_xdxf(XDXFData* data, gchar* word) {
- guint word_length = strlen(word);
+ gchar* casefold_word = g_utf8_casefold(word, -1);
+ guint word_length = strlen(casefold_word);
gchar* trans = NULL;
gnome_vfs_seek(data->xdxf, GNOME_VFS_SEEK_START, 0);
GnomeVFSResult vfs_result;
- GnomeVFSFileSize bytes_readed = DICT_SEARCHING_WORD_TRAN_BUFF_SIZE;
- gchar buffer[DICT_SEARCHING_WORD_TRAN_BUFF_SIZE+1];
+ GnomeVFSFileSize bytes_readed = DICT_SEARCHING_WORD_TRAN_BUFF_SIZE;
+ gchar buffer[DICT_SEARCHING_WORD_TRAN_BUFF_SIZE+1];
guint64 file_size = get_file_size(data->xdxf);
- //guint word_len = strlen(word); added by me
-
- XML_Parser parser = XML_ParserCreate(NULL);
+
+
+ XML_Parser parser = XML_ParserCreate(NULL);
if (!parser) {
g_warning("XDXF/%s->%s() Could not open initialize "
"XML parser.\n",
gchar tmp[DICT_MAX_WORD_LENGTH];
XDXFWordsTransData search_data = {tmp,
- word,
+ casefold_word,
word_length,
0,
NULL,
if( ('k' == el[0]) && ('\0' == el[1]) ) {
loc_data->one_word = 0;
-
- gint com = g_utf8_collate(loc_data->last_word, loc_data->word);
- if(com != 0) {
+ gchar* tmp = g_utf8_casefold(loc_data->last_word, -1);
+ gint com = g_utf8_collate(tmp, loc_data->word);
+ g_free(tmp); tmp = NULL;
+ if(com != 0)
+ {
//loc_data->cont = FALSE;
// dictionaries are not alway properly sorted, so for
// searching we should lookd in whole file!
return;
- } else if((loc_data->last_word_length == loc_data->word_len) &&
+ }
+ else if((loc_data->last_word_length == loc_data->word_len) &&
(0 == com))
{
loc_data->found = TRUE;
}
else if( (TRUE == loc_data->found) && (0 == g_utf8_collate(el,"ar")) )
{
- g_debug("Found!\n");
loc_data->found = FALSE;
loc_data->cont = FALSE;
gulong last_stop =
XDXFWordsTransData* loc_data = (XDXFWordsTransData*)data;
if( (NULL != loc_data->translation ) || (FALSE == loc_data->cont) ) {
//g_debug("STOP SEARCHING! -> _text\n");
- return;
+ return;
};
if(1 == loc_data->one_word) {
guint len = 0;
guint n = 0;
memcpy(&n,b,sizeof(guint));
- while((len + n) <= (length - 4)) {
+ while((len + n) <= length) {
len += n;
b = b + n;
+ if(len >= (length-sizeof(guint))) break;
memcpy(&n,b,sizeof(guint));
}
return len;
guint already = 0;
guint max_length = 0;
guint64 file_size = get_file_size(data->cache);
+ gchar* casefold_pattern = g_utf8_casefold(pattern, -1);
+ gchar* casefold_word = NULL;
guint pattern_len = strlen(pattern);
+ guint i = 0;
while(TRUE)
{
gnome_vfs_read(data->cache,
guint how_far = 0;
while(how_far < max_length) {
+ ++i;
memcpy(&record_length, buf, sizeof(guint));
+ gchar* tmp = g_utf8_casefold(buf + sizeof(guint), -1);
if(((record_length - 3*sizeof(guint)) >= pattern_len) &&
- ( g_ascii_strncasecmp(buf + sizeof(guint),
- pattern,
+ ( g_ascii_strncasecmp(tmp,
+ casefold_pattern,
pattern_len
) == 0 ) ) {
gchar* new = g_strndup(buf + sizeof(guint),
3*sizeof(guint));
g_array_append_val(result, new);
g_debug("New Word for pattern \"%s\" found: "
- "%s\n",
+ "%s (pos:%d)\n",
pattern,
- new
+ new,
+ i
);
};
how_far += record_length;
buf = buf + record_length;
-
+ g_free(tmp); tmp = NULL;
}
if( (bytes_readed < DICT_SEARCHING_WORD_LIST_BUFF_SIZE) ||
(already > (file_size -3)) )
DICT_SEARCHING_WORD_LIST_BUFF_SIZE
);
}
+ g_free(casefold_pattern); casefold_pattern = NULL;
timer(TIMER_STOP,(gchar*)__FUNCTION__);
timer(TIMER_START,"callback for returning words list START");