From: Christian Persch Date: Thu, 14 Jun 2012 20:04:05 +0000 (+0200) Subject: regex: Add FIRSTLINE compile flag X-Git-Tag: 2.33.4~55 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a2f54a3408fcf45cae991b6886f4495fdae1f5ac;p=platform%2Fupstream%2Fglib.git regex: Add FIRSTLINE compile flag This option exists since PCRE 6.0. --- diff --git a/glib/gregex.c b/glib/gregex.c index 07f8e52..839b1e6 100644 --- a/glib/gregex.c +++ b/glib/gregex.c @@ -121,6 +121,7 @@ G_REGEX_RAW | \ G_REGEX_NO_AUTO_CAPTURE | \ G_REGEX_OPTIMIZE | \ + G_REGEX_FIRSTLINE | \ G_REGEX_DUPNAMES | \ G_REGEX_NEWLINE_CR | \ G_REGEX_NEWLINE_LF | \ @@ -160,6 +161,7 @@ G_STATIC_ASSERT (G_REGEX_ANCHORED == PCRE_ANCHORED); G_STATIC_ASSERT (G_REGEX_DOLLAR_ENDONLY == PCRE_DOLLAR_ENDONLY); G_STATIC_ASSERT (G_REGEX_UNGREEDY == PCRE_UNGREEDY); G_STATIC_ASSERT (G_REGEX_NO_AUTO_CAPTURE == PCRE_NO_AUTO_CAPTURE); +G_STATIC_ASSERT (G_REGEX_FIRSTLINE == PCRE_FIRSTLINE); G_STATIC_ASSERT (G_REGEX_DUPNAMES == PCRE_DUPNAMES); G_STATIC_ASSERT (G_REGEX_NEWLINE_CR == PCRE_NEWLINE_CR); G_STATIC_ASSERT (G_REGEX_NEWLINE_LF == PCRE_NEWLINE_LF); diff --git a/glib/gregex.h b/glib/gregex.h index 3ac877e..29e5c6a 100644 --- a/glib/gregex.h +++ b/glib/gregex.h @@ -250,7 +250,7 @@ GQuark g_regex_error_quark (void); * It can also be set by a "(?U)" option setting within the pattern. * @G_REGEX_RAW: Usually strings must be valid UTF-8 strings, using this * flag they are considered as a raw sequence of bytes. - * @G_REGEX_NO_AUTO_CAPTURE: Disables the use of numbered capturing + * @G_REGEX_NO_AUTO_CAPTURE: Disables the use of numbered capturing * parentheses in the pattern. Any opening parenthesis that is not * followed by "?" behaves as if it were followed by "?:" but named * parentheses can still be used for capturing (and they acquire numbers @@ -258,6 +258,8 @@ GQuark g_regex_error_quark (void); * @G_REGEX_OPTIMIZE: Optimize the regular expression. If the pattern will * be used many times, then it may be worth the effort to optimize it * to improve the speed of matches. + * @G_REGEX_FIRSTLINE: Limits an unanchored pattern to match before (or at) the + * first newline. Since: 2.34 * @G_REGEX_DUPNAMES: Names used to identify capturing subpatterns need not * be unique. This can be helpful for certain types of pattern when it * is known that only one instance of the named subpattern can ever be @@ -297,6 +299,7 @@ typedef enum G_REGEX_RAW = 1 << 11, G_REGEX_NO_AUTO_CAPTURE = 1 << 12, G_REGEX_OPTIMIZE = 1 << 13, + G_REGEX_FIRSTLINE = 1 << 18, G_REGEX_DUPNAMES = 1 << 19, G_REGEX_NEWLINE_CR = 1 << 20, G_REGEX_NEWLINE_LF = 1 << 21, diff --git a/glib/tests/regex.c b/glib/tests/regex.c index b70119f..a155e3a 100644 --- a/glib/tests/regex.c +++ b/glib/tests/regex.c @@ -2326,6 +2326,9 @@ main (int argc, char *argv[]) TEST_MATCH("a#\nb", G_REGEX_EXTENDED, G_REGEX_MATCH_NEWLINE_CR, "a", -1, 0, 0, FALSE); TEST_MATCH("a#\nb", G_REGEX_EXTENDED | G_REGEX_NEWLINE_CR, 0, "a", -1, 0, 0, TRUE); + TEST_MATCH("line\nbreak", G_REGEX_MULTILINE, 0, "this is a line\nbreak", -1, 0, 0, TRUE); + TEST_MATCH("line\nbreak", G_REGEX_MULTILINE | G_REGEX_FIRSTLINE, 0, "first line\na line\nbreak", -1, 0, 0, FALSE); + /* This failed with PCRE 7.2 (gnome bug #455640) */ TEST_MATCH(".*$", 0, 0, "\xe1\xbb\x85", -1, 0, 0, TRUE);