summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2017-06-05 11:41:50 +0200
committerailin-nemui <ailin-nemui@users.noreply.github.com>2017-06-05 13:46:43 +0200
commit4edfccfce794d4c10b2a92c02fe982bb089c6629 (patch)
tree936af89080c7b50d112d2567e5d5574fdfe75d5f
parent48899a123d68051fbc73acb8ad151e89fdcb6b31 (diff)
downloadirssi-4edfccfce794d4c10b2a92c02fe982bb089c6629.zip
get rid of new_text
-rw-r--r--src/core/ignore.c2
-rw-r--r--src/core/iregex-gregex.c55
-rw-r--r--src/core/iregex-regexh.c6
-rw-r--r--src/core/iregex.h15
-rw-r--r--src/fe-common/core/hilight-text.c7
-rw-r--r--src/fe-text/textbuffer.c5
6 files changed, 50 insertions, 40 deletions
diff --git a/src/core/ignore.c b/src/core/ignore.c
index 63a507f5..cec91e6b 100644
--- a/src/core/ignore.c
+++ b/src/core/ignore.c
@@ -69,7 +69,7 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
if (rec->regexp) {
return rec->preg != NULL &&
- i_regex_match(rec->preg, text, 0, NULL, NULL);
+ i_regex_match(rec->preg, text, 0, NULL);
}
return rec->fullword ?
diff --git a/src/core/iregex-gregex.c b/src/core/iregex-gregex.c
index 4a1623b9..36b4faa4 100644
--- a/src/core/iregex-gregex.c
+++ b/src/core/iregex-gregex.c
@@ -2,6 +2,11 @@
#include "iregex.h"
+struct _MatchInfo {
+ const char *valid_string;
+ GMatchInfo *g_match_info;
+};
+
static const gchar *
make_valid_utf8(const gchar *text, gboolean *free_ret)
{
@@ -59,28 +64,29 @@ i_regex_unref (Regex *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
i_regex_match (const Regex *regex,
const gchar *string,
GRegexMatchFlags match_options,
- MatchInfo **match_info,
- const gchar **new_string)
+ MatchInfo **match_info)
{
gboolean ret;
gboolean 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 (new_string)
- *new_string = valid_string;
+ if (match_info != NULL)
+ (*match_info)->valid_string = valid_string;
else
g_free_not_null((gchar *)valid_string);
}
+
return ret;
}
@@ -114,18 +120,20 @@ gboolean
i_match_info_fetch_pos (const MatchInfo *match_info,
gint match_num,
gint *start_pos,
- gint *end_pos,
- const gchar *new_string)
+ gint *end_pos)
{
gint tmp_start, tmp_end, new_start_pos;
gboolean ret;
- if (!new_string || (!start_pos && !end_pos))
- return g_match_info_fetch_pos(match_info, match_num, start_pos, end_pos);
+ if (!match_info->valid_string || (!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) {
- 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);
g_free_not_null(to_start);
@@ -133,10 +141,25 @@ i_match_info_fetch_pos (const MatchInfo *match_info,
*start_pos = new_start_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);
g_free_not_null(to_end);
}
}
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);
+}
diff --git a/src/core/iregex-regexh.c b/src/core/iregex-regexh.c
index aabe44f6..897eb7e2 100644
--- a/src/core/iregex-regexh.c
+++ b/src/core/iregex-regexh.c
@@ -47,8 +47,7 @@ gboolean
i_regex_match (const Regex *regex,
const gchar *string,
GRegexMatchFlags match_options,
- MatchInfo **match_info,
- const gchar **new_string)
+ MatchInfo **match_info)
{
int groups;
int eflags;
@@ -75,8 +74,7 @@ gboolean
i_match_info_fetch_pos (const MatchInfo *match_info,
gint match_num,
gint *start_pos,
- gint *end_pos,
- const gchar *new_string)
+ gint *end_pos)
{
if (start_pos != NULL)
*start_pos = match_info[match_num].rm_so;
diff --git a/src/core/iregex.h b/src/core/iregex.h
index adeea987..e67378d7 100644
--- a/src/core/iregex.h
+++ b/src/core/iregex.h
@@ -7,10 +7,7 @@
#include <glib.h>
typedef GRegex Regex;
-typedef GMatchInfo MatchInfo;
-
-#define i_match_info_matches g_match_info_matches
-#define i_match_info_free g_match_info_free
+typedef struct _MatchInfo MatchInfo;
#else
@@ -18,14 +15,14 @@ typedef GMatchInfo MatchInfo;
typedef regex_t Regex;
typedef regmatch_t MatchInfo;
+#endif
+
gboolean
i_match_info_matches (const MatchInfo *match_info);
void
i_match_info_free (MatchInfo *match_info);
-#endif
-
Regex *
i_regex_new (const gchar *pattern,
GRegexCompileFlags compile_options,
@@ -39,14 +36,12 @@ gboolean
i_regex_match (const Regex *regex,
const gchar *string,
GRegexMatchFlags match_options,
- MatchInfo **match_info,
- const gchar **new_string);
+ MatchInfo **match_info);
gboolean
i_match_info_fetch_pos (const MatchInfo *match_info,
gint match_num,
gint *start_pos,
- gint *end_pos,
- const gchar *new_string);
+ gint *end_pos);
#endif
diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c
index 6a2c97dc..62e6f0de 100644
--- a/src/fe-common/core/hilight-text.c
+++ b/src/fe-common/core/hilight-text.c
@@ -197,15 +197,12 @@ static gboolean hilight_match_text(HILIGHT_REC *rec, const char *text,
if (rec->regexp) {
if (rec->preg != NULL) {
MatchInfo *match;
- const char *new_text = NULL;
-
- i_regex_match(rec->preg, text, 0, &match, &new_text);
+ i_regex_match(rec->preg, text, 0, &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);
- g_free_not_null((char *)new_text);
}
} else {
char *match;
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c
index eb841096..9e791f4c 100644
--- a/src/fe-text/textbuffer.c
+++ b/src/fe-text/textbuffer.c
@@ -576,16 +576,13 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
(line->info.level & nolevel) == 0;
if (*text != '\0') {
- const char *tmp = NULL;
textbuffer_line2text(line, FALSE, str);
if (line_matched) {
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;
}
- if (tmp && tmp != str->str)
- g_free_not_null((char *)tmp);
}
if (line_matched) {