aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-search-private.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-09-20 13:30:27 +0800
committerMichael Zucci <zucchi@src.gnome.org>2002-09-20 13:30:27 +0800
commit4c66cbd9f159141dc99b162f7f93018e71d214e0 (patch)
tree54379594b770b8a0230718285aae7be534beb041 /camel/camel-search-private.c
parent71d8e11c459129aeb1543afac5e2b8cb36a482a8 (diff)
downloadgsoc2013-evolution-4c66cbd9f159141dc99b162f7f93018e71d214e0.tar
gsoc2013-evolution-4c66cbd9f159141dc99b162f7f93018e71d214e0.tar.gz
gsoc2013-evolution-4c66cbd9f159141dc99b162f7f93018e71d214e0.tar.bz2
gsoc2013-evolution-4c66cbd9f159141dc99b162f7f93018e71d214e0.tar.lz
gsoc2013-evolution-4c66cbd9f159141dc99b162f7f93018e71d214e0.tar.xz
gsoc2013-evolution-4c66cbd9f159141dc99b162f7f93018e71d214e0.tar.zst
gsoc2013-evolution-4c66cbd9f159141dc99b162f7f93018e71d214e0.zip
New regression test for word splitting/search input parsing code.
2002-09-20 Not Zed <NotZed@Ximian.com> * tests/misc/split.c: New regression test for word splitting/search input parsing code. * tests/folder/test9.c (main): Fix for filter_driver api change. * camel-search-private.c (camel_search_words_split): Handle "'s and \'s to escape characters. For fat, lazy, slobs who dont like anything changing. svn path=/trunk/; revision=18130
Diffstat (limited to 'camel/camel-search-private.c')
-rw-r--r--camel/camel-search-private.c79
1 files changed, 56 insertions, 23 deletions
diff --git a/camel/camel-search-private.c b/camel/camel-search-private.c
index 5adf2b146f..7202254294 100644
--- a/camel/camel-search-private.c
+++ b/camel/camel-search-private.c
@@ -531,44 +531,77 @@ loop:
return v;
}
+static void
+output_c(GString *w, guint32 c, int *type)
+{
+ int utf8len;
+ char utf8[8];
+
+ if (!g_unichar_isalnum(c))
+ *type = CAMEL_SEARCH_WORD_COMPLEX | (*type & CAMEL_SEARCH_WORD_8BIT);
+ else
+ c = g_unichar_tolower(c);
+
+ if (c > 0x80)
+ *type |= CAMEL_SEARCH_WORD_8BIT;
+
+ /* FIXME: use camel_utf8_putc */
+ utf8len = g_unichar_to_utf8(c, utf8);
+ utf8[utf8len] = 0;
+ g_string_append(w, utf8);
+}
+
+static void
+output_w(GString *w, GPtrArray *list, int type)
+{
+ struct _camel_search_word *word;
+
+ if (w->len) {
+ word = g_malloc0(sizeof(*word));
+ word->word = g_strdup(w->str);
+ word->type = type;
+ g_ptr_array_add(list, word);
+ g_string_truncate(w, 0);
+ }
+}
+
struct _camel_search_words *
camel_search_words_split(const unsigned char *in)
{
int type = CAMEL_SEARCH_WORD_SIMPLE, all = 0;
GString *w;
- struct _camel_search_word *word;
struct _camel_search_words *words;
GPtrArray *list = g_ptr_array_new();
guint32 c;
- int utf8len;
- char utf8[8];
+ int inquote = 0;
words = g_malloc0(sizeof(*words));
w = g_string_new("");
do {
c = camel_utf8_getc(&in);
- if (c == 0 || g_unichar_isspace(c)) {
- if (w->len) {
- word = g_malloc0(sizeof(*word));
- word->word = g_strdup(w->str);
- word->type = type;
- g_ptr_array_add(list, word);
- all |= type;
- type = CAMEL_SEARCH_WORD_SIMPLE;
- g_string_truncate(w, 0);
- }
+
+ if (c == 0
+ || (inquote && c == '"')
+ || (!inquote && g_unichar_isspace(c))) {
+ output_w(w, list, type);
+ all |= type;
+ type = CAMEL_SEARCH_WORD_SIMPLE;
+ inquote = 0;
} else {
- if (!g_unichar_isalnum(c))
- type = CAMEL_SEARCH_WORD_COMPLEX;
- else
- c = g_unichar_tolower(c);
- if (c > 0x80)
- type |= CAMEL_SEARCH_WORD_8BIT;
-
- utf8len = g_unichar_to_utf8(c, utf8);
- utf8[utf8len] = 0;
- g_string_append(w, utf8);
+ if (c == '\\') {
+ c = camel_utf8_getc(&in);
+ if (c)
+ output_c(w, c, &type);
+ else {
+ output_w(w, list, type);
+ all |= type;
+ }
+ } else if (c == '\"') {
+ inquote = 1;
+ } else {
+ output_c(w, c, &type);
+ }
}
} while (c);