regex: Add accessor for PCRE_INFO_HASCRORLF

This flag is new in PCRE 7.3, and checks whether there is an explicit
CR or LF reference in the pattern.
This commit is contained in:
Christian Persch 2012-06-07 15:57:15 +02:00
parent 7ada976516
commit 69a12e3275
5 changed files with 35 additions and 0 deletions

View File

@ -1005,6 +1005,7 @@ g_regex_unref
g_regex_get_pattern
g_regex_get_max_backref
g_regex_get_capture_count
g_regex_get_has_cr_or_lf
g_regex_get_string_number
g_regex_get_compile_flags
g_regex_get_match_flags

View File

@ -1405,6 +1405,7 @@ g_regex_unref
g_regex_get_pattern
g_regex_get_max_backref
g_regex_get_capture_count
g_regex_get_has_cr_or_lf
g_regex_get_string_number
g_regex_get_compile_flags
g_regex_get_match_flags

View File

@ -1455,6 +1455,27 @@ g_regex_get_capture_count (const GRegex *regex)
return value;
}
/**
* g_regex_get_has_cr_or_lf:
* @regex: a #GRegex structure
*
* Checks whether the pattern contains explicit CR or LF references.
*
* Returns: %TRUE if the pattern contains explicit CR or LF references
*
* Since: 2.34
*/
gboolean
g_regex_get_has_cr_or_lf (const GRegex *regex)
{
gint value;
pcre_fullinfo (regex->pcre_re, regex->extra,
PCRE_INFO_HASCRORLF, &value);
return !!value;
}
/**
* g_regex_get_compile_flags:
* @regex: a #GRegex

View File

@ -406,6 +406,7 @@ void g_regex_unref (GRegex *regex);
const gchar *g_regex_get_pattern (const GRegex *regex);
gint g_regex_get_max_backref (const GRegex *regex);
gint g_regex_get_capture_count (const GRegex *regex);
gboolean g_regex_get_has_cr_or_lf (const GRegex *regex);
gint g_regex_get_string_number (const GRegex *regex,
const gchar *name);
gchar *g_regex_escape_string (const gchar *string,

View File

@ -2023,6 +2023,16 @@ test_multiline (void)
g_assert_cmpint (count, ==, 2);
}
static void
test_explicit_crlf (void)
{
GRegex *regex;
regex = g_regex_new ("[\r\n]a", 0, 0, NULL);
g_assert_cmpint (g_regex_get_has_cr_or_lf (regex), ==, TRUE);
g_regex_unref (regex);
}
int
main (int argc, char *argv[])
{
@ -2041,6 +2051,7 @@ main (int argc, char *argv[])
g_test_add_func ("/regex/condition", test_condition);
g_test_add_func ("/regex/recursion", test_recursion);
g_test_add_func ("/regex/multiline", test_multiline);
g_test_add_func ("/regex/explicit-crlf", test_explicit_crlf);
/* TEST_NEW(pattern, compile_opts, match_opts) */
TEST_NEW("", 0, 0);