summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--search.c5
-rw-r--r--utf8.c72
-rw-r--r--utf8.h3
3 files changed, 79 insertions, 1 deletions
diff --git a/search.c b/search.c
index f82db024..a1bf4665 100644
--- a/search.c
+++ b/search.c
@@ -35,6 +35,8 @@
#include "messagepump.h"
#include "messages.h"
+#include "utf8.h"
+
extern GtkWidget *searchwin;
struct playItem_s *search_current = NULL;
int search_count = 0;
@@ -65,7 +67,8 @@ on_searchentry_changed (GtkEditable *editable,
if (*text) {
for (playItem_t *it = playlist_head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
for (metaInfo_t *m = it->meta; m; m = m->next) {
- if (strcasestr (m->value, text)) {
+// if (strcasestr (m->value, text)) {
+ if (utfcasestr (m->value, text)) {
// add to list
it->next[PL_SEARCH] = NULL;
if (playlist_tail[PL_SEARCH]) {
diff --git a/utf8.c b/utf8.c
index 06a9e3bb..6c9ada11 100644
--- a/utf8.c
+++ b/utf8.c
@@ -18,6 +18,7 @@
#include <string.h>
#include <stdarg.h>
#include <alloca.h>
+#include "ctype.h"
#include "utf8.h"
static const uint32_t offsetsFromUTF8[6] = {
@@ -592,3 +593,74 @@ int u8_valid (const char *str,
return 1;
}
+static const char lowerchars[] = "záéíñóúüäöåæøàçèéêабвгдеёжзийклмнорпстуфхцчшщъыьэюя";
+static const char upperchars[] = "ZÁÉÍÑÓÚÜÄÖÅÆØÀÇÈÉÊАБВГДЕЁЖЗИЙКЛМНОРПСТУФХЦЧШЩЪЫЬЭЮЯ";
+
+int
+u8_tolower (const signed char *c, int l, char *out) {
+ if (*c > 0) {
+ *out = tolower (*c);
+ out[1] = 0;
+ return 1;
+ }
+ else {
+ for (int i = 0; i < sizeof (upperchars)-l; i++) {
+ if (!memcmp (upperchars+i, c, l)) {
+ // found!
+ memcpy (out, lowerchars+i, l);
+ out[l] = 0;
+ return l;
+ }
+ }
+ memcpy (out, c, l);
+ out[l] = 0;
+ return l;
+ }
+}
+
+const char *
+utfcasestr (const char *s1, const char *s2) {
+#if 0 // small u8_tolower test
+ while (*s2) {
+ int32_t i = 0;
+ u8_nextchar (s2, &i);
+ const char *next = s2 + i;
+ char lw[10];
+ int l = u8_tolower (s2, next-s2, lw);
+ s2 = next;
+ fprintf (stderr, "%s", lw);
+ }
+ fprintf (stderr, "\n");
+ return NULL;
+#endif
+ while (*s1) {
+ const char *p1 = s1;
+ const char *p2 = s2;
+ while (*p2 && *p1) {
+ int32_t i1 = 0;
+ int32_t i2 = 0;
+ char lw1[10];
+ char lw2[10];
+ const char *next;
+ u8_nextchar (p1, &i1);
+ u8_nextchar (p2, &i2);
+ int l1 = u8_tolower (p1, i1, lw1);
+ int l2 = u8_tolower (p2, i2, lw2);
+ //fprintf (stderr, "comparing %s to %s\n", lw1, lw2);
+ if (strcmp (lw1, lw2)) {
+ //fprintf (stderr, "fail\n");
+ break;
+ }
+ p1 += i1;
+ p2 += i2;
+ }
+ if (*p2 == 0) {
+ //fprintf (stderr, "%s found in %s\n", s2, s1);
+ return p1;
+ }
+ int32_t i = 0;
+ u8_nextchar (s1, &i);
+ s1 += i;
+ }
+ return NULL;
+}
diff --git a/utf8.h b/utf8.h
index 7796a903..76ed4400 100644
--- a/utf8.h
+++ b/utf8.h
@@ -88,3 +88,6 @@ int u8_printf(char *fmt, ...);
int u8_valid (const char *str,
int max_len,
const char **end);
+
+const char *
+utfcasestr (const char *s1, const char *s2);