tmus

TUI Music Player
git clone https://git.sinitax.com/sinitax/tmus
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

commit 5d62ca335a60f9e762fd4f63f7c0258157328c0b
parent fa2f322580bba3ff71053c895f658ecb4116a456
Author: Louis Burda <quent.burda@gmail.com>
Date:   Mon, 14 Feb 2022 14:48:33 +0100

Use case insensitive search

Diffstat:
Msrc/history.c | 4++--
Msrc/tui.c | 8++++----
Msrc/util.c | 16++++++++++++++++
Msrc/util.h | 2++
4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/history.c b/src/history.c @@ -55,7 +55,7 @@ history_list_prev(struct inputln *cur, const wchar_t *search) for (iter = cur->link.prev; iter && iter->prev; iter = iter->prev) { ln = UPCAST(iter, struct inputln); - if (!search || !*search || wcsstr(ln->buf, search)) + if (!search || !*search || wcscasestr(ln->buf, search)) return ln; } @@ -71,7 +71,7 @@ history_list_next(struct inputln *cur, const wchar_t *search) iter = cur->link.next; while (LIST_INNER(iter)) { ln = UPCAST(iter, struct inputln); - if (!search || !*search || wcsstr(ln->buf, search)) + if (!search || !*search || wcscasestr(ln->buf, search)) return ln; iter = iter->next; } diff --git a/src/tui.c b/src/tui.c @@ -159,7 +159,7 @@ track_name_gen(const wchar_t *text, int fwd, int reset) while (LIST_INNER(iter)) { track = UPCAST(iter, struct ref)->data; - if (wcsstr(track->name, text)) { + if (wcscasestr(track->name, text)) { cur = iter; return wcsdup(track->name); } @@ -185,7 +185,7 @@ tag_name_gen(const wchar_t *text, int fwd, int reset) while (LIST_INNER(iter)) { tag = UPCAST(iter, struct tag); - if (wcsstr(tag->name, text)) { + if (wcscasestr(tag->name, text)) { cur = iter; return wcsdup(tag->name); } @@ -412,7 +412,7 @@ play_track(const wchar_t *query) for (LIST_ITER(&tracks, iter)) { track = UPCAST(iter, struct ref)->data; - if (wcsstr(track->name, query)) { + if (!wcscmp(track->name, query)) { player_play_track(track); return 1; } @@ -432,7 +432,7 @@ select_tag(const wchar_t *query) for (LIST_ITER(&tags, iter)) { index += 1; tag = UPCAST(iter, struct tag); - if (wcsstr(tag->name, query)) { + if (wcscasestr(tag->name, query)) { listnav_update_sel(&tag_nav, index); return 1; } diff --git a/src/util.c b/src/util.c @@ -1,4 +1,5 @@ #define _XOPEN_SOURCE 600 +#define _GNU_SOURCE #include "util.h" #include "tui.h" @@ -40,6 +41,21 @@ done: return width; } +const wchar_t * +wcscasestr(const wchar_t *haystack, const wchar_t *needle) +{ + int hslen, nlen, i; + + nlen = wcslen(needle); + hslen = wcslen(haystack) - nlen; + for (i = 0; i < hslen; i++) { + if (!wcsncasecmp(haystack + i, needle, nlen)) + return haystack + i; + } + + return NULL; +} + void panic(const char *file, int line, const char *msg, ...) { diff --git a/src/util.h b/src/util.h @@ -17,6 +17,8 @@ int strnwidth(const char *s, int n); +const wchar_t *wcscasestr(const wchar_t *haystack, const wchar_t *needle); + void panic(const char *file, int line, const char *msg, ...); void assert(int cond, const char *file, int line, const char *condstr); void error(const char *fmtstr, ...);