Kouhei Sutou
kous****@users*****
2006年 11月 27日 (月) 17:52:01 JST
Index: tomoe/lib/Makefile.am diff -u tomoe/lib/Makefile.am:1.37 tomoe/lib/Makefile.am:1.38 --- tomoe/lib/Makefile.am:1.37 Sat Nov 25 16:01:29 2006 +++ tomoe/lib/Makefile.am Mon Nov 27 17:52:01 2006 @@ -62,6 +62,7 @@ lib_LTLIBRARIES = libtomoe.la libtomoe_la_SOURCES = \ + glib-utils.c \ glib-utils.h \ tomoe-enum-types.c \ tomoe.c \ Index: tomoe/lib/glib-utils.c diff -u /dev/null tomoe/lib/glib-utils.c:1.1 --- /dev/null Mon Nov 27 17:52:01 2006 +++ tomoe/lib/glib-utils.c Mon Nov 27 17:52:01 2006 @@ -0,0 +1,40 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2006 Kouhei Sutou <kou****@cozmi*****> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id: glib-utils.c,v 1.1 2006/11/27 08:52:01 kous Exp $ + */ + +#include <glib.h> +#include "glib-utils.h" + +void +g_ptr_array_foreach_reverse (GPtrArray *array, + GFunc func, + gpointer user_data) +{ + guint i; + + for (i = array->len - 1; i; i--) { + func (g_ptr_array_index (array, i), user_data); + } +} + +/* +vi:ts=4:nowrap:ai:expandtab +*/ Index: tomoe/lib/glib-utils.h diff -u tomoe/lib/glib-utils.h:1.4 tomoe/lib/glib-utils.h:1.5 --- tomoe/lib/glib-utils.h:1.4 Sat Nov 25 12:32:19 2006 +++ tomoe/lib/glib-utils.h Mon Nov 27 17:52:01 2006 @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: glib-utils.h,v 1.4 2006/11/25 03:32:19 kous Exp $ + * $Id: glib-utils.h,v 1.5 2006/11/27 08:52:01 kous Exp $ */ @@ -43,6 +43,10 @@ error = NULL; \ } while (FALSE) +void g_ptr_array_foreach_reverse (GPtrArray *array, + GFunc func, + gpointer user_data); + G_END_DECLS #endif /* __GLIB_UTILS_H__ */ Index: tomoe/lib/tomoe-dict.c diff -u tomoe/lib/tomoe-dict.c:1.111 tomoe/lib/tomoe-dict.c:1.112 --- tomoe/lib/tomoe-dict.c:1.111 Mon Nov 27 17:39:17 2006 +++ tomoe/lib/tomoe-dict.c Mon Nov 27 17:52:01 2006 @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Copyright (C) 2000 - 2004 Hiroyuki Komatsu <komat****@taiya*****> * Copyright (C) 2004 Hiroaki Nakamura <hnaka****@good-*****> @@ -21,7 +21,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-dict.c,v 1.111 2006/11/27 08:39:17 makeinu Exp $ + * $Id: tomoe-dict.c,v 1.112 2006/11/27 08:52:01 kous Exp $ */ #include <stdio.h> @@ -56,6 +56,8 @@ }; typedef struct _TomoeDictSearchContext { + gint min_n_strokes; + gint max_n_strokes; TomoeReading *reading; GList *results; } TomoeDictSearchContext; @@ -376,11 +378,41 @@ return NULL; } -const GPtrArray* -tomoe_dict_get_letters (TomoeDict *dict) +static void +tomoe_dict_collect_chars_by_n_strokes (gpointer data, gpointer user_data) { - g_return_val_if_fail(dict, NULL); - return TOMOE_DICT_GET_PRIVATE(dict)->letters; + TomoeChar *chr = data; + TomoeDictSearchContext *context = user_data; + TomoeWriting *writing; + gint n_strokes; + + writing = tomoe_char_get_writing (chr); + if (!writing) return; + + n_strokes = tomoe_writing_get_number_of_strokes (writing); + if ((context->min_n_strokes < 0 || context->min_n_strokes <= n_strokes) && + (context->max_n_strokes < 0 || context->max_n_strokes >= n_strokes)) { + context->results = g_list_prepend (context->results, + tomoe_candidate_new (chr)); + } +} + +GList * +tomoe_dict_search_by_n_strokes (TomoeDict *dict, gint min, gint max) +{ + TomoeDictPrivate *priv; + TomoeDictSearchContext context; + + context.min_n_strokes = min; + context.max_n_strokes = max; + context.results = NULL; + + priv = TOMOE_DICT_GET_PRIVATE(dict); + g_ptr_array_foreach_reverse (priv->letters, + tomoe_dict_collect_chars_by_n_strokes, + &context); + + return context.results; } static gint @@ -416,8 +448,9 @@ context.results = NULL; priv = TOMOE_DICT_GET_PRIVATE(dict); - g_ptr_array_foreach (priv->letters, tomoe_dict_collect_chars_by_reading, - &context); + g_ptr_array_foreach_reverse (priv->letters, + tomoe_dict_collect_chars_by_reading, + &context); return context.results; } Index: tomoe/lib/tomoe-dict.h diff -u tomoe/lib/tomoe-dict.h:1.44 tomoe/lib/tomoe-dict.h:1.45 --- tomoe/lib/tomoe-dict.h:1.44 Mon Nov 27 16:49:18 2006 +++ tomoe/lib/tomoe-dict.h Mon Nov 27 17:52:01 2006 @@ -21,7 +21,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-dict.h,v 1.44 2006/11/27 07:49:18 kous Exp $ + * $Id: tomoe-dict.h,v 1.45 2006/11/27 08:52:01 kous Exp $ */ /** @@ -135,7 +135,9 @@ * @param dict - Pointer to the TomoeDict struct. * @return The array of TomoeChar. */ -const GPtrArray *tomoe_dict_get_letters (TomoeDict *dict); +GList *tomoe_dict_search_by_n_strokes (TomoeDict *dict, + gint min, + gint max); /* search methods */ /**