From 1e23dc1c811a619678c6b2f8876a8c30066b7654 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 11 Feb 2004 15:21:18 +0000 Subject: Better keyword matching function. Should match only words (not middle 2004-02-11 Marco Pesenti Gritti * lib/widgets/ephy-location-entry.c: (keyword_match), (completion_func): Better keyword matching function. Should match only words (not middle parts of them) and maybe be a bit faster. --- lib/widgets/ephy-location-entry.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'lib/widgets/ephy-location-entry.c') diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c index 36b1b4d8c..cee04febb 100644 --- a/lib/widgets/ephy-location-entry.c +++ b/lib/widgets/ephy-location-entry.c @@ -192,6 +192,41 @@ entry_button_press_cb (GtkWidget *entry, GdkEventButton *event, EphyLocationEntr return FALSE; } +static gboolean +keyword_match (const char *list, + const char *keyword) +{ + const char *p; + gsize keyword_len; + + p = list; + keyword_len = strlen (keyword); + + while (*p) + { + int i; + + for (i = 0; i < keyword_len; i++) + { + if (p[i] == ' ') + goto next_char; + + if (p[i] != keyword[i]) + goto next_token; + } + + return TRUE; + + next_token: + while (*p != ' ') p++; + + next_char: + if (*p) p++; + } + + return FALSE; +} + static gboolean completion_func (GtkEntryCompletion *completion, const char *key, @@ -216,7 +251,7 @@ completion_func (GtkEntryCompletion *completion, { ret = TRUE; } - else if (strstr (keywords, key)) + else if (keyword_match (keywords, key)) { ret = TRUE; } -- cgit v1.2.3