+Mon Sep 19 17:23:23 2005 Tim Janik <timj@imendio.com>
+
+ * glib/gpattern.c: applied a patch from matthias which checks on the
+ upper bound of GPatternSpec length to optimize matches.
+ cosmetic fixups.
+
+ * tests/patterntest.c: added more match cases.
+
2005-09-16 Tor Lillqvist <tml@novell.com>
* glib/gstrfuncs.c (g_ascii_strcasecmp, g_ascii_strncasecmp): Add
+Mon Sep 19 17:23:23 2005 Tim Janik <timj@imendio.com>
+
+ * glib/gpattern.c: applied a patch from matthias which checks on the
+ upper bound of GPatternSpec length to optimize matches.
+ cosmetic fixups.
+
+ * tests/patterntest.c: added more match cases.
+
2005-09-16 Tor Lillqvist <tml@novell.com>
* glib/gstrfuncs.c (g_ascii_strcasecmp, g_ascii_strncasecmp): Add
+Mon Sep 19 17:23:23 2005 Tim Janik <timj@imendio.com>
+
+ * glib/gpattern.c: applied a patch from matthias which checks on the
+ upper bound of GPatternSpec length to optimize matches.
+ cosmetic fixups.
+
+ * tests/patterntest.c: added more match cases.
+
2005-09-16 Tor Lillqvist <tml@novell.com>
* glib/gstrfuncs.c (g_ascii_strcasecmp, g_ascii_strncasecmp): Add
GMatchType match_type;
guint pattern_length;
guint min_length;
+ guint max_length;
gchar *pattern;
};
g_return_val_if_fail (pspec != NULL, FALSE);
g_return_val_if_fail (string != NULL, FALSE);
- if (pspec->min_length > string_length)
+ if (string_length < pspec->min_length ||
+ string_length > pspec->max_length)
return FALSE;
switch (pspec->match_type)
return TRUE;
case G_MATCH_EXACT:
if (pspec->pattern_length != string_length)
- return FALSE;
+ return FALSE;
else
- return strcmp (pspec->pattern, string) == 0;
+ return strcmp (pspec->pattern, string) == 0;
default:
g_return_val_if_fail (pspec->match_type < G_MATCH_LAST, FALSE);
return FALSE;
pspec = g_new (GPatternSpec, 1);
pspec->pattern_length = strlen (pattern);
pspec->min_length = 0;
+ pspec->max_length = 0;
pspec->pattern = g_new (gchar, pspec->pattern_length + 1);
d = pspec->pattern;
for (i = 0, s = pattern; *s != 0; s++)
case '?':
pending_jokers++;
pspec->min_length++;
+ pspec->max_length += 4; /* maximum UTF-8 character length */
continue;
default:
for (; pending_jokers; pending_jokers--, i++) {
}
follows_wildcard = FALSE;
pspec->min_length++;
+ pspec->max_length++;
break;
}
*d++ = *s;
seen_joker = hj_pos >= 0;
seen_wildcard = hw_pos >= 0;
more_wildcards = seen_wildcard && hw_pos != tw_pos;
+ if (seen_wildcard)
+ pspec->max_length = G_MAXUINT;
/* special case sole head/tail wildcard or exact matches */
if (!seen_joker && !more_wildcards)
GMatchType match_type;
guint pattern_length;
guint min_length;
+ guint max_length;
gchar *pattern;
};
TEST_MATCH("ab*", "ab\xc3\xa4\xc3\xb6", TRUE);
TEST_MATCH("ab*\xc3\xb6", "ab\xc3\xa4\xc3\xb6", TRUE);
TEST_MATCH("ab*\xc3\xb6", "aba\xc3\xb6x\xc3\xb6", TRUE);
- TEST_MATCH("", "", TRUE);
TEST_MATCH("", "abc", FALSE);
+
+ TEST_MATCH("", "", TRUE);
+ TEST_MATCH("abc", "abc", TRUE);
+ TEST_MATCH("*fo1*bar", "yyyfoxfo1bar", TRUE);
+ TEST_MATCH("12*fo1g*bar", "12yyyfoxfo1gbar", TRUE);
+ TEST_MATCH("__________:*fo1g*bar", "__________:yyyfoxfo1gbar", TRUE);
verbose ("\n%u tests passed, %u failed\n", passed, failed);