summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-06 15:14:42 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-08 13:43:39 (GMT)
commit0005ac1a1cf3affd0a49ed53af8de89705858fb1 (patch)
treef69f702f9023b84a3fe2ea117051f672a7f184b2
parent87ed6d3f7399a64c01231664974c6d853eb9fe87 (diff)
downloadtraprain-0005ac1a1cf3affd0a49ed53af8de89705858fb1.tar.gz
traprain-0005ac1a1cf3affd0a49ed53af8de89705858fb1.tar.xz
common: add _trp_languages_map_to_hash()
Signed-off-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk> Differential Revision: https://phabricator.apertis.org/D4201
-rw-r--r--traprain-common/languages-map-internal.h2
-rw-r--r--traprain-common/languages-map.c19
2 files changed, 21 insertions, 0 deletions
diff --git a/traprain-common/languages-map-internal.h b/traprain-common/languages-map-internal.h
index cc289b3..30f9c80 100644
--- a/traprain-common/languages-map-internal.h
+++ b/traprain-common/languages-map-internal.h
@@ -36,6 +36,8 @@ void _trp_languages_map_assert_same_content (_TrpLanguagesMap *a,
const gchar *_trp_languages_map_lookup (_TrpLanguagesMap *map,
const gchar *language);
+GHashTable *_trp_languages_map_to_hash (_TrpLanguagesMap *map);
+
G_END_DECLS
#endif /* __TRAPRAIN_LANGUAGES_MAP_INTERNAL_H__ */
diff --git a/traprain-common/languages-map.c b/traprain-common/languages-map.c
index edc1f50..e837bb1 100644
--- a/traprain-common/languages-map.c
+++ b/traprain-common/languages-map.c
@@ -175,3 +175,22 @@ _trp_languages_map_lookup (_TrpLanguagesMap *map,
return NULL;
}
+
+GHashTable *
+_trp_languages_map_to_hash (_TrpLanguagesMap *map)
+{
+ GHashTable *h;
+ guint i;
+
+ h = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
+
+ for (i = 0; i < map->len; i++)
+ {
+ _TrpLanguageString s = g_array_index (map, _TrpLanguageString, i);
+
+ /* Language is interned so no need to dup */
+ g_hash_table_insert (h, (gpointer) s.language, g_strdup (s.string));
+ }
+
+ return h;
+}