From: Behdad Esfahbod Date: Thu, 6 Jul 2006 20:30:16 +0000 (+0000) Subject: When matching debug flag keys, ignore case and accept any of comma, colon, X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=4e866367a74e3d2dce1d1c0f4d16b878e09e6a38;p=dana%2Fcg-glib.git When matching debug flag keys, ignore case and accept any of comma, colon, 2006-07-06 Behdad Esfahbod * glib/gutils.c (g_parse_debug_string): When matching debug flag keys, ignore case and accept any of comma, colon, semicolon, space, and tab as separators. Also, match dash with underscore. --- diff --git a/ChangeLog b/ChangeLog index b4d24429..ccaf7b17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-07-06 Behdad Esfahbod + + * glib/gutils.c (g_parse_debug_string): When matching debug flag keys, + ignore case and accept any of comma, colon, semicolon, space, and tab + as separators. Also, match dash with underscore. + 2006-07-05 Matthias Clasen * glib/gbase64.c: Fix typos in the docs. (#346660, Mark diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index b4d24429..ccaf7b17 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +2006-07-06 Behdad Esfahbod + + * glib/gutils.c (g_parse_debug_string): When matching debug flag keys, + ignore case and accept any of comma, colon, semicolon, space, and tab + as separators. Also, match dash with underscore. + 2006-07-05 Matthias Clasen * glib/gbase64.c: Fix typos in the docs. (#346660, Mark diff --git a/glib/gutils.c b/glib/gutils.c index 79248577..70fb864b 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -38,6 +38,7 @@ #include #include #include +#include /* For tolower() */ #include #ifdef HAVE_PWD_H #include @@ -552,16 +553,33 @@ g_find_program_in_path (const gchar *program) return NULL; } +static gboolean +debug_key_matches (const gchar *key, + const gchar *token, + guint length) +{ + for (; length; length--, key++, token++) + { + char k = (*key == '_') ? '-' : tolower (*key ); + char t = (*token == '_') ? '-' : tolower (*token); + + if (k != t) + return FALSE; + } + + return *key == '\0'; +} + /** * g_parse_debug_string: - * @string: a list of debug options separated by ':' or "all" - * to set all flags. + * @string: a list of debug options separated by colons, spaces, or + * commas; or the string "all" to set all flags. * @keys: pointer to an array of #GDebugKey which associate * strings with bit flags. * @nkeys: the number of #GDebugKeys in the array. * - * Parses a string containing debugging options separated - * by ':' into a %guint containing bit flags. This is used + * Parses a string containing debugging options + * into a %guint containing bit flags. This is used * within GDK and GTK+ to parse the debug options passed on the * command line or through environment variables. * @@ -594,17 +612,16 @@ g_parse_debug_string (const gchar *string, while (*p) { - q = strchr (p, ':'); + q = strpbrk (p, ":;, \t"); if (!q) q = p + strlen(p); for (i = 0; i < nkeys; i++) - if (g_ascii_strncasecmp (keys[i].key, p, q - p) == 0 && - keys[i].key[q - p] == '\0') + if (debug_key_matches (keys[i].key, p, q - p)) result |= keys[i].value; p = q; - if (*p == ':') + if (*p) p++; } }