[gspell/wip/untie-libxml: 4/5] cont. 2



commit cc1a1294ef3db3957b6e741286fd88d94ae169a7
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Dec 10 19:04:01 2015 +0100

    cont. 2

 gspell/gspell-language.c |  141 +++++++++++++++++++++++-----------------------
 1 files changed, 71 insertions(+), 70 deletions(-)
---
diff --git a/gspell/gspell-language.c b/gspell/gspell-language.c
index 65ad73d..be0f95d 100644
--- a/gspell/gspell-language.c
+++ b/gspell/gspell-language.c
@@ -35,6 +35,11 @@ struct _GspellLanguage
        gchar *ckey;
 };
 
+G_DEFINE_BOXED_TYPE (GspellLanguage,
+                    gspell_language,
+                    gspell_language_copy,
+                    gspell_language_free)
+
 static GHashTable *iso_639_table = NULL;
 static GHashTable *iso_3166_table = NULL;
 
@@ -276,14 +281,15 @@ spell_language_dict_describe_cb (const gchar * const language_code,
 
        iso_639_name = g_hash_table_lookup (iso_639_table, tokens[0]);
 
-       if (iso_639_name == NULL) {
-               language_name = g_strdup_printf (
+       if (iso_639_name == NULL)
+       {
                /* Translators: %s is the language ISO code. */
-                       C_("language", "Unknown (%s)"), language_code);
+               language_name = g_strdup_printf (C_("language", "Unknown (%s)"), language_code);
                goto exit;
        }
 
-       if (g_strv_length (tokens) < 2) {
+       if (g_strv_length (tokens) < 2)
+       {
                language_name = g_strdup (iso_639_name);
                goto exit;
        }
@@ -291,15 +297,23 @@ spell_language_dict_describe_cb (const gchar * const language_code,
        iso_3166_name = g_hash_table_lookup (iso_3166_table, tokens[1]);
 
        if (iso_3166_name != NULL)
-               language_name = g_strdup_printf (
-                /* Translators: The first %s is the language name, and the
-                * second is the country name. Example: "French (France)" */
-                       C_("language", "%s (%s)"), iso_639_name, iso_3166_name);
+       {
+               /* Translators: The first %s is the language name, and the
+                * second is the country name. Example: "French (France)".
+                */
+               language_name = g_strdup_printf (C_("language", "%s (%s)"),
+                                                iso_639_name,
+                                                iso_3166_name);
+       }
        else
-               language_name = g_strdup_printf (
-                /* Translators: The first %s is the language name, and the
-                * second is the country name. Example: "French (France)" */
-                       C_("language", "%s (%s)"), iso_639_name, tokens[1]);
+       {
+               /* Translators: The first %s is the language name, and the
+                * second is the country name. Example: "French (France)".
+                */
+               language_name = g_strdup_printf (C_("language", "%s (%s)"),
+                                                iso_639_name,
+                                                tokens[1]);
+       }
 
 exit:
        g_strfreev (tokens);
@@ -308,18 +322,6 @@ exit:
 }
 
 static const GspellLanguage *
-spell_language_copy (const GspellLanguage *language)
-{
-       return language;
-}
-
-static void
-spell_language_free (const GspellLanguage *language)
-{
-       /* do nothing */
-}
-
-static const GspellLanguage *
 spell_language_lookup (const gchar *language_code)
 {
        const GspellLanguage *closest_match = NULL;
@@ -327,16 +329,21 @@ spell_language_lookup (const gchar *language_code)
 
        available_languages = gspell_language_get_available ();
 
-       while (available_languages != NULL && language_code != NULL) {
+       while (available_languages != NULL && language_code != NULL)
+       {
                GspellLanguage *language = available_languages->data;
                const gchar *code = language->code;
                gsize length = strlen (code);
 
                if (g_ascii_strcasecmp (language_code, code) == 0)
+               {
                        return language;
+               }
 
                if (g_ascii_strncasecmp (language_code, code, length) == 0)
+               {
                        closest_match = language;
+               }
 
                available_languages = g_list_next (available_languages);
        }
@@ -345,9 +352,9 @@ spell_language_lookup (const gchar *language_code)
 }
 
 static gboolean
-spell_language_traverse_cb (const gchar *code,
-                            const gchar *name,
-                            GList **available_languages)
+spell_language_traverse_cb (const gchar  *code,
+                           const gchar  *name,
+                           GList       **available_languages)
 {
        GspellLanguage *language;
 
@@ -356,27 +363,13 @@ spell_language_traverse_cb (const gchar *code,
        language->name = g_strdup (name);
        language->ckey = g_utf8_collate_key (name, -1);
 
-       *available_languages = g_list_insert_sorted (
-               *available_languages, language,
-               (GCompareFunc) gspell_language_compare);
+       *available_languages = g_list_insert_sorted (*available_languages,
+                                                    language,
+                                                    (GCompareFunc) gspell_language_compare);
 
        return FALSE;
 }
 
-GType
-gspell_language_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0))
-               type = g_boxed_type_register_static (
-                       "GspellLanguage",
-                       (GBoxedCopyFunc) spell_language_copy,
-                       (GBoxedFreeFunc) spell_language_free);
-
-       return type;
-}
-
 const GList *
 gspell_language_get_available (void)
 {
@@ -386,48 +379,45 @@ gspell_language_get_available (void)
        GTree *tree;
 
        if (initialized)
+       {
                return available_languages;
+       }
 
        initialized = TRUE;
 
-#if defined (ENABLE_NLS) && defined (HAVE_ISO_CODES)
        bindtextdomain (ISO_639_DOMAIN, ISOCODESLOCALEDIR);
        bind_textdomain_codeset (ISO_639_DOMAIN, "UTF-8");
 
        bindtextdomain (ISO_3166_DOMAIN, ISOCODESLOCALEDIR);
        bind_textdomain_codeset (ISO_3166_DOMAIN, "UTF-8");
-#endif
 
-       iso_639_table = g_hash_table_new_full (
-               g_str_hash, g_str_equal,
-               (GDestroyNotify) g_free,
-               (GDestroyNotify) g_free);
+       iso_639_table = g_hash_table_new_full (g_str_hash,
+                                              g_str_equal,
+                                              (GDestroyNotify) g_free,
+                                              (GDestroyNotify) g_free);
 
-       iso_3166_table = g_hash_table_new_full (
-               g_str_hash, g_str_equal,
-               (GDestroyNotify) g_free,
-               (GDestroyNotify) g_free);
+       iso_3166_table = g_hash_table_new_full (g_str_hash,
+                                               g_str_equal,
+                                               (GDestroyNotify) g_free,
+                                               (GDestroyNotify) g_free);
 
-#ifdef HAVE_ISO_CODES
        iso_codes_parse (&iso_639_parser, "iso_639.xml", iso_639_table);
        iso_codes_parse (&iso_3166_parser, "iso_3166.xml", iso_3166_table);
-#endif
 
-       tree = g_tree_new_full (
-               (GCompareDataFunc) strcmp, NULL,
-               (GDestroyNotify) g_free,
-               (GDestroyNotify) g_free);
+       tree = g_tree_new_full ((GCompareDataFunc) strcmp,
+                               NULL,
+                               (GDestroyNotify) g_free,
+                               (GDestroyNotify) g_free);
 
        broker = enchant_broker_init ();
-       enchant_broker_list_dicts (
-               broker, (EnchantDictDescribeFn)
-               spell_language_dict_describe_cb, tree);
+       enchant_broker_list_dicts (broker,
+                                  (EnchantDictDescribeFn) spell_language_dict_describe_cb,
+                                  tree);
        enchant_broker_free (broker);
 
-       g_tree_foreach (
-               tree, (GTraverseFunc)
-               spell_language_traverse_cb,
-               &available_languages);
+       g_tree_foreach (tree,
+                       (GTraverseFunc) spell_language_traverse_cb,
+                       &available_languages);
 
        g_tree_destroy (tree);
 
@@ -446,13 +436,19 @@ spell_language_pick_default (void)
        available_languages = gspell_language_get_available ();
 
        for (ii = 0; language == NULL && language_names[ii] != NULL; ii++)
+       {
                language = spell_language_lookup (language_names[ii]);
+       }
 
        if (language == NULL)
+       {
                language = spell_language_lookup ("en_US");
+       }
 
        if (language == NULL && available_languages != NULL)
+       {
                language = available_languages->data;
+       }
 
        return language;
 }
@@ -465,7 +461,9 @@ gspell_language_lookup (const gchar *language_code)
        language = spell_language_lookup (language_code);
 
        if (language == NULL)
+       {
                language = spell_language_pick_default ();
+       }
 
        return language;
 }
@@ -482,9 +480,12 @@ const gchar *
 gspell_language_get_name (const GspellLanguage *language)
 {
        if (language == NULL)
-                /* Translators: This refers to the default language used
-                * by the spell checker. */
+       {
+               /* Translators: This refers to the default language used by the
+                * spell checker.
+                */
                return C_("language", "Default");
+       }
 
        return language->name;
 }


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