[vte] regex: Use MULTILINE option and limit offset



commit d84745204b9325f90fe3b5660d918cfd7b389780
Author: Christian Persch <chpe gnome org>
Date:   Sat Dec 26 12:27:22 2015 +0100

    regex: Use MULTILINE option and limit offset
    
    Since we now pass the whole text with an offset, instead of
    only the current line like previously, we need to use the
    MULTILINE option so that '^' works correctly; and we need
    to limit the match offset so that we don't match beyond the
    end of the line (but still can satisfy lookahead assertions).

 configure.ac    |    2 +-
 src/vte.cc      |    6 ++++--
 src/vteregex.cc |    3 ++-
 3 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f5ae65f..11d4b8a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -206,7 +206,7 @@ GLIB_REQUIRED=2.40.0
 GIO_REQUIRED=2.40.0
 PANGO_REQUIRED=1.22.0
 GNUTLS_REQUIRED=3.2.7
-PCRE2_REQUIRED=10.20
+PCRE2_REQUIRED=10.21
 
 # GNUTLS
 
diff --git a/src/vte.cc b/src/vte.cc
index 279b4f8..8868dd2 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -1398,13 +1398,15 @@ VteTerminalPrivate::match_check_pcre(
         /* Iterate throught the matches until we either find one which contains the
          * offset, or we get no more matches.
          */
+        pcre2_set_offset_limit_8(match_context, eattr);
         position = sattr;
         while (position < eattr &&
                ((r = match_fn(_vte_regex_get_pcre(regex),
                               (PCRE2_SPTR8)line, line_length, /* subject, length */
                               position, /* start offset */
                               match_flags |
-                              PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY | PCRE2_PARTIAL_SOFT /* FIXME: HARD? */,
+                              PCRE2_NO_UTF_CHECK | PCRE2_NOTEMPTY | PCRE2_PARTIAL_SOFT /* FIXME: HARD? */ |
+                              PCRE2_MULTILINE,
                               match_data,
                               match_context)) >= 0 || r == PCRE2_ERROR_PARTIAL)) {
                 gsize ko = offset;
@@ -1595,7 +1597,7 @@ VteTerminalPrivate::match_check_gregex(GRegex *regex,
         if (!g_regex_match_full(regex,
                                 line, line_length, /* subject, length */
                                 sattr, /* start position */
-                                match_flags,
+                                GRegexMatchFlags(match_flags | G_REGEX_MULTILINE),
                                 &match_info,
                                 NULL)) {
                 g_match_info_free(match_info);
diff --git a/src/vteregex.cc b/src/vteregex.cc
index 16dc0fa..15ce162 100644
--- a/src/vteregex.cc
+++ b/src/vteregex.cc
@@ -187,7 +187,8 @@ vte_regex_new(const char *pattern,
                                (uint32_t)flags |
                                PCRE2_UTF |
                                (flags & PCRE2_UTF ? PCRE2_NO_UTF_CHECK : 0) |
-                               PCRE2_NEVER_BACKSLASH_C,
+                               PCRE2_NEVER_BACKSLASH_C |
+                               PCRE2_USE_OFFSET_LIMIT,
                                &errcode, &erroffset,
                                NULL);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]