[vte] regex: Warn if MULTILINE flag it not used
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] regex: Warn if MULTILINE flag it not used
- Date: Sun, 4 Sep 2016 13:19:15 +0000 (UTC)
commit b00caee60a757d354bf8d51678669c2eb426e086
Author: Christian Persch <chpe src gnome org>
Date: Sun Sep 4 15:18:22 2016 +0200
regex: Warn if MULTILINE flag it not used
Due to the way that vte implements the regex search, using
PCRE2_MULTILINE when creating the regex is required. Warn
if passing a regex that doesn't have it.
src/vtegtk.cc | 8 ++++++--
src/vteregex.cc | 16 ++++++++++++++++
src/vteregexinternal.hh | 2 ++
3 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 87e2a73..924b5a0 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -1731,6 +1731,7 @@ vte_terminal_match_add_regex(VteTerminal *terminal,
g_return_val_if_fail(VTE_IS_TERMINAL(terminal), -1);
g_return_val_if_fail(regex != NULL, -1);
g_return_val_if_fail(_vte_regex_has_purpose(regex, VteRegexPurpose::match), -1);
+ g_warn_if_fail(_vte_regex_get_compile_flags(regex) & PCRE2_MULTILINE);
auto impl = IMPL(terminal);
@@ -1830,8 +1831,10 @@ vte_terminal_event_check_regex_simple(VteTerminal *terminal,
g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
g_return_val_if_fail(event != NULL, FALSE);
g_return_val_if_fail(regexes != NULL || n_regexes == 0, FALSE);
- for (gsize i = 0; i < n_regexes; i++)
+ for (gsize i = 0; i < n_regexes; i++) {
g_return_val_if_fail(_vte_regex_has_purpose(regexes[i], VteRegexPurpose::match), -1);
+ g_warn_if_fail(_vte_regex_get_compile_flags(regexes[i]) & PCRE2_MULTILINE);
+ }
g_return_val_if_fail(matches != NULL, FALSE);
return IMPL(terminal)->regex_match_check_extra(event, regexes, n_regexes, match_flags, matches);
@@ -2006,7 +2009,8 @@ vte_terminal_search_set_regex (VteTerminal *terminal,
guint32 flags)
{
g_return_if_fail(VTE_IS_TERMINAL(terminal));
- g_return_if_fail(regex == NULL || _vte_regex_has_purpose(regex, VteRegexPurpose::search));
+ g_return_if_fail(regex == nullptr || _vte_regex_has_purpose(regex, VteRegexPurpose::search));
+ g_warn_if_fail(regex == nullptr || _vte_regex_get_compile_flags(regex) & PCRE2_MULTILINE);
IMPL(terminal)->search_set_regex(regex, flags);
}
diff --git a/src/vteregex.cc b/src/vteregex.cc
index 129576a..d9c4841 100644
--- a/src/vteregex.cc
+++ b/src/vteregex.cc
@@ -408,3 +408,19 @@ _vte_regex_get_jited(VteRegex *regex)
return r == 0 && s != 0;
}
+
+/*
+ * _vte_regex_get_compile_flags:
+ *
+ * Returns: the PCRE2 flags used to compile @regex
+ */
+guint32
+_vte_regex_get_compile_flags(VteRegex *regex)
+{
+ g_return_val_if_fail(regex != nullptr, 0);
+
+ uint32_t v;
+ int r = pcre2_pattern_info_8(regex->code, PCRE2_INFO_ARGOPTIONS, &v);
+
+ return r == 0 ? v : 0u;
+}
diff --git a/src/vteregexinternal.hh b/src/vteregexinternal.hh
index 95f4b7d..21f43f8 100644
--- a/src/vteregexinternal.hh
+++ b/src/vteregexinternal.hh
@@ -27,6 +27,8 @@ gboolean _vte_regex_has_purpose(VteRegex *regex,
gboolean _vte_regex_get_jited(VteRegex *regex);
+guint32 _vte_regex_get_compile_flags (VteRegex *regex);
+
const pcre2_code_8 *_vte_regex_get_pcre (VteRegex *regex);
/* GRegex translation */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]