[evince] comics: Split off checking whether a file has a supported extension



commit 06c17eb0e7e9fe4d7c1194c7b482b0d4221e436c
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Jul 18 16:43:16 2017 +0200

    comics: Split off checking whether a file has a supported extension
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784963

 backend/comics/comics-document.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c
index b3e028f..cb9d2fc 100644
--- a/backend/comics/comics-document.c
+++ b/backend/comics/comics-document.c
@@ -58,7 +58,28 @@ static GSList* get_supported_image_extensions (void);
 
 EV_BACKEND_REGISTER (ComicsDocument, comics_document)
 
-static char **
+static gboolean
+has_supported_extension (const char *name,
+                        GSList     *supported_extensions)
+{
+       gboolean ret = FALSE;
+       gchar *suffix;
+
+       suffix = g_strrstr (name, ".");
+       if (!suffix)
+               return ret;
+
+       suffix = g_ascii_strdown (suffix + 1, -1);
+       if (g_slist_find_custom (supported_extensions, suffix,
+                                (GCompareFunc) strcmp) != NULL) {
+               ret = TRUE;
+       }
+       g_free (suffix);
+
+       return ret;
+}
+
+static GPtrArray *
 comics_document_list (ComicsDocument  *comics_document,
                      GError         **error)
 {
@@ -239,16 +260,10 @@ comics_document_load (EvDocument *document,
        supported_extensions = get_supported_image_extensions ();
        for (i = 0; cb_files[i] != NULL; i++) {
                cb_file = cb_files[i];
-               gchar *suffix = g_strrstr (cb_file, ".");
-               if (!suffix)
-                       continue;
-               suffix = g_ascii_strdown (suffix + 1, -1);
-               if (g_slist_find_custom (supported_extensions, suffix,
-                                        (GCompareFunc) strcmp) != NULL) {
+               if (has_supported_extension (cb_file, supported_extensions)) {
                         g_ptr_array_add (comics_document->page_names,
                                          g_strdup (cb_file));
                }
-               g_free (suffix);
        }
        g_strfreev (cb_files);
        g_slist_foreach (supported_extensions, (GFunc) g_free, NULL);


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