[Tomoe-cvs 1926] CVS update: tomoe/module/dict

Back to archive index

Kouhei Sutou kous****@users*****
2006年 12月 18日 (月) 10:02:07 JST


Index: tomoe/module/dict/tomoe-dict-est.c
diff -u tomoe/module/dict/tomoe-dict-est.c:1.13 tomoe/module/dict/tomoe-dict-est.c:1.14
--- tomoe/module/dict/tomoe-dict-est.c:1.13	Tue Dec 12 19:08:12 2006
+++ tomoe/module/dict/tomoe-dict-est.c	Mon Dec 18 10:02:06 2006
@@ -17,7 +17,7 @@
  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *  Boston, MA  02111-1307  USA
  *
- *  $Id: tomoe-dict-est.c,v 1.13 2006/12/12 10:08:12 kous Exp $
+ *  $Id: tomoe-dict-est.c,v 1.14 2006/12/18 01:02:06 kous Exp $
  */
 
 #include <stdio.h>
@@ -100,6 +100,7 @@
                                                TomoeQuery    *query);
 static gboolean     flush                     (TomoeDict     *dict);
 static gboolean     is_editable               (TomoeDict     *dict);
+static gchar       *get_available_private_utf8 (TomoeDict    *dict);
 static gboolean     tomoe_dict_est_open       (TomoeDictEst  *dict);
 static gboolean     tomoe_dict_est_close      (TomoeDictEst  *dict);
 
@@ -126,6 +127,7 @@
     dict_class->search          = search;
     dict_class->flush           = flush;
     dict_class->is_editable     = is_editable;
+    dict_class->get_available_private_utf8 = get_available_private_utf8;
 
     g_object_class_install_property (
         gobject_class,
@@ -332,6 +334,10 @@
         g_free (value);
 
         est_doc_add_attr (doc, "utf8", original_value);
+
+        value = g_strdup_printf ("%d", g_utf8_get_char (original_value));
+        est_doc_add_attr (doc, "code-point", value);
+        g_free (value);
     }
 
     n_strokes = tomoe_char_get_n_strokes (chr);
@@ -344,7 +350,7 @@
 
     if (n_strokes >= 0) {
         value = g_strdup_printf ("%d", n_strokes);
-        est_doc_add_attr (doc, "n_strokes", value);
+        est_doc_add_attr (doc, "n-strokes", value);
         g_free (value);
     }
 
@@ -479,28 +485,34 @@
     g_return_val_if_fail (TOMOE_IS_DICT_EST (dict), candidates);
 
     cond = est_cond_new ();
-    est_cond_set_phrase (cond, "</character>");
     est_cond_set_order (cond, "utf8 STRA");
 
-    min_n_strokes = tomoe_query_get_min_n_strokes (query);
-    if (min_n_strokes >= 0) {
-        expr = g_strdup_printf ("n_strokes NUMGE %d", min_n_strokes);
-        est_cond_add_attr (cond, expr);
-        g_free (expr);
-    }
-
-    max_n_strokes = tomoe_query_get_max_n_strokes (query);
-    if (max_n_strokes >= 0) {
-        expr = g_strdup_printf ("n_strokes NUMLE %d", max_n_strokes);
-        est_cond_add_attr (cond, expr);
-        g_free (expr);
-    }
-
-    reading = g_list_nth_data ((GList *)tomoe_query_get_readings (query), 0);
-    if (reading) {
-        expr = tomoe_reading_to_xml (reading);
-        est_cond_set_phrase (cond, expr);
-        g_free (expr);
+    if (tomoe_query_is_empty (query)) {
+        est_cond_set_phrase (cond, "[UVSET]");
+    } else {
+        GList *node;
+
+        min_n_strokes = tomoe_query_get_min_n_strokes (query);
+        if (min_n_strokes >= 0) {
+            expr = g_strdup_printf ("n-strokes NUMGE %d", min_n_strokes);
+            est_cond_add_attr (cond, expr);
+            g_free (expr);
+        }
+
+        max_n_strokes = tomoe_query_get_max_n_strokes (query);
+        if (max_n_strokes >= 0) {
+            expr = g_strdup_printf ("n-strokes NUMLE %d", max_n_strokes);
+            est_cond_add_attr (cond, expr);
+            g_free (expr);
+        }
+
+        node = (GList *)tomoe_query_get_readings (query);
+        reading = node ? node->data : NULL;
+        if (reading) {
+            expr = tomoe_reading_to_xml (reading);
+            est_cond_set_phrase (cond, expr);
+            g_free (expr);
+        }
     }
 
     results = est_db_search (dict->db, cond, &n_results, NULL);
@@ -536,6 +548,63 @@
     return dict->editable;
 }
 
