mirror of
https://github.com/irssi/irssi.git
synced 2026-08-18 08:02:13 +02:00
Use GLib's regexp interface (backed by PCRE)
This commit is contained in:
parent
91f48c6f0e
commit
8e5db471e4
7 changed files with 43 additions and 88 deletions
|
|
@ -67,12 +67,8 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
|
|||
return FALSE;
|
||||
|
||||
if (rec->regexp) {
|
||||
#ifdef HAVE_REGEX_H
|
||||
return rec->regexp_compiled &&
|
||||
regexec(&rec->preg, text, 0, NULL, 0) == 0;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
g_regex_match(rec->preg, text, 0, NULL);
|
||||
}
|
||||
|
||||
return rec->fullword ?
|
||||
|
|
@ -326,26 +322,23 @@ static void ignore_remove_config(IGNORE_REC *rec)
|
|||
|
||||
static void ignore_init_rec(IGNORE_REC *rec)
|
||||
{
|
||||
#ifdef HAVE_REGEX_H
|
||||
char *errbuf;
|
||||
int errcode, errbuf_len;
|
||||
if (rec->regexp_compiled) {
|
||||
g_regex_unref(rec->preg);
|
||||
rec->regexp_compiled = FALSE;
|
||||
}
|
||||
|
||||
if (rec->regexp_compiled) regfree(&rec->preg);
|
||||
rec->regexp_compiled = FALSE;
|
||||
if (rec->regexp && rec->pattern != NULL) {
|
||||
errcode = regcomp(&rec->preg, rec->pattern,
|
||||
REG_EXTENDED|REG_ICASE|REG_NOSUB);
|
||||
if (errcode != 0) {
|
||||
errbuf_len = regerror(errcode, &rec->preg, 0, 0);
|
||||
errbuf = g_malloc(errbuf_len);
|
||||
regerror(errcode, &rec->preg, errbuf, errbuf_len);
|
||||
g_warning("Failed to compile regexp '%s': %s", rec->pattern, errbuf);
|
||||
g_free(errbuf);
|
||||
GError *re_error;
|
||||
|
||||
rec->preg = g_regex_new(rec->pattern, G_REGEX_CASELESS, 0, &re_error);
|
||||
|
||||
if (rec->preg == NULL) {
|
||||
g_warning("Failed to compile regexp '%s': %s", rec->pattern, re_error->message);
|
||||
g_error_free(re_error);
|
||||
} else {
|
||||
rec->regexp_compiled = TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ignore_add_rec(IGNORE_REC *rec)
|
||||
|
|
@ -365,9 +358,7 @@ static void ignore_destroy(IGNORE_REC *rec, int send_signal)
|
|||
if (send_signal)
|
||||
signal_emit("ignore destroyed", 1, rec);
|
||||
|
||||
#ifdef HAVE_REGEX_H
|
||||
if (rec->regexp_compiled) regfree(&rec->preg);
|
||||
#endif
|
||||
if (rec->regexp_compiled) g_regex_unref(rec->preg);
|
||||
if (rec->channels != NULL) g_strfreev(rec->channels);
|
||||
g_free_not_null(rec->mask);
|
||||
g_free_not_null(rec->servertag);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue