}
/**
+ * g_regex_get_max_lookbehind:
+ * @regex: a #GRegex structure
+ *
+ * Gets the number of characters in the longest lookbehind assertion in the
+ * pattern. This information is useful when doing multi-segment matching using
+ * the partial matching facilities.
+ *
+ * Returns: the number of characters in the longest lookbehind assertion.
+ *
+ * Since: 2.38
+ */
+gint
+g_regex_get_max_lookbehind (const GRegex *regex)
+{
+ gint max_lookbehind;
+
+ pcre_fullinfo (regex->pcre_re, regex->extra,
+ PCRE_INFO_MAXLOOKBEHIND, &max_lookbehind);
+
+ return max_lookbehind;
+}
+
+/**
* g_regex_get_compile_flags:
* @regex: a #GRegex
*
gint g_regex_get_capture_count (const GRegex *regex);
GLIB_AVAILABLE_IN_ALL
gboolean g_regex_get_has_cr_or_lf (const GRegex *regex);
+GLIB_AVAILABLE_IN_2_38
+gint g_regex_get_max_lookbehind (const GRegex *regex);
GLIB_AVAILABLE_IN_ALL
gint g_regex_get_string_number (const GRegex *regex,
const gchar *name);
g_regex_unref (regex);
}
+static void
+test_max_lookbehind (void)
+{
+ GRegex *regex;
+
+ regex = g_regex_new ("abc", 0, 0, NULL);
+ g_assert_cmpint (g_regex_get_max_lookbehind (regex), ==, 0);
+ g_regex_unref (regex);
+
+ regex = g_regex_new ("\\babc", 0, 0, NULL);
+ g_assert_cmpint (g_regex_get_max_lookbehind (regex), ==, 1);
+ g_regex_unref (regex);
+
+ regex = g_regex_new ("(?<=123)abc", 0, 0, NULL);
+ g_assert_cmpint (g_regex_get_max_lookbehind (regex), ==, 3);
+ g_regex_unref (regex);
+}
+
int
main (int argc, char *argv[])
{
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);
+ g_test_add_func ("/regex/max-lookbehind", test_max_lookbehind);
/* TEST_NEW(pattern, compile_opts, match_opts) */
TEST_NEW("[A-Z]+", G_REGEX_CASELESS | G_REGEX_EXTENDED | G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTBOL | G_REGEX_MATCH_PARTIAL);