mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
Use the RAW flag when building the regexps.
Also, plugged a memory leak when retrieving the match position.
This commit is contained in:
parent
5eaead761f
commit
5dcf291f21
@ -328,7 +328,7 @@ static void ignore_init_rec(IGNORE_REC *rec)
|
|||||||
if (rec->regexp && rec->pattern != NULL) {
|
if (rec->regexp && rec->pattern != NULL) {
|
||||||
GError *re_error;
|
GError *re_error;
|
||||||
|
|
||||||
rec->preg = g_regex_new(rec->pattern, G_REGEX_CASELESS, 0, &re_error);
|
rec->preg = g_regex_new(rec->pattern, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, &re_error);
|
||||||
|
|
||||||
if (rec->preg == NULL) {
|
if (rec->preg == NULL) {
|
||||||
g_warning("Failed to compile regexp '%s': %s", rec->pattern, re_error->message);
|
g_warning("Failed to compile regexp '%s': %s", rec->pattern, re_error->message);
|
||||||
|
@ -121,7 +121,7 @@ static void hilight_init_rec(HILIGHT_REC *rec)
|
|||||||
if (rec->preg != NULL)
|
if (rec->preg != NULL)
|
||||||
g_regex_unref(rec->preg);
|
g_regex_unref(rec->preg);
|
||||||
|
|
||||||
rec->preg = g_regex_new(rec->text, G_REGEX_CASELESS, 0, NULL);
|
rec->preg = g_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hilight_create(HILIGHT_REC *rec)
|
void hilight_create(HILIGHT_REC *rec)
|
||||||
@ -188,22 +188,25 @@ static HILIGHT_REC *hilight_find(const char *text, char **channels)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hilight_match_text(HILIGHT_REC *rec, const char *text,
|
static gboolean hilight_match_text(HILIGHT_REC *rec, const char *text,
|
||||||
int *match_beg, int *match_end)
|
int *match_beg, int *match_end)
|
||||||
{
|
{
|
||||||
char *match;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
if (rec->regexp) {
|
if (rec->regexp) {
|
||||||
GMatchInfo *match;
|
|
||||||
|
|
||||||
if (rec->preg != NULL) {
|
if (rec->preg != NULL) {
|
||||||
|
GMatchInfo *match;
|
||||||
|
|
||||||
g_regex_match (rec->preg, text, 0, &match);
|
g_regex_match (rec->preg, text, 0, &match);
|
||||||
|
|
||||||
if (g_match_info_matches(match)) {
|
if (g_match_info_matches(match))
|
||||||
return g_match_info_fetch_pos(match, 0, match_beg, match_end);
|
ret = g_match_info_fetch_pos(match, 0, match_beg, match_end);
|
||||||
}
|
|
||||||
|
g_match_info_free(match);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
char *match;
|
||||||
|
|
||||||
if (rec->case_sensitive) {
|
if (rec->case_sensitive) {
|
||||||
match = rec->fullword ?
|
match = rec->fullword ?
|
||||||
strstr_full(text, rec->text) :
|
strstr_full(text, rec->text) :
|
||||||
@ -218,11 +221,11 @@ static int hilight_match_text(HILIGHT_REC *rec, const char *text,
|
|||||||
*match_beg = (int) (match-text);
|
*match_beg = (int) (match-text);
|
||||||
*match_end = *match_beg + strlen(rec->text);
|
*match_end = *match_beg + strlen(rec->text);
|
||||||
}
|
}
|
||||||
return TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define hilight_match_level(rec, level) \
|
#define hilight_match_level(rec, level) \
|
||||||
|
@ -546,7 +546,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
|
|||||||
preg = NULL;
|
preg = NULL;
|
||||||
|
|
||||||
if (regexp) {
|
if (regexp) {
|
||||||
preg = g_regex_new(text, (case_sensitive ? 0 : G_REGEX_CASELESS), 0, NULL);
|
preg = g_regex_new(text, G_REGEX_RAW | (case_sensitive ? 0 : G_REGEX_CASELESS), 0, NULL);
|
||||||
|
|
||||||
if (preg == NULL)
|
if (preg == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -602,7 +602,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regexp)
|
if (preg != NULL)
|
||||||
g_regex_unref(preg);
|
g_regex_unref(preg);
|
||||||
g_string_free(str, TRUE);
|
g_string_free(str, TRUE);
|
||||||
return matches;
|
return matches;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user