--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/glib-compat.h Tue Oct 09 03:10:04 2007 -0400
@@ -0,0 +1,191 @@
+#ifndef g_str_has_suffix + * @str: a nul-terminated string. + * @suffix: the nul-terminated suffix to look for. + * Looks whether the string @str ends with @suffix. + * Return value: TRUE if @str end with @suffix, FALSE otherwise. +g_str_has_suffix (const gchar *str, + g_return_val_if_fail (str != NULL, FALSE); + g_return_val_if_fail (suffix != NULL, FALSE); + str_len = strlen (str); + suffix_len = strlen (suffix); + if (str_len < suffix_len) + return strcmp (str + str_len - suffix_len, suffix) == 0; +#ifndef g_str_has_prefix + * @str: a nul-terminated string. + * @prefix: the nul-terminated prefix to look for. + * Looks whether the string @str begins with @prefix. + * Return value: TRUE if @str begins with @prefix, FALSE otherwise. +g_str_has_prefix (const gchar *str, + g_return_val_if_fail (str != NULL, FALSE); + g_return_val_if_fail (prefix != NULL, FALSE); + str_len = strlen (str); + prefix_len = strlen (prefix); + if (str_len < prefix_len) + return strncmp (str, prefix, prefix_len) == 0; + * @string: The string to be tokenized + * @delimiters: A nul-terminated string containing bytes that are used + * @max_tokens: The maximum number of tokens to split @string into. + * If this is less than 1, the string is split completely + * Splits @string into a number of tokens not containing any of the characters + * in @delimiter. A token is the (possibly empty) longest string that does not + * contain any of the characters in @delimiters. If @max_tokens is reached, the + * remainder is appended to the last token. + * For example the result of g_strsplit_set ("abc:def/ghi", ":/", -1) is a + * %NULL-terminated vector containing the three strings "abc", "def", + * The result if g_strsplit_set (":def/ghi:", ":/", -1) is a %NULL-terminated + * vector containing the four strings "", "def", "ghi", and "". + * As a special case, the result of splitting the empty string "" is an empty + * vector, not a vector containing a single string. The reason for this + * special case is that being able to represent a empty vector is typically + * more useful than consistent handling of empty elements. If you do need + * to represent empty elements, you'll need to check for the empty string + * before calling g_strsplit_set(). + * Note that this function works on bytes not characters, so it can't be used + * to delimit UTF-8 strings for anything but ASCII characters. + * Return value: a newly-allocated %NULL-terminated array of strings. Use + * g_strfreev() to free it. +g_strsplit_set (const gchar *string, + const gchar *delimiters, + gboolean delim_table[256]; + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (delimiters != NULL, NULL); + result = g_new (char *, 1); + memset (delim_table, FALSE, sizeof (delim_table)); + for (s = delimiters; *s != '\0'; ++s) + delim_table[*(guchar *)s] = TRUE; + if (delim_table[*(guchar *)s] && n_tokens + 1 < max_tokens) + token = g_strndup (current, s - current); + tokens = g_slist_prepend (tokens, token); + token = g_strndup (current, s - current); + tokens = g_slist_prepend (tokens, token); + result = g_new (gchar *, n_tokens + 1); + result[n_tokens] = NULL; + for (list = tokens; list != NULL; list = list->next) + result[--n_tokens] = list->data; + * @str_array: a %NULL-terminated array of strings. + * Returns the length of the given %NULL-terminated + * string array @str_array. + * Return value: length of @str_array. + * From the file gstrfuncs.c +g_strv_length (gchar **str_array) + g_return_val_if_fail (str_array != NULL, 0);