summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2014-03-19 10:17:58 +0100
committerStefano Karapetsas <[email protected]>2014-03-19 10:17:58 +0100
commitec3b83d34ffeaf2c0d16ba013fcba64f17fab203 (patch)
tree0d4a000d647207cf3804e28c536bfc2cae905bde /backend
parent6db1758b9cad94ab491170e722ddbca6d07a672c (diff)
downloadatril-ec3b83d34ffeaf2c0d16ba013fcba64f17fab203.tar.bz2
atril-ec3b83d34ffeaf2c0d16ba013fcba64f17fab203.tar.xz
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
Diffstat (limited to 'backend')
-rw-r--r--backend/djvu/djvu-document.c2
-rw-r--r--backend/djvu/djvu-text-page.c15
-rw-r--r--backend/djvu/djvu-text-page.h3
3 files changed, 16 insertions, 4 deletions
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);