--- a/gplate/gplate-util.c Wed Feb 20 00:48:17 2008 -0600
+++ b/gplate/gplate-util.c Wed Feb 20 00:54:01 2008 -0600
@@ -22,9 +22,10 @@
#include <gplate/gplate-errors.h>
/******************************************************************************
*****************************************************************************/
-static GRegex *quoted_string_regex = NULL;
+#define QUOTED_REGEX "\\s*(\"(.+)\"|'(.+)')\\s*" +#define FIRST_WORD_REGEX "\\s*([a-zA-Z_][a-zA-Z0-9_\\.]*)(\\s*(.*))?" /******************************************************************************
@@ -82,17 +83,16 @@
gplate_util_is_quoted_string(const gchar *str, gchar **contents) {
+ static GRegex *regex = NULL; g_return_val_if_fail(str, FALSE);
- if(!quoted_string_regex) {
- quoted_string_regex = g_regex_new("\\s*(\"(.+)\"|'(.+)')\\s*",
+ regex = g_regex_new(QUOTED_REGEX, G_REGEX_OPTIMIZE, 0, NULL); - ret = g_regex_match(quoted_string_regex, str, 0, &info);
+ ret = g_regex_match(regex, str, 0, &info); *contents = g_match_info_fetch(info, 1);
@@ -101,3 +101,42 @@
+ * gplate_util_get_first_word: + * @str: The string who's first word to get. + * @leftovers: The return address for everything after the first word. + * Gets the first word of a @str and returns it. The remaining contents of + * @str are stored in @leftovers if provided. + * The use of "word" is a bit of a misnomer. A word in this sense is a series + * of characters that begins with an letter or underscore and is followed by + * any number of letters, numbers, periods, or underscores. + * Return Value: The first word of @str, or NULL. +gplate_util_get_first_word(const gchar *str, gchar **leftovers) { + static GRegex *regex = NULL; + GMatchInfo *info = NULL; + g_return_val_if_fail(str, NULL); + regex = g_regex_new(FIRST_WORD_REGEX, G_REGEX_OPTIMIZE, 0, NULL); + if(!g_regex_match(regex, str, 0, &info)) + ret = g_match_info_fetch(info, 1); + if(leftovers && g_match_info_get_match_count(info) > 2) + *leftovers = g_match_info_fetch(info, 3); + g_match_info_free(info);