Use GRegex for channel list search

This adds support for Windows
This commit is contained in:
TingPing 2014-02-15 11:50:22 -05:00
parent b245f2f79e
commit 22b5affbe6
2 changed files with 11 additions and 18 deletions

View File

@ -76,13 +76,11 @@ chanlist_match (server *serv, const char *str)
{
case 1:
return match (gtk_entry_get_text (GTK_ENTRY (serv->gui->chanlist_wild)), str);
#ifndef WIN32
case 2:
if (!serv->gui->have_regex)
return 0;
/* regex returns 0 if it's a match: */
return !regexec (&serv->gui->chanlist_match_regex, str, 1, NULL, REG_NOTBOL);
#endif
return g_regex_match (serv->gui->chanlist_match_regex, str, 0, NULL);
default: /* case 0: */
return nocasestrstr (str, gtk_entry_get_text (GTK_ENTRY (serv->gui->chanlist_wild))) ? 1 : 0;
}
@ -406,18 +404,20 @@ chanlist_search_pressed (GtkButton * button, server *serv)
static void
chanlist_find_cb (GtkWidget * wid, server *serv)
{
#ifndef WIN32
char *pattern = gtk_entry_get_text (GTK_ENTRY (wid));
/* recompile the regular expression. */
if (serv->gui->have_regex)
{
serv->gui->have_regex = 0;
regfree (&serv->gui->chanlist_match_regex);
g_regex_unref (serv->gui->chanlist_match_regex);
}
if (regcomp (&serv->gui->chanlist_match_regex, gtk_entry_get_text (GTK_ENTRY (wid)),
REG_ICASE | REG_EXTENDED | REG_NOSUB) == 0)
serv->gui->chanlist_match_regex = g_regex_new (pattern, G_REGEX_CASELESS | G_REGEX_EXTENDED,
G_REGEX_MATCH_NOTBOL, NULL);
if (serv->gui->chanlist_match_regex)
serv->gui->have_regex = 1;
#endif
}
static void
@ -655,13 +655,11 @@ chanlist_destroy_widget (GtkWidget *wid, server *serv)
serv->gui->chanlist_tag = 0;
}
#ifndef WIN32
if (serv->gui->have_regex)
{
regfree (&serv->gui->chanlist_match_regex);
g_regex_unref (serv->gui->chanlist_match_regex);
serv->gui->have_regex = 0;
}
#endif
}
static void
@ -902,9 +900,7 @@ chanlist_opengui (server *serv, int do_refresh)
wid = gtk_combo_box_text_new ();
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (wid), _("Simple Search"));
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (wid), _("Pattern Match (Wildcards)"));
#ifndef WIN32
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (wid), _("Regular Expression"));
#endif
gtk_combo_box_set_active (GTK_COMBO_BOX (wid), serv->gui->chanlist_search_type);
gtk_table_attach (GTK_TABLE (table), wid, 1, 2, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);

View File

@ -30,7 +30,6 @@
#ifndef WIN32
#include <sys/types.h>
#include <regex.h>
#endif
#if defined(ENABLE_NLS) && !defined(_)
@ -102,10 +101,8 @@ struct server_gui
gboolean chanlist_match_wants_channel; /* match in channel name */
gboolean chanlist_match_wants_topic; /* match in topic */
#ifndef WIN32
regex_t chanlist_match_regex; /* compiled regular expression here */
GRegex *chanlist_match_regex; /* compiled regular expression here */
unsigned int have_regex;
#endif
guint chanlist_users_found_count; /* users total for all channels */
guint chanlist_users_shown_count; /* users total for displayed channels */