Fixed bug #74
authorkrzsas <krzsas@gmail.com>
Mon, 13 Aug 2007 11:56:36 +0000 (11:56 +0000)
committerkrzsas <krzsas@gmail.com>
Mon, 13 Aug 2007 11:56:36 +0000 (11:56 +0000)
git-svn-id: file:///svnroot/mdictionary/trunk@174 5bde0345-f819-0410-ac75-e5045f9217cc

src/bookmarks/bdb/src/engine_bookmark.c
src/plugins/stardict/src/engine_stardict.c
src/plugins/xdxf/src/engine_xdxf.c

index 2e85fff..c5af148 100755 (executable)
@@ -930,9 +930,13 @@ void bm_engine_search_word_list(Engine* engine,
        else
        {*/
        while(0 == code) {
-               down_word = g_utf8_casefold((gchar*)(search.data),-1);
+               tmp = g_strconcat ((gchar*)(search.data), " ", NULL);
+               down_word = g_utf8_casefold(tmp,-1);
+               g_free (tmp);
+               tmp = g_utf8_casefold ((gchar*)(search.data),-1);
                
-               if( g_pattern_match_string( regex, down_word ) == TRUE )
+               if(( g_pattern_match_string( regex, down_word ) == TRUE ) ||
+                       ( g_pattern_match_string( regex, tmp ) == TRUE ))
                {
                        tmp = g_strdup(search.data);
                        g_array_append_val(result, tmp );
@@ -941,6 +945,7 @@ void bm_engine_search_word_list(Engine* engine,
                //eg_free(reply.data);
                eg_free(down_word);
                code = data->db_words->seq(data->db_words, &search, &reply, R_NEXT);
+               g_free (tmp);
        }
        
         bm_timer(TIMER_STOP,(gchar*)(gchar*)__FUNCTION__);
index f96fe76..bd82855 100755 (executable)
@@ -369,6 +369,8 @@ void sd_engine_search_word_list(Engine* engine,
        gint readed =0;
        gint offset = 0;
        gchar* tmp = NULL;
+       gchar* tmp1 = NULL;
+       gchar* tmp2 = NULL;
        guint len = 0;
 //     guint pl = strlen(pattern);
        GPatternSpec* regex;
@@ -396,13 +398,19 @@ void sd_engine_search_word_list(Engine* engine,
                        further = (readed == (WORD_LIST_BUFFER_LENGTH-offset));
                }
                tmp = buffer;
-
+               
                guint i = 0;
                gint min = _MIN(readed, WORD_LIST_BUFFER_LENGTH-270);
                while(i<min)
                {
+                       tmp1 = g_strconcat (tmp, " ", NULL);
+                       tmp2 = g_utf8_casefold(tmp1, -1);
+                       g_free (tmp1);
+                       tmp1 = g_utf8_casefold(tmp, -1);
+                       
                        // check next words
-                       if(g_pattern_match_string (regex, tmp) == TRUE)
+                       if ((g_pattern_match_string (regex, tmp1) == TRUE) ||
+                               (g_pattern_match_string (regex, tmp2) == TRUE))
                        {
                                gchar* new = g_strdup(tmp);
                                g_array_append_val(result,new);
@@ -414,6 +422,9 @@ void sd_engine_search_word_list(Engine* engine,
                                        pattern
                                        );
                        }
+                       
+                       g_free (tmp1);
+                       g_free (tmp2);
                        // calculate length of word
                        len = strlen(tmp)+1;
                        // jump in buffer over this word, and ...
@@ -423,6 +434,7 @@ void sd_engine_search_word_list(Engine* engine,
                        // update i value
                        i = i + len + 2 * sizeof(guint);
                }
+               
                offset = WORD_LIST_BUFFER_LENGTH - i;
                g_memmove(buffer,buffer+WORD_LIST_BUFFER_LENGTH-offset, offset);
        }
index fb05efc..104399b 100644 (file)
@@ -1360,7 +1360,6 @@ static void search_word_list_start(void *data,
 //------------------------------------------------------------------------------
 static void search_word_list_end(void *data, const char *el)
 {
-       static gint compare_result = 0;
         static gboolean matched   = FALSE;
        static gchar* tmp = NULL;
 
@@ -1377,16 +1376,19 @@ static void search_word_list_end(void *data, const char *el)
                 return;
         }
 
-       tmp = g_utf8_casefold(loc_data->last_word, -1);
-
+       gchar *tmp1 = g_strconcat (loc_data->last_word, " ", NULL);
+       tmp = g_utf8_casefold(tmp1, -1);
+       g_free (tmp1);
+       tmp1 = g_utf8_casefold(loc_data->last_word, -1);
+       
 /*     if(loc_data->last_word_length > loc_data->pattern_len)
        {
                tmp[loc_data->pattern_len] = '\0';
        };*/
-       compare_result = g_pattern_match_string (regex, tmp);
        
-        if( ( loc_data->last_word_length >= loc_data->pattern_len ) &&
-            ( compare_result == TRUE ) )
+//     if ( loc_data->last_word_length >= loc_data->pattern_len )      
+        if (( g_pattern_match_string (regex, tmp) == TRUE ) ||
+           ( g_pattern_match_string (regex, tmp1) == TRUE ) )
        {
                 matched = TRUE;
                 gchar* new = g_strdup(loc_data->last_word);
@@ -1406,6 +1408,7 @@ static void search_word_list_end(void *data, const char *el)
                 loc_data->cont = FALSE;
         };
        g_free(tmp); tmp = NULL;
+       g_free(tmp1);
        g_pattern_spec_free (regex);
 }
 //------------------------------------------------------------------------------
@@ -1438,8 +1441,8 @@ static void word_list_cache(XDXFData* data,
         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);
+//     gchar* casefold_word = NULL;
+//     guint pattern_len = strlen(pattern);
        
        GPatternSpec* regex;
        regex = g_pattern_spec_new (casefold_pattern);
@@ -1462,10 +1465,14 @@ static void word_list_cache(XDXFData* data,
                        ++i;
                         memcpy(&record_length, buf, sizeof(guint));
                        buf[record_length-sizeof(guint)*2] = '\0';
-                       gchar* tmp = g_utf8_casefold(buf + sizeof(guint), -1);
                        
-                        if(((record_length - 3*sizeof(guint)) >= pattern_len) &&
-                           ( g_pattern_match_string (regex, tmp) == TRUE ) ) {
+                       gchar *tmp1 = g_strconcat (buf + sizeof(guint), " ", NULL);
+                       gchar* tmp = g_utf8_casefold(tmp1, -1);
+                       g_free (tmp1);
+                       
+//                     if (record_length - 3*sizeof(guint)) >= pattern_len) 
+                       
+                        if ( g_pattern_match_string (regex, tmp) == TRUE )  {
                                 gchar* new = g_strndup(buf + sizeof(guint),
                                                        record_length - 
                                                                3*sizeof(guint));