From ec3b83d34ffeaf2c0d16ba013fcba64f17fab203 Mon Sep 17 00:00:00 2001 From: Stefano Karapetsas Date: Wed, 19 Mar 2014 10:17:58 +0100 Subject: djvu: Fix case sensitive search Closes https://github.com/mate-desktop/atril/issues/41 Closes https://github.com/mate-desktop/atril/pull/74 This commit is based on Aleksi Blinnikka one from #74 --- backend/djvu/djvu-document.c | 2 +- backend/djvu/djvu-text-page.c | 15 +++++++++++++-- backend/djvu/djvu-text-page.h | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'backend/djvu') diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c index 814503c1..bddcef51 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -654,7 +654,7 @@ djvu_document_find_find_text (EvDocumentFind *document, djvu_text_page_prepare_search (tpage, case_sensitive); if (tpage->links->len > 0) { - djvu_text_page_search (tpage, text); + djvu_text_page_search (tpage, text, case_sensitive); matches = tpage->results; } djvu_text_page_free (tpage); diff --git a/backend/djvu/djvu-text-page.c b/backend/djvu/djvu-text-page.c index 3f171d1e..d74a3983 100644 --- a/backend/djvu/djvu-text-page.c +++ b/backend/djvu/djvu-text-page.c @@ -365,22 +365,31 @@ djvu_text_page_append_text (DjvuTextPage *page, * djvu_text_page_search: * @page: #DjvuTextPage instance * @text: text to search + * @case_sensitive: do not ignore case * * Searches the page for the given text. The results list has to be * externally freed afterwards. */ void djvu_text_page_search (DjvuTextPage *page, - const char *text) + const char *text, + gboolean case_sensitive) { char *haystack = page->text; + char *search_text; int search_len; EvRectangle *result; if (page->links->len == 0) return; search_len = strlen (text); - while ((haystack = strstr (haystack, text)) != NULL) { + + if (case_sensitive) + search_text = g_strdup (text); + else + search_text = g_utf8_casefold (text, search_len); + + while ((haystack = strstr (haystack, search_text)) != NULL) { int start_p = haystack - page->text; miniexp_t start = djvu_text_page_position (page, start_p); int end_p = start_p + search_len - 1; @@ -391,6 +400,8 @@ djvu_text_page_search (DjvuTextPage *page, haystack = haystack + search_len; } page->results = g_list_reverse (page->results); + + g_free (search_text); } diff --git a/backend/djvu/djvu-text-page.h b/backend/djvu/djvu-text-page.h index 6e16f259..5ee85a3e 100644 --- a/backend/djvu/djvu-text-page.h +++ b/backend/djvu/djvu-text-page.h @@ -51,7 +51,8 @@ char * djvu_text_page_copy (DjvuTextPage *page, void djvu_text_page_prepare_search (DjvuTextPage *page, gboolean case_sensitive); void djvu_text_page_search (DjvuTextPage *page, - const char *text); + const char *text, + gboolean case_sensitive); DjvuTextPage* djvu_text_page_new (miniexp_t text); void djvu_text_page_free (DjvuTextPage *page); -- cgit v1.2.1