fixed g_regex_fetch_named* for cases when (?J) is used inside a pattern
authorYevgen Muntyan <muntyan@tamu.edu>
Sun, 3 Jun 2007 06:05:23 +0000 (06:05 +0000)
committerYevgen Muntyan <muntyan@src.gnome.org>
Sun, 3 Jun 2007 06:05:23 +0000 (06:05 +0000)
2007-06-03  Yevgen Muntyan  <muntyan@tamu.edu>

* glib/gregex.c: fixed g_regex_fetch_named* for cases when (?J)
is used inside a pattern (#442265, comment #12).
* tests/regex-test.c: Test it.

svn path=/trunk/; revision=5526

ChangeLog
glib/gregex.c
tests/regex-test.c

index 3b758b9..78c356d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,19 @@
+2007-06-03  Yevgen Muntyan  <muntyan@tamu.edu>
+
+       * glib/gregex.c: fixed g_regex_fetch_named* for cases when (?J)
+       is used inside a pattern (#442265, comment #12).
+       * tests/regex-test.c: Test it.
+
 2007-06-03  Matthias Clasen <mclasen@redhat.com>
 
        * NEWS: Updates
 
 2007-06-03  Yevgen Muntyan  <muntyan@tamu.edu>
 
+       Some API additions and changes (#442265).
+
        * glib/gregex.c:
-       * glib/gregex.h: New functions: g_regex_ref(), g_regex_unref() which
+       * glib/gregex.h: new functions: g_regex_ref(), g_regex_unref() which
        replaces g_regex_free(); g_match_info_get_regex(), g_match_info_get_string();
        g_regex_check_replacement().
        Made g_match_info_expand_references() accept NULL; changed GRegexEvalCallback
index 953cd26..52ea980 100644 (file)
@@ -222,7 +222,7 @@ match_info_new (const GRegex *regex,
  * g_match_info_get_regex:
  * @match_info: a #GMatchInfo
  *
- * Returns #GRegex object used in @match_info. It belongs to glib
+ * Returns #GRegex object used in @match_info. It belongs to Glib
  * and must not be freed. Use g_regex_ref() if you need to keep it
  * after you free @match_info object.
  *
@@ -617,8 +617,20 @@ get_matched_substring_number (const GMatchInfo *match_info,
   gchar *first, *last;
   guchar *entry;
 
+  /*
+   * FIXME: (?J) may be used inside the pattern as the equivalent of
+   * DUPNAMES compile option. In this case we can't know about it,
+   * and pcre doesn't tell us about it either, it uses private flag
+   * PCRE_JCHANGED for this. So we have to always search string
+   * table, unlike pcre which uses pcre_get_stringnumber() shortcut
+   * when possible. It shouldn't be actually bad since
+   * pcre_get_stringtable_entries() uses binary search; still would 
+   * be better to fix it, to be not worse than pcre.
+   */
+#if 0
   if ((match_info->regex->compile_opts & G_REGEX_DUPNAMES) == 0)
     return pcre_get_stringnumber (match_info->regex->pcre_re, name);
+#endif
 
   /* This code is copied from pcre_get.c: get_first_set() */
   entrysize = pcre_get_stringtable_entries (match_info->regex->pcre_re, 
index 111ca58..26d9677 100644 (file)
@@ -1829,6 +1829,13 @@ main (int argc, char *argv[])
   TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>x)|(?P<N>a)", "a", 0, "N", "a", 0, 1);
   TEST_NAMED_SUB_PATTERN_DUPNAMES("(?P<N>x)y|(?P<N>a)b", "ab", 0, "N", "a", 0, 1);
 
+  /* DUPNAMES option inside the pattern */
+  TEST_NAMED_SUB_PATTERN("(?J)(?P<N>a)|(?P<N>b)", "ab", 0, "N", "a", 0, 1);
+  TEST_NAMED_SUB_PATTERN("(?J)(?P<N>aa)|(?P<N>a)", "aa", 0, "N", "aa", 0, 2);
+  TEST_NAMED_SUB_PATTERN("(?J)(?P<N>aa)(?P<N>a)", "aaa", 0, "N", "aa", 0, 2);
+  TEST_NAMED_SUB_PATTERN("(?J)(?P<N>x)|(?P<N>a)", "a", 0, "N", "a", 0, 1);
+  TEST_NAMED_SUB_PATTERN("(?J)(?P<N>x)y|(?P<N>a)b", "ab", 0, "N", "a", 0, 1);
+
   /* TEST_FETCH_ALL#(pattern, string, ...) */
   TEST_FETCH_ALL0("a", "");
   TEST_FETCH_ALL0("a", "b");