* mu-msg-str.c: improve xapian-escaping, string-eating

This commit is contained in:
djcb
2012-01-21 11:18:29 +02:00
parent e1f598f672
commit 98ca74f9a8

View File

@ -350,14 +350,13 @@ eat_esc_string (char **strlst)
if (*str == '"') { if (*str == '"') {
quoted = !quoted; quoted = !quoted;
continue; continue;
} else if (quoted) } else if (*str == '\\') {
gstr = g_string_append_c (gstr, *str);
else if (*str == '\\') {
if (str[1] != ' ' && str[1] != '"' && str[1] != '\\') if (str[1] != ' ' && str[1] != '"' && str[1] != '\\')
goto err; /* invalid escaping */ goto err; /* invalid escaping */
g_string_append_c (gstr, *(str++)); g_string_append_c (gstr, str[1]);
++str;
continue; continue;
} else if (*str == ' ') { } else if (*str == ' ' && !quoted) {
++str; ++str;
goto leave; goto leave;
} else } else
@ -445,29 +444,25 @@ mu_str_ascii_xapian_escape_in_place (char *query, gboolean esc_space)
switch (*cur) { switch (*cur) {
case ' ': case ' ':
if (!esc_space)
break;
case '@': case '@':
case '-': case '-':
case ';':
case '/': case '/':
case '.': *cur = escchar;
{ break;
/* don't replace a final special char */ case '.': /* don't escape '..' */
if (cur[1]== ' ' || cur[1]=='\t' || cur[1]== '.') if (cur[1]=='.')
++cur; cur += 1;
else if (cur[1] == '\0')
break;
else else
*cur = escchar; *cur = escchar;
break; break;
}
case ':': case ':':
/* if there's a registered xapian prefix before the /* if there's a registered xapian prefix before the
* ':', don't touch it. Otherwise replace ':' with * ':', don't touch it. Otherwise replace ':' with
* a space'... ugh yuck ugly... * a _'... ugh yuck ugly...
*/ */
if (!is_xapian_prefix (query, cur)) if (!is_xapian_prefix (query, cur))
*cur = ' '; *cur = escchar;
break; break;
} }
} }