mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
get rid of new_text
This commit is contained in:
parent
48899a123d
commit
4edfccfce7
@ -69,7 +69,7 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
|
|||||||
|
|
||||||
if (rec->regexp) {
|
if (rec->regexp) {
|
||||||
return rec->preg != NULL &&
|
return rec->preg != NULL &&
|
||||||
i_regex_match(rec->preg, text, 0, NULL, NULL);
|
i_regex_match(rec->preg, text, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rec->fullword ?
|
return rec->fullword ?
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
#include "iregex.h"
|
#include "iregex.h"
|
||||||
|
|
||||||
|
struct _MatchInfo {
|
||||||
|
const char *valid_string;
|
||||||
|
GMatchInfo *g_match_info;
|
||||||
|
};
|
||||||
|
|
||||||
static const gchar *
|
static const gchar *
|
||||||
make_valid_utf8(const gchar *text, gboolean *free_ret)
|
make_valid_utf8(const gchar *text, gboolean *free_ret)
|
||||||
{
|
{
|
||||||
@ -59,28 +64,29 @@ i_regex_unref (Regex *regex)
|
|||||||
g_regex_unref(regex);
|
g_regex_unref(regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if new_string is present, the caller must free new_string.
|
|
||||||
otherwise, g_match_info_get_string must not be used.
|
|
||||||
if string is not vali utf8, new_string will be assigned
|
|
||||||
a similar, but valid utf8, string */
|
|
||||||
gboolean
|
gboolean
|
||||||
i_regex_match (const Regex *regex,
|
i_regex_match (const Regex *regex,
|
||||||
const gchar *string,
|
const gchar *string,
|
||||||
GRegexMatchFlags match_options,
|
GRegexMatchFlags match_options,
|
||||||
MatchInfo **match_info,
|
MatchInfo **match_info)
|
||||||
const gchar **new_string)
|
|
||||||
{
|
{
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
gboolean free_valid_string;
|
gboolean free_valid_string;
|
||||||
const gchar *valid_string = make_valid_utf8(string, &free_valid_string);
|
const gchar *valid_string = make_valid_utf8(string, &free_valid_string);
|
||||||
|
|
||||||
ret = g_regex_match(regex, valid_string, match_options, match_info);
|
if (match_info != NULL)
|
||||||
|
*match_info = g_new0(MatchInfo, 1);
|
||||||
|
|
||||||
|
ret = g_regex_match(regex, valid_string, match_options,
|
||||||
|
match_info != NULL ? &(*match_info)->g_match_info : NULL);
|
||||||
|
|
||||||
if (free_valid_string) {
|
if (free_valid_string) {
|
||||||
if (new_string)
|
if (match_info != NULL)
|
||||||
*new_string = valid_string;
|
(*match_info)->valid_string = valid_string;
|
||||||
else
|
else
|
||||||
g_free_not_null((gchar *)valid_string);
|
g_free_not_null((gchar *)valid_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,18 +120,20 @@ gboolean
|
|||||||
i_match_info_fetch_pos (const MatchInfo *match_info,
|
i_match_info_fetch_pos (const MatchInfo *match_info,
|
||||||
gint match_num,
|
gint match_num,
|
||||||
gint *start_pos,
|
gint *start_pos,
|
||||||
gint *end_pos,
|
gint *end_pos)
|
||||||
const gchar *new_string)
|
|
||||||
{
|
{
|
||||||
gint tmp_start, tmp_end, new_start_pos;
|
gint tmp_start, tmp_end, new_start_pos;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
if (!new_string || (!start_pos && !end_pos))
|
if (!match_info->valid_string || (!start_pos && !end_pos))
|
||||||
return g_match_info_fetch_pos(match_info, match_num, start_pos, end_pos);
|
return g_match_info_fetch_pos(match_info->g_match_info,
|
||||||
|
match_num, start_pos, end_pos);
|
||||||
|
|
||||||
ret = g_match_info_fetch_pos(match_info, match_num, &tmp_start, &tmp_end);
|
ret = g_match_info_fetch_pos(match_info->g_match_info,
|
||||||
|
match_num, &tmp_start, &tmp_end);
|
||||||
if (start_pos || end_pos) {
|
if (start_pos || end_pos) {
|
||||||
gchar *to_start = g_strndup(new_string, tmp_start);
|
const gchar *str = match_info->valid_string;
|
||||||
|
gchar *to_start = g_strndup(str, tmp_start);
|
||||||
new_start_pos = strlen_pua_oddly(to_start);
|
new_start_pos = strlen_pua_oddly(to_start);
|
||||||
g_free_not_null(to_start);
|
g_free_not_null(to_start);
|
||||||
|
|
||||||
@ -133,10 +141,25 @@ i_match_info_fetch_pos (const MatchInfo *match_info,
|
|||||||
*start_pos = new_start_pos;
|
*start_pos = new_start_pos;
|
||||||
|
|
||||||
if (end_pos) {
|
if (end_pos) {
|
||||||
gchar *to_end = g_strndup(new_string + tmp_start, tmp_end - tmp_start);
|
gchar *to_end = g_strndup(str + tmp_start, tmp_end - tmp_start);
|
||||||
*end_pos = new_start_pos + strlen_pua_oddly(to_end);
|
*end_pos = new_start_pos + strlen_pua_oddly(to_end);
|
||||||
g_free_not_null(to_end);
|
g_free_not_null(to_end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
i_match_info_matches (const MatchInfo *match_info)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(match_info != NULL, FALSE);
|
||||||
|
|
||||||
|
return g_match_info_matches(match_info->g_match_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
i_match_info_free (MatchInfo *match_info)
|
||||||
|
{
|
||||||
|
g_match_info_free(match_info->g_match_info);
|
||||||
|
g_free(match_info);
|
||||||
|
}
|
||||||
|
@ -47,8 +47,7 @@ gboolean
|
|||||||
i_regex_match (const Regex *regex,
|
i_regex_match (const Regex *regex,
|
||||||
const gchar *string,
|
const gchar *string,
|
||||||
GRegexMatchFlags match_options,
|
GRegexMatchFlags match_options,
|
||||||
MatchInfo **match_info,
|
MatchInfo **match_info)
|
||||||
const gchar **new_string)
|
|
||||||
{
|
{
|
||||||
int groups;
|
int groups;
|
||||||
int eflags;
|
int eflags;
|
||||||
@ -75,8 +74,7 @@ gboolean
|
|||||||
i_match_info_fetch_pos (const MatchInfo *match_info,
|
i_match_info_fetch_pos (const MatchInfo *match_info,
|
||||||
gint match_num,
|
gint match_num,
|
||||||
gint *start_pos,
|
gint *start_pos,
|
||||||
gint *end_pos,
|
gint *end_pos)
|
||||||
const gchar *new_string)
|
|
||||||
{
|
{
|
||||||
if (start_pos != NULL)
|
if (start_pos != NULL)
|
||||||
*start_pos = match_info[match_num].rm_so;
|
*start_pos = match_info[match_num].rm_so;
|
||||||
|
@ -7,10 +7,7 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
typedef GRegex Regex;
|
typedef GRegex Regex;
|
||||||
typedef GMatchInfo MatchInfo;
|
typedef struct _MatchInfo MatchInfo;
|
||||||
|
|
||||||
#define i_match_info_matches g_match_info_matches
|
|
||||||
#define i_match_info_free g_match_info_free
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -18,14 +15,14 @@ typedef GMatchInfo MatchInfo;
|
|||||||
typedef regex_t Regex;
|
typedef regex_t Regex;
|
||||||
typedef regmatch_t MatchInfo;
|
typedef regmatch_t MatchInfo;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
i_match_info_matches (const MatchInfo *match_info);
|
i_match_info_matches (const MatchInfo *match_info);
|
||||||
|
|
||||||
void
|
void
|
||||||
i_match_info_free (MatchInfo *match_info);
|
i_match_info_free (MatchInfo *match_info);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Regex *
|
Regex *
|
||||||
i_regex_new (const gchar *pattern,
|
i_regex_new (const gchar *pattern,
|
||||||
GRegexCompileFlags compile_options,
|
GRegexCompileFlags compile_options,
|
||||||
@ -39,14 +36,12 @@ gboolean
|
|||||||
i_regex_match (const Regex *regex,
|
i_regex_match (const Regex *regex,
|
||||||
const gchar *string,
|
const gchar *string,
|
||||||
GRegexMatchFlags match_options,
|
GRegexMatchFlags match_options,
|
||||||
MatchInfo **match_info,
|
MatchInfo **match_info);
|
||||||
const gchar **new_string);
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
i_match_info_fetch_pos (const MatchInfo *match_info,
|
i_match_info_fetch_pos (const MatchInfo *match_info,
|
||||||
gint match_num,
|
gint match_num,
|
||||||
gint *start_pos,
|
gint *start_pos,
|
||||||
gint *end_pos,
|
gint *end_pos);
|
||||||
const gchar *new_string);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -197,15 +197,12 @@ static gboolean hilight_match_text(HILIGHT_REC *rec, const char *text,
|
|||||||
if (rec->regexp) {
|
if (rec->regexp) {
|
||||||
if (rec->preg != NULL) {
|
if (rec->preg != NULL) {
|
||||||
MatchInfo *match;
|
MatchInfo *match;
|
||||||
const char *new_text = NULL;
|
i_regex_match(rec->preg, text, 0, &match);
|
||||||
|
|
||||||
i_regex_match(rec->preg, text, 0, &match, &new_text);
|
|
||||||
|
|
||||||
if (i_match_info_matches(match))
|
if (i_match_info_matches(match))
|
||||||
ret = i_match_info_fetch_pos(match, 0, match_beg, match_end, new_text);
|
ret = i_match_info_fetch_pos(match, 0, match_beg, match_end);
|
||||||
|
|
||||||
i_match_info_free(match);
|
i_match_info_free(match);
|
||||||
g_free_not_null((char *)new_text);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char *match;
|
char *match;
|
||||||
|
@ -576,16 +576,13 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
|
|||||||
(line->info.level & nolevel) == 0;
|
(line->info.level & nolevel) == 0;
|
||||||
|
|
||||||
if (*text != '\0') {
|
if (*text != '\0') {
|
||||||
const char *tmp = NULL;
|
|
||||||
textbuffer_line2text(line, FALSE, str);
|
textbuffer_line2text(line, FALSE, str);
|
||||||
|
|
||||||
if (line_matched) {
|
if (line_matched) {
|
||||||
line_matched = regexp ?
|
line_matched = regexp ?
|
||||||
i_regex_match(preg, str->str, 0, NULL, &tmp)
|
i_regex_match(preg, str->str, 0, NULL)
|
||||||
: match_func(str->str, text) != NULL;
|
: match_func(str->str, text) != NULL;
|
||||||
}
|
}
|
||||||
if (tmp && tmp != str->str)
|
|
||||||
g_free_not_null((char *)tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_matched) {
|
if (line_matched) {
|
||||||
|
Loading…
Reference in New Issue
Block a user