GNOME Bugzilla – Bug 61852
GtkTextBuffer needs a case insensitive search
Last modified: 2010-11-01 14:47:58 UTC
Here is a patch to gtk_text_iter_[forward/backward]_search with an extra boolean flag (is_case_sensitive). This is until we have a better solution.
Created attachment 5769 [details] [review] gtktextiter case sensitive search patch
The case insensitive search is really hard to make i18n-correct, so punting from 2.0. However, I'm changing forward/backward search to take a "flags" field instead of the current visible_only/slice boolean args; we can add a GTK_TEXT_SEARCH_CASE_INSENSITIVE flag in a future version, as well as GTK_TEXT_SEARCH_REGEXP.
Look at http://www.unicode.org/unicode/reports/tr21/ I think that writing a function to perform "caseless matching" should be not so difficult since we already have g_utf8_casefold (...) Please, reconsider it for inclusion in 2.0, we need it in gedit.
Implementing search yourself shouldn't be too difficult. There's nothing magic about how it's done in gtktextiter.c.
I have an experimental implementation for it in gedit (you can find it in gedit-utils.c) It works quite well even if it has 1 or 2 little problems.
This has been implemented in gtksourceview.
Paolo: should we just close this then?
I'd really love to have this available in GtkTextBuffer itself, please don't close this only because gtksourceview has this functionality.
As discussed in the 20100907 meeting, the code from gtksourceview should be merged in GTK+
I'm working on this.
Created attachment 173286 [details] [review] case insensitive v1 This patch has been reviewed by pbor.
It would be awesome to have some testcases for this stuff, either in the existing gtk/tests/textbuffer.c, or as a new gtk/tests/textiter.c.
Created attachment 173591 [details] [review] unit test Here is a unit test for text iter search. I actually exposes a bug in the current backward search. The next patch in the series will fix the bug. Later nacho will upload an updated version of his patch that adds caseless testcases to the unit test
Created attachment 173592 [details] [review] patch Fixes bug exposed by the unit test
Created attachment 173598 [details] [review] case insensitive v2 minor fix
Created attachment 173599 [details] [review] case insensitive tests v1 and the unit tests
Review of attachment 173598 [details] [review]: Ok, thanks for the tests, lets commit this now.
Review of attachment 173599 [details] [review]: Would be great to have some more tests around the more finicky parts of the tests, e.g decomposed forms, or maybe some Unicode chars with more unusual casedness (e.g. titlecase, etc). But this is a good start, thanks.
Pushed the patch set. Great to see a 10 year old bug die :) The current tests already check decomposed forms of accented letters etc, we can add more test cases, but I will need some suggestions (italian mostly uses utf8 for accented letters).. for instance I tried to add a test with Ӕ but it turns out it should not match "ae"