diff options
author | Stefano Karapetsas <[email protected]> | 2014-03-19 10:17:58 +0100 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2014-03-19 10:17:58 +0100 |
commit | ec3b83d34ffeaf2c0d16ba013fcba64f17fab203 (patch) | |
tree | 0d4a000d647207cf3804e28c536bfc2cae905bde /backend/djvu/djvu-text-page.c | |
parent | 6db1758b9cad94ab491170e722ddbca6d07a672c (diff) | |
download | atril-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/djvu/djvu-text-page.c')
-rw-r--r-- | backend/djvu/djvu-text-page.c | 15 |
1 files changed, 13 insertions, 2 deletions
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); } |