[devhelp] DhLink: add match_relative_url()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] DhLink: add match_relative_url()
- Date: Wed, 6 Dec 2017 12:58:39 +0000 (UTC)
commit 4c9092ddd2ead7063cc022a32dca71b755a59895
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Dec 6 13:24:50 2017 +0100
DhLink: add match_relative_url()
dh_link_get_file_name() returns the empty string for the book top-level
link. find_equivalent_local_uri() in dh-window.c calls g_strcmp0() on
the string returned by dh_link_get_file_name(), to see if the relative
URL matches.
So currently find_equivalent_local_uri() will find an equivalent for:
https://developer.gnome.org/glib/unstable/
but not for:
https://developer.gnome.org/glib/unstable/index.html
With dh_link_match_relative_url(), it will find an equivalent for both.
docs/reference/devhelp-sections.txt | 1 +
src/dh-link.c | 39 +++++++++++++++++++++++++++++++++++
src/dh-link.h | 3 ++
3 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index 4b7203c..15f1bdf 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -117,6 +117,7 @@ dh_link_get_flags
dh_link_set_flags
dh_link_get_name
dh_link_get_file_name
+dh_link_match_relative_url
dh_link_get_uri
dh_link_get_book_name
dh_link_get_book_id
diff --git a/src/dh-link.c b/src/dh-link.c
index 30e2808..b1710b4 100644
--- a/src/dh-link.c
+++ b/src/dh-link.c
@@ -265,6 +265,45 @@ dh_link_get_file_name (DhLink *link)
}
/**
+ * dh_link_match_relative_url:
+ * @link: a #DhLink.
+ * @relative_url: an URL relative to the book base path. Can contain an anchor.
+ *
+ * Returns: whether the relative URL of @link matches with @relative_url. There
+ * is a special case for the index.html page, it can also match the empty
+ * string.
+ * Since: 3.28
+ */
+gboolean
+dh_link_match_relative_url (DhLink *link,
+ const gchar *relative_url)
+{
+ g_return_val_if_fail (link != NULL, FALSE);
+ g_return_val_if_fail (link->relative_url != NULL, FALSE);
+ g_return_val_if_fail (relative_url != NULL, FALSE);
+
+ if (g_str_equal (link->relative_url, relative_url))
+ return TRUE;
+
+ /* Special case for index.html, can also match the empty string.
+ * Example of full URLs:
+ * file:///usr/share/gtk-doc/html/glib/
+ * file:///usr/share/gtk-doc/html/glib/index.html
+ *
+ * This supports only the root index.html page of a DhBook, this doesn't
+ * support index.html inside a sub-directory, if the relative_url
+ * contains a sub-directory. But apparently GTK-Doc doesn't create
+ * sub-directories, all the *.html pages are in the same directory.
+ */
+ if (relative_url[0] == '\0')
+ return g_str_equal (link->relative_url, "index.html");
+ else if (link->relative_url[0] == '\0')
+ return g_str_equal (relative_url, "index.html");
+
+ return FALSE;
+}
+
+/**
* dh_link_get_uri:
* @link: a #DhLink.
*
diff --git a/src/dh-link.h b/src/dh-link.h
index dddb83d..51093a0 100644
--- a/src/dh-link.h
+++ b/src/dh-link.h
@@ -93,6 +93,9 @@ const gchar *dh_link_get_name (DhLink *link);
const gchar *dh_link_get_file_name (DhLink *link);
+gboolean dh_link_match_relative_url (DhLink *link,
+ const gchar *relative_url);
+
gchar * dh_link_get_uri (DhLink *link);
const gchar *dh_link_get_book_name (DhLink *link);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]