Commit e6cbdc21 authored by Sébastien Wilmet's avatar Sébastien Wilmet

Link: simplify dh_link_belongs_to_page()

Always case sensitive. It's a page ID, so the ID needs to be correct.
parent 30075bd6
......@@ -2,7 +2,7 @@
/*
* Copyright (C) 2001-2002 Mikael Hallendal <micke@imendio.com>
* Copyright (C) 2008 Imendio AB
* Copyright (C) 2017 Sébastien Wilmet <swilmet@gnome.org>
* Copyright (C) 2017, 2018 Sébastien Wilmet <swilmet@gnome.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -337,7 +337,6 @@ dh_link_match_relative_url (DhLink *link,
* dh_link_belongs_to_page:
* @link: a #DhLink.
* @page_id: a page ID, i.e. the filename without its extension.
* @case_sensitive: whether @page_id is case sensitive.
*
* This function permits to know if @link belongs to a certain page.
*
......@@ -353,12 +352,10 @@ dh_link_match_relative_url (DhLink *link,
*/
gboolean
dh_link_belongs_to_page (DhLink *link,
const gchar *page_id,
gboolean case_sensitive)
const gchar *page_id)
{
const gchar *relative_url;
gsize page_id_len;
gboolean has_prefix;
g_return_val_if_fail (link != NULL, FALSE);
g_return_val_if_fail (link->relative_url != NULL, FALSE);
......@@ -370,16 +367,9 @@ dh_link_belongs_to_page (DhLink *link,
page_id_len = strlen (page_id);
if (case_sensitive)
has_prefix = strncmp (relative_url, page_id, page_id_len) == 0;
else
has_prefix = g_ascii_strncasecmp (relative_url, page_id, page_id_len) == 0;
/* Check that a file extension follows. */
if (has_prefix)
return relative_url[page_id_len] == '.';
return FALSE;
return (g_str_has_prefix (relative_url, page_id) &&
relative_url[page_id_len] == '.');
}
/**
......
......@@ -2,7 +2,7 @@
/*
* Copyright (C) 2002 Mikael Hallendal <micke@imendio.com>
* Copyright (C) 2008 Imendio AB
* Copyright (C) 2017 Sébastien Wilmet <swilmet@gnome.org>
* Copyright (C) 2017, 2018 Sébastien Wilmet <swilmet@gnome.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -96,8 +96,7 @@ gboolean dh_link_match_relative_url (DhLink *link,
const gchar *relative_url);
gboolean dh_link_belongs_to_page (DhLink *link,
const gchar *page_id,
gboolean case_sensitive);
const gchar *page_id);
gchar * dh_link_get_uri (DhLink *link);
......
......@@ -310,7 +310,7 @@ _dh_search_context_match_link (DhSearchContext *search,
/* Filter by page? */
if (search->page_id != NULL) {
if (!dh_link_belongs_to_page (link, search->page_id, TRUE))
if (!dh_link_belongs_to_page (link, search->page_id))
return FALSE;
if (search->keywords == NULL)
......
......@@ -22,13 +22,10 @@
static void
check_belongs_to_page_book_link (DhLink *book_link)
{
g_assert (dh_link_belongs_to_page (book_link, "index", TRUE));
g_assert (!dh_link_belongs_to_page (book_link, "Index", TRUE));
g_assert (dh_link_belongs_to_page (book_link, "Index", FALSE));
g_assert (!dh_link_belongs_to_page (book_link, "", TRUE));
g_assert (!dh_link_belongs_to_page (book_link, "kiwi", TRUE));
g_assert (!dh_link_belongs_to_page (book_link, "", FALSE));
g_assert (!dh_link_belongs_to_page (book_link, "kiwi", FALSE));
g_assert (dh_link_belongs_to_page (book_link, "index"));
g_assert (!dh_link_belongs_to_page (book_link, "Index"));
g_assert (!dh_link_belongs_to_page (book_link, ""));
g_assert (!dh_link_belongs_to_page (book_link, "kiwi"));
}
static void
......@@ -58,13 +55,10 @@ test_belongs_to_page (void)
"dh_link_ref",
"DhLink.html#dh-link-ref");
g_assert (dh_link_belongs_to_page (link, "DhLink", TRUE));
g_assert (!dh_link_belongs_to_page (link, "dhlink", TRUE));
g_assert (dh_link_belongs_to_page (link, "dhlink", FALSE));
g_assert (!dh_link_belongs_to_page (link, "", TRUE));
g_assert (!dh_link_belongs_to_page (link, "kiwi", TRUE));
g_assert (!dh_link_belongs_to_page (link, "", FALSE));
g_assert (!dh_link_belongs_to_page (link, "kiwi", FALSE));
g_assert (dh_link_belongs_to_page (link, "DhLink"));
g_assert (!dh_link_belongs_to_page (link, "dhlink"));
g_assert (!dh_link_belongs_to_page (link, ""));
g_assert (!dh_link_belongs_to_page (link, "kiwi"));
dh_link_unref (book_link);
dh_link_unref (link);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment