[libgepub/wip/cosimoc/fixes: 4/8] doc: make API to get resources consistent



commit 6a46910f9013ef8cc8c3b696468c2cb0d4a852d1
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Jun 12 15:19:41 2016 -0700

    doc: make API to get resources consistent
    
    Right now there are _by_id() variants for certain methods, but the id is
    used by default for others. Make it consistent by always having the
    unsuffixed methods take a path.

 libgepub/gepub-doc.c |   22 +++++++++++-----------
 libgepub/gepub-doc.h |    6 +++---
 tests/test-gepub.c   |    2 +-
 3 files changed, 15 insertions(+), 15 deletions(-)
---
diff --git a/libgepub/gepub-doc.c b/libgepub/gepub-doc.c
index a71f165..b38ff5a 100644
--- a/libgepub/gepub-doc.c
+++ b/libgepub/gepub-doc.c
@@ -333,7 +333,7 @@ gepub_doc_get_resources (GepubDoc *doc)
 }
 
 /**
- * gepub_doc_get_resource:
+ * gepub_doc_get_resource_by_id:
  * @doc: a #GepubDoc
  * @id: the resource id
  * @bufsize: (out): location to store the length in bytes of the contents
@@ -341,7 +341,7 @@ gepub_doc_get_resources (GepubDoc *doc)
  * Returns: (array length=bufsize) (transfer full): the resource content
  */
 guchar *
-gepub_doc_get_resource (GepubDoc *doc, gchar *id, gsize *bufsize)
+gepub_doc_get_resource_by_id (GepubDoc *doc, gchar *id, gsize *bufsize)
 {
     guchar *res = NULL;
     GepubResource *gres = g_hash_table_lookup (doc->resources, id);
@@ -356,19 +356,19 @@ gepub_doc_get_resource (GepubDoc *doc, gchar *id, gsize *bufsize)
 }
 
 /**
- * gepub_doc_get_resource_v:
+ * gepub_doc_get_resource:
  * @doc: a #GepubDoc
- * @v: the resource path
+ * @path: the resource path
  * @bufsize: (out): location to store length in bytes of the contents
  *
  * Returns: (array length=bufsize) (transfer full): the resource content
  */
 guchar *
-gepub_doc_get_resource_v (GepubDoc *doc, gchar *v, gsize *bufsize)
+gepub_doc_get_resource (GepubDoc *doc, gchar *path, gsize *bufsize)
 {
     guchar *res = NULL;
 
-    if (!gepub_archive_read_entry (doc->archive, v, &res, bufsize)) {
+    if (!gepub_archive_read_entry (doc->archive, path, &res, bufsize)) {
         return NULL;
     }
 
@@ -401,19 +401,19 @@ gepub_doc_get_resource_mime_by_id (GepubDoc *doc, gchar *id)
 /**
  * gepub_doc_get_resource_mime:
  * @doc: a #GepubDoc
- * @v: the resource path
+ * @path: the resource path
  *
  * Returns: (transfer full): the resource mime
  */
 gchar *
-gepub_doc_get_resource_mime (GepubDoc *doc, gchar *v)
+gepub_doc_get_resource_mime (GepubDoc *doc, gchar *path)
 {
     GepubResource *gres;
     GList *keys = g_hash_table_get_keys (doc->resources);
 
     while (keys) {
         gres = ((GepubResource*)g_hash_table_lookup (doc->resources, keys->data));
-        if (!strcmp (gres->uri, v))
+        if (!strcmp (gres->uri, path))
             break;
         keys = keys->next;
     }
@@ -458,7 +458,7 @@ gepub_doc_get_spine (GepubDoc *doc)
 guchar *
 gepub_doc_get_current (GepubDoc *doc, gsize *bufsize)
 {
-    return gepub_doc_get_resource (doc, doc->spine->data, bufsize);
+    return gepub_doc_get_resource_by_id (doc, doc->spine->data, bufsize);
 }
 
 /**
@@ -534,7 +534,7 @@ gepub_doc_get_text_by_id (GepubDoc *doc, gchar *id)
 
     GList *texts = NULL;
 
-    res = gepub_doc_get_resource (doc, id, &size);
+    res = gepub_doc_get_resource_by_id (doc, id, &size);
     if (!res) {
         return NULL;
     }
diff --git a/libgepub/gepub-doc.h b/libgepub/gepub-doc.h
index cb03101..9de28fa 100644
--- a/libgepub/gepub-doc.h
+++ b/libgepub/gepub-doc.h
@@ -47,10 +47,10 @@ GType             gepub_doc_get_type                        (void) G_GNUC_CONST;
 GepubDoc         *gepub_doc_new                             (const gchar *path);
 gchar            *gepub_doc_get_content                     (GepubDoc *doc);
 gchar            *gepub_doc_get_metadata                    (GepubDoc *doc, gchar *mdata);
-guchar           *gepub_doc_get_resource                    (GepubDoc *doc, gchar *id, gsize *bufsize);
-guchar           *gepub_doc_get_resource_v                  (GepubDoc *doc, gchar *v, gsize *bufsize);
+guchar           *gepub_doc_get_resource                    (GepubDoc *doc, gchar *path, gsize *bufsize);
+guchar           *gepub_doc_get_resource_by_id              (GepubDoc *doc, gchar *id, gsize *bufsize);
 GHashTable       *gepub_doc_get_resources                   (GepubDoc *doc);
-gchar            *gepub_doc_get_resource_mime               (GepubDoc *doc, gchar *v);
+gchar            *gepub_doc_get_resource_mime               (GepubDoc *doc, gchar *path);
 gchar            *gepub_doc_get_resource_mime_by_id         (GepubDoc *doc, gchar *id);
 gchar            *gepub_doc_get_current_mime                (GepubDoc *doc);
 GList            *gepub_doc_get_spine                       (GepubDoc *doc);
diff --git a/tests/test-gepub.c b/tests/test-gepub.c
index 55c4bee..b07a4c5 100644
--- a/tests/test-gepub.c
+++ b/tests/test-gepub.c
@@ -199,7 +199,7 @@ test_doc_resources (const char *path)
     guchar *ncx;
     gsize size;
 
-    ncx = gepub_doc_get_resource (doc, "ncx", &size);
+    ncx = gepub_doc_get_resource_by_id (doc, "ncx", &size);
     PTEST ("ncx:\n%s\n", ncx);
     g_free (ncx);
 


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