[gnome-software/wip/temp/ubuntu-xenial-rebased-corrected: 62/331] Hack up a simple search filter



commit d8785d5aae9e796be68834d37201b34260e83926
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Jan 26 15:03:08 2016 +1300

    Hack up a simple search filter

 src/plugins/gs-plugin-snappy.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/gs-plugin-snappy.c b/src/plugins/gs-plugin-snappy.c
index ca1f2dc..247465d 100644
--- a/src/plugins/gs-plugin-snappy.c
+++ b/src/plugins/gs-plugin-snappy.c
@@ -23,6 +23,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <gs-plugin.h>
 #include <gio/gunixsocketaddress.h>
 #include <libsoup/soup.h>
@@ -349,10 +350,31 @@ gs_plugin_add_installed (GsPlugin *plugin,
 }
 
 static gboolean
+string_contains (const gchar *string, const gchar *fragment)
+{
+       gint i, j;
+
+       for (i = 0; string[i]; i++) {
+               for (j = 0; fragment[j] && string[i+j] && tolower (string[i+j]) == tolower (fragment[j]); 
j++);
+               if (fragment[j] == '\0')
+                       return TRUE;
+       }
+
+       return FALSE;
+}
+
+static gboolean
 matches_search (const gchar *id, JsonObject *object, gpointer data)
 {
-       gchar **values = data;
-       return TRUE;
+       gchar **search_terms = data;
+       gint i;
+
+       for (i = 0; search_terms[i]; i++)
+               if (string_contains (json_object_get_string_member (object, "name"), search_terms[i]) ||
+                   string_contains (json_object_get_string_member (object, "description"), search_terms[i]))
+                       return TRUE;
+
+       return FALSE;
 }
 
 gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]