[gnome-session] gnome-session-check-accelerated: Simplify _has_extension()
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] gnome-session-check-accelerated: Simplify _has_extension()
- Date: Tue, 13 Nov 2012 17:39:47 +0000 (UTC)
commit 69ed18b716c73fef014086d86c038825d0724128
Author: Bastien Nocera <hadess hadess net>
Date: Tue Nov 13 16:16:38 2012 +0100
gnome-session-check-accelerated: Simplify _has_extension()
https://bugzilla.gnome.org/show_bug.cgi?id=688252
tools/gnome-session-check-accelerated-helper.c | 46 +++++++++--------------
1 files changed, 18 insertions(+), 28 deletions(-)
---
diff --git a/tools/gnome-session-check-accelerated-helper.c b/tools/gnome-session-check-accelerated-helper.c
index 0e24582..e4aa3db 100644
--- a/tools/gnome-session-check-accelerated-helper.c
+++ b/tools/gnome-session-check-accelerated-helper.c
@@ -318,43 +318,33 @@ static gboolean
_has_extension (const char *extension_list,
const char *extension)
{
- int s = 0, e = 0;
- int ext_len;
+ char **extensions;
+ guint i;
+ gboolean ret;
- /* Extension_list is one big string, containing extensions
- * separated by spaces. We could use strstr, except that we
- * can't know for sure that there's no extension that starts
- * with the same string... */
+ g_return_val_if_fail (extension != NULL, TRUE);
- if (!extension_list || extension_list[0] == 0)
+ /* Extension_list is one big string, containing extensions
+ * separated by spaces. */
+ if (extension_list == NULL)
return FALSE;
- if (!extension || extension[0] == 0)
- return TRUE;
-
- ext_len = strlen (extension);
- while (1) {
- if (extension_list[e] != ' ' && extension_list[e] != 0) {
- e++;
- continue;
- }
+ ret = FALSE;
- /* End of a word. Was is the extension we're looking for? */
- if ((e - s) == ext_len &&
- strncmp (&extension_list[s], extension, ext_len) == 0) {
- return TRUE;
- }
+ extensions = g_strsplit (extension_list, " ", -1);
+ if (extensions == NULL)
+ return FALSE;
- /* was it the end of the string? */
- if (extension_list[e] == 0)
+ for (i = 0; extensions[i] != NULL; i++) {
+ if (g_str_equal (extensions[i], extension)) {
+ ret = TRUE;
break;
-
- /* skip the space and start looking at the next word */
- e++;
- s = e;
+ }
}
- return FALSE;
+ g_strfreev (extensions);
+
+ return ret;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]