summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2236f0c)
raw | patch | inline | side by side (parent: 2236f0c)
author | Matt Portas <m.portas20@googlemail.com> | |
Mon, 16 Mar 2009 16:13:33 +0000 (17:13 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 16 Mar 2009 18:14:15 +0000 (19:14 +0100) |
This patch extends the jump function. Current jump only searches the
start of the lines, but with this patch it searches through the whole
line for a match. Since this takes more cpu power, I have inlined it
back to the original behavior in MINI.
start of the lines, but with this patch it searches through the whole
line for a match. Since this takes more cpu power, I have inlined it
back to the original behavior in MINI.
src/list_window.c | patch | blob | history | |
src/match.c | patch | blob | history | |
src/match.h | patch | blob | history |
diff --git a/src/list_window.c b/src/list_window.c
index 40fd179c7bd35bad60624a7b1251e1efbc2bf7f3..fedae31d2291373699497b80b553b2042408eb47 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
while ((label = callback(i,&h,callback_data))) {
if (label && label[0] != '[')
{
- if (str && label && g_ascii_strncasecmp(label, str, strlen(str)) == 0) {
+ if (str && label && find_occurence(label, str, strlen(str)) == 0) {
lw->selected = i;
if(!lw->visual_selection || i > lw->selected_end)
lw->selected_end = i;
return true;
}
}
- else if (str && label && g_ascii_strncasecmp(label+1, str, strlen(str)) == 0) {
+ else if (str && label && find_occurence(label+1, str, strlen(str)) == 0) {
lw->selected = i;
if(!lw->visual_selection || i > lw->selected_end)
lw->selected_end = i;
diff --git a/src/match.c b/src/match.c
index c97cde5109483639f8d04f123a393b2bf9146e8a..313c76e686dde0c563c71b0ad762b6980027d2fc 100644 (file)
--- a/src/match.c
+++ b/src/match.c
#include <glib.h>
#include <string.h>
+#include <ctype.h>
static char *
locale_casefold(const char *src)
return ret;
}
+
+int
+find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len)
+{
+ const int str_orig_len = strlen (str_orig);
+ int i, j;
+
+ if (str_occur_len > str_orig_len)
+ return -1;
+
+ for (i = 0; i < str_orig_len; i++) {
+ if ((i + str_occur_len) > str_orig_len)
+ return -1;
+
+ for (j = 0; j < str_occur_len; j++) {
+ if (tolower (str_occur[j]) != tolower (str_orig[i+j]))
+ break;
+
+ if (j == str_occur_len - 1)
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
diff --git a/src/match.h b/src/match.h
index d42f14df605796bcde7e74a10cba740e9f581978..4362cce8a22769c5489156a20310f7ff35e362d3 100644 (file)
--- a/src/match.h
+++ b/src/match.h
return strstr(line, needle) != NULL;
}
+static inline int
+find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len)
+{
+ return g_ascii_strncasecmp(str_orig, str_occur, str_occur_len);
+}
+
#else
/**
bool
match_line(const char *line, const char *needle);
+int
+find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len);
+
#endif
#endif