diff options
author | Richard Hughes <richard@hughsie.com> | 2015-09-16 15:58:27 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-09-16 17:59:30 +0100 |
commit | d707ebe7e684a7f8aae6c65be390d02cb0740077 (patch) | |
tree | d78638bb2776bdb50d8adae7ab41449a72b0fe9d /libappstream-glib | |
parent | da5e21b44a51a9df81f168ecbbd4416925558315 (diff) | |
download | appstream-glib-d707ebe7e684a7f8aae6c65be390d02cb0740077.tar.gz |
Do not ever store the KDE x-test locale data
Diffstat (limited to 'libappstream-glib')
-rw-r--r-- | libappstream-glib/as-app.c | 37 | ||||
-rw-r--r-- | libappstream-glib/as-node-private.h | 1 | ||||
-rw-r--r-- | libappstream-glib/as-node.c | 35 |
3 files changed, 44 insertions, 29 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index f0c5b84..3b89aba 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -1724,25 +1724,6 @@ as_app_set_icon_path (AsApp *app, const gchar *icon_path) } /** - * as_app_parse_locale: - **/ -static gchar * -as_app_parse_locale (const gchar *locale) -{ - gchar *tmp; - - if (locale == NULL) - return g_strdup ("C"); - if (g_strcmp0 (locale, "xx") == 0) - return NULL; - if (g_strcmp0 (locale, "x-test") == 0) - return NULL; - tmp = g_strdup (locale); - g_strdelimit (tmp, "-", '_'); - return tmp; -} - -/** * as_app_set_name: * @app: a #AsApp instance. * @locale: the locale, or %NULL. e.g. "en_GB" @@ -1768,7 +1749,7 @@ as_app_set_name (AsApp *app, } /* get fixed locale */ - tmp_locale = as_app_parse_locale (locale); + tmp_locale = as_node_fix_locale (locale); if (tmp_locale == NULL) return; g_hash_table_insert (priv->names, @@ -1804,7 +1785,7 @@ as_app_set_comment (AsApp *app, } /* get fixed locale */ - tmp_locale = as_app_parse_locale (locale); + tmp_locale = as_node_fix_locale (locale); if (tmp_locale == NULL) return; g_hash_table_insert (priv->comments, @@ -1840,7 +1821,7 @@ as_app_set_developer_name (AsApp *app, } /* get fixed locale */ - tmp_locale = as_app_parse_locale (locale); + tmp_locale = as_node_fix_locale (locale); if (tmp_locale == NULL) return; g_hash_table_insert (priv->developer_names, @@ -1876,7 +1857,7 @@ as_app_set_description (AsApp *app, } /* get fixed locale */ - tmp_locale = as_app_parse_locale (locale); + tmp_locale = as_node_fix_locale (locale); if (tmp_locale == NULL) return; g_hash_table_insert (priv->descriptions, @@ -1990,7 +1971,7 @@ as_app_add_keyword (AsApp *app, } /* get fixed locale */ - tmp_locale = as_app_parse_locale (locale); + tmp_locale = as_node_fix_locale (locale); if (tmp_locale == NULL) return; @@ -3290,7 +3271,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags, /* <name> */ case AS_TAG_NAME: - taken = as_app_parse_locale (as_node_get_attribute (n, "xml:lang")); + taken = as_node_fix_locale (as_node_get_attribute (n, "xml:lang")); if (taken == NULL) break; g_hash_table_insert (priv->names, @@ -3300,7 +3281,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags, /* <summary> */ case AS_TAG_SUMMARY: - taken = as_app_parse_locale (as_node_get_attribute (n, "xml:lang")); + taken = as_node_fix_locale (as_node_get_attribute (n, "xml:lang")); if (taken == NULL) break; g_hash_table_insert (priv->comments, @@ -3310,7 +3291,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags, /* <developer_name> */ case AS_TAG_DEVELOPER_NAME: - taken = as_app_parse_locale (as_node_get_attribute (n, "xml:lang")); + taken = as_node_fix_locale (as_node_get_attribute (n, "xml:lang")); if (taken == NULL) break; g_hash_table_insert (priv->developer_names, @@ -3412,7 +3393,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags, tmp = as_node_get_data (c); if (tmp == NULL) continue; - taken = as_app_parse_locale (as_node_get_attribute (c, "xml:lang")); + taken = as_node_fix_locale (as_node_get_attribute (c, "xml:lang")); if (taken == NULL) continue; as_app_add_keyword (app, taken, tmp); diff --git a/libappstream-glib/as-node-private.h b/libappstream-glib/as-node-private.h index 71ecc08..785afda 100644 --- a/libappstream-glib/as-node-private.h +++ b/libappstream-glib/as-node-private.h @@ -48,6 +48,7 @@ gchar *as_node_take_attribute (const GNode *node, const gchar *key); gchar *as_node_reflow_text (const gchar *text, gssize text_len); +gchar *as_node_fix_locale (const gchar *locale); G_END_DECLS diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c index 53df10c..db7f22d 100644 --- a/libappstream-glib/as-node.c +++ b/libappstream-glib/as-node.c @@ -1470,6 +1470,8 @@ as_node_insert_localized (AsNode *parent, key = l->data; if (g_strcmp0 (key, "C") == 0) continue; + if (g_strcmp0 (key, "x-test") == 0) + continue; value = g_hash_table_lookup (localized, key); if ((insert_flags & AS_NODE_INSERT_FLAG_DEDUPE_LANG) > 0 && g_strcmp0 (value_c, value) == 0) @@ -1575,6 +1577,8 @@ as_node_get_localized (const AsNode *node, const gchar *key) if (g_strcmp0 (as_tag_data_get_name (data), key) != 0) continue; xml_lang = as_node_attr_lookup (data, "xml:lang"); + if (g_strcmp0 (xml_lang, "x-test") == 0) + continue; /* avoid storing identical strings */ data_localized = data->cdata; @@ -1827,6 +1831,31 @@ as_node_get_localized_unwrap_type_ul (const AsNode *node, } /** + * as_node_fix_locale: (skip) + * + * Fixes and filters incorrect locale strings. + * + * Returns: a newly allocated string + * + * Since: 0.5.2 + **/ +gchar * +as_node_fix_locale (const gchar *locale) +{ + gchar *tmp; + + if (locale == NULL) + return g_strdup ("C"); + if (g_strcmp0 (locale, "xx") == 0) + return NULL; + if (g_strcmp0 (locale, "x-test") == 0) + return NULL; + tmp = g_strdup (locale); + g_strdelimit (tmp, "-", '_'); + return tmp; +} + +/** * as_node_get_localized_unwrap: * @node: a #AsNode. * @error: A #GError or %NULL. @@ -1907,10 +1936,14 @@ as_node_get_localized_unwrap (const AsNode *node, GError **error) results = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); keys = g_hash_table_get_keys (hash); for (l = keys; l != NULL; l = l->next) { + gchar *locale_fixed; xml_lang = l->data; + locale_fixed = as_node_fix_locale (xml_lang); + if (locale_fixed == NULL) + continue; str = g_hash_table_lookup (hash, xml_lang); g_hash_table_insert (results, - g_strdup (xml_lang), + locale_fixed, g_strdup (str->str)); } return results; |