[geocode-glib] lib: Print warning for unknown XEP attributes



commit 295a039f157657252819969524f40f72ca19dbe9
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Nov 25 23:14:05 2012 +0100

    lib: Print warning for unknown XEP attributes

 TODO                           |    1 -
 geocode-glib/geocode-forward.c |   45 ++++++++++++++++++++++++++++-----------
 2 files changed, 32 insertions(+), 14 deletions(-)
---
diff --git a/TODO b/TODO
index 3e19882..17ce18c 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
 - More test cases
 - Write examples
 
-- Make geocode_foward_new_for_params() output warnings if a key is unknown to us
 - Create better descriptions from the search results, and fix Paris test case for it
 - Add test case for search json parsing
 - Make answer count a property and immutable if XEP params are passed
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index c1b0904..1f8f72a 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -131,7 +131,7 @@ static struct {
 	{ "postalcode", "postal" },
 	{ "street", "street" },
 	{ "building", "house" },
-	{ "floor", "" },
+	{ "floor", NULL },
 	{ "room", "unit" },
 	{ "text", NULL },
 	{ "description", NULL },
@@ -139,30 +139,49 @@ static struct {
 	{ "language", "locale" },
 };
 
-static void
-geocode_forward_fill_params (GeocodeForward *forward,
-			     GHashTable    *params)
+static const char *
+tp_attr_to_gc_attr (const char *attr,
+		    gboolean   *found)
 {
 	guint i;
 
+	*found = FALSE;
+
 	for (i = 0; i < G_N_ELEMENTS (attrs_map); i++) {
-		const char *str;
-		GValue *value;
+		if (g_str_equal (attr, attrs_map[i].tp_attr)){
+			*found = TRUE;
+			return attrs_map[i].gc_attr;
+		}
+	}
 
-		if (attrs_map[i].gc_attr == NULL)
-			continue;
+	return NULL;
+}
+
+static void
+geocode_forward_fill_params (GeocodeForward *forward,
+			     GHashTable    *params)
+{
+	GHashTableIter iter;
+	GValue *value;
+	const char *key;
+
+	g_hash_table_iter_init (&iter, params);
+	while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value)) {
+		gboolean found;
+		const char *gc_attr;
+		const char *str;
 
-		value = g_hash_table_lookup (params, attrs_map[i].tp_attr);
-		if (value == NULL)
+		gc_attr = tp_attr_to_gc_attr (key, &found);
+		if (found == FALSE) {
+			g_warning ("XEP attribute '%s' unhandled", key);
 			continue;
+		}
 
 		str = g_value_get_string (value);
 		if (str == NULL)
 			continue;
 
-		geocode_forward_add (forward,
-				    attrs_map[i].gc_attr,
-				    str);
+		geocode_forward_add (forward, gc_attr, str);
 	}
 }
 



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