fontchooserwidget: Simplify function

- Don't do unnecessary casts
- Fix weird variable declaration indenting
- Fix loop indentation
- Use a for loop for iterating over a list, instead of a while loop
- Casefold font name only once, instead of every iteration
- Remove needless true_var = true_var && TRUE assignment
This commit is contained in:
Benjamin Otte 2011-09-16 10:14:15 +02:00
parent 7a34a5971e
commit 824aeb77c6

View File

@ -835,16 +835,15 @@ visible_func (GtkTreeModel *model,
GtkTreeIter *iter, GtkTreeIter *iter,
gpointer user_data) gpointer user_data)
{ {
GtkFontChooserWidgetPrivate *priv = user_data;
gboolean result = TRUE; gboolean result = TRUE;
GtkFontChooserWidgetPrivate *priv = (GtkFontChooserWidgetPrivate*)user_data; const gchar *search_text;
gchar **split_terms;
const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry)); gchar *font_name, *font_name_casefold, *term_casefold;
gchar *font_name; guint i;
gchar *term;
gchar **split_terms;
gint n_terms = 0;
/* If there's no filter string we show the item */ /* If there's no filter string we show the item */
search_text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
if (strlen (search_text) == 0) if (strlen (search_text) == 0)
return TRUE; return TRUE;
@ -856,25 +855,19 @@ visible_func (GtkTreeModel *model,
return FALSE; return FALSE;
split_terms = g_strsplit (search_text, " ", 0); split_terms = g_strsplit (search_text, " ", 0);
term = split_terms[0]; font_name_casefold = g_utf8_casefold (font_name, -1);
while (term && result) for (i = 0; split_terms[i] && result; i++)
{ {
gchar* font_name_casefold = g_utf8_casefold (font_name, -1); gchar* term_casefold = g_utf8_casefold (split_terms[i], -1);
gchar* term_casefold = g_utf8_casefold (term, -1);
if (g_strrstr (font_name_casefold, term_casefold)) if (!strstr (font_name_casefold, term_casefold))
result = result && TRUE; result = FALSE;
else
result = FALSE;
n_terms++; g_free (term_casefold);
term = split_terms[n_terms]; }
g_free (term_casefold);
g_free (font_name_casefold);
}
g_free (font_name_casefold);
g_free (font_name); g_free (font_name);
g_strfreev (split_terms); g_strfreev (split_terms);