[geocode-glib] lib: Remove duplicated _get_lang() functions



commit f3eccb3107b6fa5dfdea82bd38ed8189004aded9
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Nov 25 02:24:35 2012 +0100

    lib: Remove duplicated _get_lang() functions

 geocode-glib/geocode-forward.c      |   79 +----------------------------------
 geocode-glib/geocode-glib-private.h |    2 +
 geocode-glib/geocode-glib.c         |   10 ++--
 geocode-glib/geocode-reverse.c      |   79 +----------------------------------
 4 files changed, 9 insertions(+), 161 deletions(-)
---
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index 98add98..92d5884 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -119,83 +119,6 @@ _geocode_parse_single_result_json (const char  *contents,
 	return ret;
 }
 
-static gboolean
-parse_lang (const char *locale,
-	    char      **language_codep,
-	    char      **territory_codep)
-{
-	GRegex     *re;
-	GMatchInfo *match_info;
-	gboolean    res;
-	GError     *error;
-	gboolean    retval;
-
-	match_info = NULL;
-	retval = FALSE;
-
-	error = NULL;
-	re = g_regex_new ("^(?P<language>[^_  [:space:]]+)"
-			  "(_(?P<territory>[[:upper:]]+))?"
-			  "(\\.(?P<codeset>[-_0-9a-zA-Z]+))?"
-			  "(@(?P<modifier>[[:ascii:]]+))?$",
-			  0, 0, &error);
-	if (re == NULL) {
-		g_warning ("%s", error->message);
-		goto out;
-	}
-
-	if (!g_regex_match (re, locale, 0, &match_info) ||
-	    g_match_info_is_partial_match (match_info)) {
-		g_warning ("locale '%s' isn't valid\n", locale);
-		goto out;
-	}
-
-	res = g_match_info_matches (match_info);
-	if (! res) {
-		g_warning ("Unable to parse locale: %s", locale);
-		goto out;
-	}
-
-	retval = TRUE;
-
-	*language_codep = g_match_info_fetch_named (match_info, "language");
-
-	*territory_codep = g_match_info_fetch_named (match_info, "territory");
-
-	if (*territory_codep != NULL &&
-	    *territory_codep[0] == '\0') {
-		g_free (*territory_codep);
-		*territory_codep = NULL;
-	}
-
-out:
-	g_match_info_free (match_info);
-	g_regex_unref (re);
-
-	return retval;
-}
-
-static char *
-geocode_forward_get_lang_for_locale (const char *locale)
-{
-	char *lang;
-	char *territory;
-
-	if (parse_lang (locale, &lang, &territory) == FALSE)
-		return NULL;
-
-	return g_strdup_printf ("%s%s%s",
-				lang,
-				territory ? "-" : "",
-				territory ? territory : "");
-}
-
-static char *
-geocode_forward_get_lang (void)
-{
-	return geocode_forward_get_lang_for_locale (setlocale (LC_MESSAGES, NULL));
-}
-
 static struct {
 	const char *tp_attr;
 	const char *gc_attr; /* NULL to ignore */
@@ -455,7 +378,7 @@ get_search_query_for_params (GeocodeForward *forward,
 	ht = g_hash_table_new (g_str_hash, g_str_equal);
 	g_hash_table_insert (ht, "appid", YAHOO_APPID);
 	g_hash_table_insert (ht, "format", "json");
-	lang = geocode_forward_get_lang ();
+	lang = _geocode_object_get_lang ();
 	if (lang)
 		g_hash_table_insert (ht, "lang", lang);
 
diff --git a/geocode-glib/geocode-glib-private.h b/geocode-glib/geocode-glib-private.h
index 586e62b..6529849 100644
--- a/geocode-glib/geocode-glib-private.h
+++ b/geocode-glib/geocode-glib-private.h
@@ -41,6 +41,8 @@ GList      *_geocode_parse_search_json  (const char *contents,
 GFile      *_get_resolve_query_for_params (GHashTable  *orig_ht,
 					   gboolean     reverse);
 
+char       *_geocode_object_get_lang (void);
+
 char *_geocode_glib_cache_path_for_query (GFile *query);
 gboolean _geocode_glib_cache_save (GFile      *query,
 				  const char *contents);
diff --git a/geocode-glib/geocode-glib.c b/geocode-glib/geocode-glib.c
index a1cf07c..8715c7f 100644
--- a/geocode-glib/geocode-glib.c
+++ b/geocode-glib/geocode-glib.c
@@ -214,12 +214,12 @@ geocode_object_get_lang_for_locale (const char *locale)
 
 	return g_strdup_printf ("%s%s%s",
 				lang,
-				territory ? "_" : "",
+				territory ? "-" : "",
 				territory ? territory : "");
 }
 
-static char *
-geocode_object_get_lang (void)
+char *
+_geocode_object_get_lang (void)
 {
 	return geocode_object_get_lang_for_locale (setlocale (LC_MESSAGES, NULL));
 }
@@ -572,7 +572,7 @@ get_resolve_query_for_params (GeocodeObject *object,
 
 	locale = NULL;
 	if (g_hash_table_lookup (ht, "locale") == NULL) {
-		locale = geocode_object_get_lang ();
+		locale = _geocode_object_get_lang ();
 		if (locale)
 			g_hash_table_insert (ht, "locale", locale);
 	}
@@ -765,7 +765,7 @@ get_search_query_for_params (GeocodeObject *object,
 	ht = g_hash_table_new (g_str_hash, g_str_equal);
 	g_hash_table_insert (ht, "appid", YAHOO_APPID);
 	g_hash_table_insert (ht, "format", "json");
-	lang = geocode_object_get_lang ();
+	lang = _geocode_object_get_lang ();
 	if (lang)
 		g_hash_table_insert (ht, "lang", lang);
 
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index 0eb082a..64cf5be 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -78,83 +78,6 @@ geocode_reverse_init (GeocodeReverse *object)
 						  g_free, g_free);
 }
 
-static gboolean
-parse_lang (const char *locale,
-	    char      **language_codep,
-	    char      **territory_codep)
-{
-	GRegex     *re;
-	GMatchInfo *match_info;
-	gboolean    res;
-	GError     *error;
-	gboolean    retval;
-
-	match_info = NULL;
-	retval = FALSE;
-
-	error = NULL;
-	re = g_regex_new ("^(?P<language>[^_  [:space:]]+)"
-			  "(_(?P<territory>[[:upper:]]+))?"
-			  "(\\.(?P<codeset>[-_0-9a-zA-Z]+))?"
-			  "(@(?P<modifier>[[:ascii:]]+))?$",
-			  0, 0, &error);
-	if (re == NULL) {
-		g_warning ("%s", error->message);
-		goto out;
-	}
-
-	if (!g_regex_match (re, locale, 0, &match_info) ||
-	    g_match_info_is_partial_match (match_info)) {
-		g_warning ("locale '%s' isn't valid\n", locale);
-		goto out;
-	}
-
-	res = g_match_info_matches (match_info);
-	if (! res) {
-		g_warning ("Unable to parse locale: %s", locale);
-		goto out;
-	}
-
-	retval = TRUE;
-
-	*language_codep = g_match_info_fetch_named (match_info, "language");
-
-	*territory_codep = g_match_info_fetch_named (match_info, "territory");
-
-	if (*territory_codep != NULL &&
-	    *territory_codep[0] == '\0') {
-		g_free (*territory_codep);
-		*territory_codep = NULL;
-	}
-
-out:
-	g_match_info_free (match_info);
-	g_regex_unref (re);
-
-	return retval;
-}
-
-static char *
-geocode_reverse_get_lang_for_locale (const char *locale)
-{
-	char *lang;
-	char *territory;
-
-	if (parse_lang (locale, &lang, &territory) == FALSE)
-		return NULL;
-
-	return g_strdup_printf ("%s%s%s",
-				lang,
-				territory ? "_" : "",
-				territory ? territory : "");
-}
-
-static char *
-geocode_reverse_get_lang (void)
-{
-	return geocode_reverse_get_lang_for_locale (setlocale (LC_MESSAGES, NULL));
-}
-
 /**
  * geocode_reverse_new_for_coords:
  * @latitude: a valid latitude
@@ -461,7 +384,7 @@ _get_resolve_query_for_params (GHashTable  *orig_ht,
 
 	locale = NULL;
 	if (g_hash_table_lookup (ht, "locale") == NULL) {
-		locale = geocode_reverse_get_lang ();
+		locale = _geocode_object_get_lang ();
 		if (locale)
 			g_hash_table_insert (ht, "locale", locale);
 	}



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