[tepl] Encoding: get_all(): include locale encoding



commit facf7d1c48e6d829e38c0e105c0791d500b4c86a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Oct 26 10:29:54 2017 +0200

    Encoding: get_all(): include locale encoding

 tepl/tepl-encoding.c |   44 +++++++++++++++++++++++++++++---------------
 1 files changed, 29 insertions(+), 15 deletions(-)
---
diff --git a/tepl/tepl-encoding.c b/tepl/tepl-encoding.c
index 16d390d..c11674b 100644
--- a/tepl/tepl-encoding.c
+++ b/tepl/tepl-encoding.c
@@ -453,6 +453,25 @@ tepl_encoding_equals (const TeplEncoding *enc1,
        return g_ascii_strcasecmp (enc1->charset, enc2->charset) == 0;
 }
 
+static gboolean
+present_in_list (const GSList       *list,
+                const TeplEncoding *enc)
+{
+       const GSList *l;
+
+       for (l = list; l != NULL; l = l->next)
+       {
+               const TeplEncoding *cur_enc = l->data;
+
+               if (tepl_encoding_equals (cur_enc, enc))
+               {
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
 /**
  * tepl_encoding_get_all:
  *
@@ -466,6 +485,7 @@ GSList *
 tepl_encoding_get_all (void)
 {
        GSList *list = NULL;
+       TeplEncoding *locale_enc;
        gint i;
 
        for (i = G_N_ELEMENTS (encodings_table) - 1; i >= 0; i--)
@@ -479,26 +499,20 @@ tepl_encoding_get_all (void)
                list = g_slist_prepend (list, enc);
        }
 
-       return list;
-}
+       /* Add locale encoding first. */
 
-static gboolean
-present_in_list (const GSList       *list,
-                const TeplEncoding *enc)
-{
-       const GSList *l;
+       locale_enc = tepl_encoding_new_from_locale ();
 
-       for (l = list; l != NULL; l = l->next)
+       if (present_in_list (list, locale_enc))
        {
-               const TeplEncoding *cur_enc = l->data;
-
-               if (tepl_encoding_equals (cur_enc, enc))
-               {
-                       return TRUE;
-               }
+               tepl_encoding_free (locale_enc);
+       }
+       else
+       {
+               list = g_slist_prepend (list, locale_enc);
        }
 
-       return FALSE;
+       return list;
 }
 
 static GSList *


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