summaryrefslogtreecommitdiff
path: root/nncmpp.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-12-21 05:37:42 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-12-21 05:46:22 +0100
commit48482ef2e53b5eaae9a47e8ade9e3940bc01f48d (patch)
tree58fc789d1a5bd2e7156ff0642a3297dddd82086f /nncmpp.c
parent840c69767c6eea61e69343546ecdadae70b9afad (diff)
downloadnncmpp-48482ef2e53b5eaae9a47e8ade9e3940bc01f48d.tar.gz
nncmpp-48482ef2e53b5eaae9a47e8ade9e3940bc01f48d.tar.xz
nncmpp-48482ef2e53b5eaae9a47e8ade9e3940bc01f48d.zip
Make incremental search more useful
Make it unanchored, as well as case-insensitive.
Diffstat (limited to 'nncmpp.c')
-rw-r--r--nncmpp.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/nncmpp.c b/nncmpp.c
index fb49b3a..e148c2d 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -2350,12 +2350,17 @@ static size_t
incremental_search_match (const ucs4_t *needle, size_t len,
const struct row_buffer *row)
{
- // TODO: case-insensitive search, wilcards, regexps, something easy to use
- size_t i = 0;
- for (; i < len && i < row->chars_len; i++)
- if (needle[i] != row->chars[i].c)
- break;
- return i;
+ // XXX: this is slow and simplistic, but unistring is awkward to use
+ size_t best = 0;
+ for (size_t start = 0; start < row->chars_len; start++)
+ {
+ size_t i = 0;
+ for (; i < len && start + i < row->chars_len; i++)
+ if (uc_tolower(needle[i]) != uc_tolower(row->chars[start + i].c))
+ break;
+ best = MAX (best, i);
+ }
+ return best;
}
static void