+static gchar *
+get_available_private_utf8 (TomoeDict *_dict)
+{
+    TomoeDictEst *dict = TOMOE_DICT_EST (_dict);
+    ESTCOND *cond;
+    gchar *expr;
+    int i, *results, n_results;
+    gunichar result_ucs = TOMOE_CHAR_PRIVATE_USE_AREA_START;
+
+    g_return_val_if_fail (TOMOE_IS_DICT_EST (dict), FALSE);
+
+    cond = est_cond_new ();
+    est_cond_set_order (cond, "utf8 STRA");
+    est_cond_set_max (cond, 1);
+
+    expr = g_strdup_printf ("code-point NUMGE %d",
+                            TOMOE_CHAR_PRIVATE_USE_AREA_START);
+    est_cond_add_attr (cond, expr);
+    g_free (expr);
+
+    expr = g_strdup_printf ("code-point NUMLE %d",
+                            TOMOE_CHAR_PRIVATE_USE_AREA_END);
+    est_cond_add_attr (cond, expr);
+    g_free (expr);
+
+    results = est_db_search (dict->db, cond, &n_results, NULL);
+    for (i = 0; i < n_results; i++) {
+        TomoeChar *chr;
+        gunichar ucs;
+
+        chr = retrieve_char_by_id (dict, results[i]);
+        ucs = g_utf8_get_char (tomoe_char_get_utf8 (chr));
+        if (ucs >= TOMOE_CHAR_PRIVATE_USE_AREA_START) {
+            if (ucs >= TOMOE_CHAR_PRIVATE_USE_AREA_END) {
+                result_ucs = 0;
+            } else {
+                result_ucs = ucs + 1;
+            }
+        }
+    }
+    g_free (results);
+    est_cond_delete (cond);
+
+    if (result_ucs >= TOMOE_CHAR_PRIVATE_USE_AREA_START) {
+        gint result_len;
+        gchar *result;
+
+        result_len = g_unichar_to_utf8 (result_ucs, NULL);
+        result = g_new (gchar, result_len + 1);
+        g_unichar_to_utf8 (result_ucs, result);
+        result[result_len] = '\0';
+        return result;
+    } else {
+        return NULL;
+    }
+}
+
 static gboolean
 tomoe_dict_est_open (TomoeDictEst *dict)
 {
Index: tomoe/module/dict/tomoe-dict-mysql.c
diff -u tomoe/module/dict/tomoe-dict-mysql.c:1.8 tomoe/module/dict/tomoe-dict-mysql.c:1.9
--- tomoe/module/dict/tomoe-dict-mysql.c:1.8	Tue Dec 12 18:29:56 2006
+++ tomoe/module/dict/tomoe-dict-mysql.c	Mon Dec 18 10:02:06 2006
@@ -17,7 +17,7 @@
  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *  Boston, MA  02111-1307  USA
  *
- *  $Id: tomoe-dict-mysql.c,v 1.8 2006/12/12 09:29:56 kous Exp $
+ *  $Id: tomoe-dict-mysql.c,v 1.9 2006/12/18 01:02:06 kous Exp $
  */
 
 #include <string.h>
@@ -657,7 +657,7 @@
 
     utf8 = tomoe_query_get_utf8 (query);
     if (utf8) {
-        g_string_append (sql, " AND utf8 = ");
+        g_string_append (sql, " AND chars.utf8 = ");
         append_string_value (dict, sql, utf8);
     }
 }
@@ -861,7 +861,7 @@
     GList *cands;
 
     g_return_val_if_fail (TOMOE_IS_DICT_MYSQL (dict), chr);
-    g_return_val_if_fail (TOMOE_IS_CHAR (chr), chr);
+    g_return_val_if_fail (utf8 && utf8[0] != '\0', chr);
 
     g_return_val_if_fail (dict->mysql, chr);
 
@@ -871,7 +871,7 @@
     g_object_unref (query);
 
     if (cands) {
-        chr = g_object_ref (cands->data);
+        chr = g_object_ref (tomoe_candidate_get_char (cands->data));
         g_list_foreach (cands, (GFunc) g_object_unref, NULL);
         g_list_free (cands);
     }
Index: tomoe/module/dict/tomoe-dict-ptr-array.c
diff -u tomoe/module/dict/tomoe-dict-ptr-array.c:1.3 tomoe/module/dict/tomoe-dict-ptr-array.c:1.4
--- tomoe/module/dict/tomoe-dict-ptr-array.c:1.3	Wed Dec  6 15:28:36 2006
+++ tomoe/module/dict/tomoe-dict-ptr-array.c	Mon Dec 18 10:02:06 2006
@@ -17,7 +17,7 @@
  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *  Boston, MA  02111-1307  USA
  *
- *  $Id: tomoe-dict-ptr-array.c,v 1.3 2006/12/06 06:28:36 kous Exp $
+ *  $Id: tomoe-dict-ptr-array.c,v 1.4 2006/12/18 01:02:06 kous Exp $
  */
 
 #include <string.h>
@@ -169,6 +169,16 @@
                                        tomoe_candidate_new (chr));
 }
 
+static void
+collect_all_chars (gpointer data, gpointer user_data)
+{
+    TomoeChar *chr = data;
+    TomoeDictSearchContext *context = user_data;
+
+    context->results = g_list_prepend (context->results,
+                                       tomoe_candidate_new (chr));
+}
+
 GList *
 _tomoe_dict_ptr_array_search (GPtrArray *chars, TomoeQuery *query)
 {
@@ -177,8 +187,13 @@
     search_context.query = g_object_ref (query);
     search_context.results = NULL;
 
-    g_ptr_array_foreach_reverse (chars, collect_chars_by_query,
-                                 &search_context);
+    if (tomoe_query_is_empty (query)) {
+        g_ptr_array_foreach_reverse (chars, collect_all_chars,
+                                     &search_context);
+    } else {
+        g_ptr_array_foreach_reverse (chars, collect_chars_by_query,
+                                     &search_context);
+    }
     g_object_unref (search_context.query);
 
     return search_context.results;


tomoe-cvs メーリングリストの案内
Back to archive index