* reindentation, fix mu_str_ascii_xapian_escape_in_place for '..'

This commit is contained in:
Dirk-Jan C. Binnema 2011-05-22 10:27:12 +03:00
parent 000805ae1f
commit e478eeee6d
2 changed files with 252 additions and 243 deletions

View File

@ -1,5 +1,7 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -348,6 +350,10 @@ mu_str_size_parse_kmg (const char* str)
}
/*
* Xapian treats various characters such as '@', '-', ':' and '.'
* specially; function below is an ugly hack to make it DWIM in most
* cases...*/
char*
mu_str_ascii_xapian_escape_in_place (char *query)
{
@ -361,26 +367,25 @@ mu_str_ascii_xapian_escape_in_place (char *query)
replace_dot = (g_strstr_len(query, -1, "@") != NULL);
for (cur = query; *cur; ++cur) {
*cur = tolower(*cur);
if (*cur == '@' || *cur == '-')
*cur = '_';
else if (*cur == '.') {
/* don't replace a final cur */
if (cur[1] == '.' || cur[1]== ' ' || cur[1]=='\t')
cur += 2;
else if (cur[1] == '\0')
if (cur[1]== ' ' || cur[1]=='\t' || cur[1] == '\0' ||
cur[1]== '.')
++cur;
else
*cur = '_';
} else if (*cur == ':') {
/* if there's a registered xapian prefix before the
* ':', don't touch it. Otherwise replace ':' with
* a space'... ugly...
* a space'... ugh yuck ugly...
*/
if (!is_xapian_prefix (query, cur))
*cur = '_';
} else
*cur = tolower(*cur);
}
}
return query;

View File

@ -1,3 +1,5 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
@ -187,6 +189,8 @@ test_mu_str_ascii_xapian_escape (void)
} words [] = {
{ "aap@noot.mies", "aap_noot_mies"},
{ "Foo..Bar", "foo..bar" },
{ "Foo.Bar", "foo_bar" },
{ "Foo. Bar", "foo. bar" },
{ "subject:test@foo", "subject:test_foo" },
{ "xxx:test@bar", "xxx_test_bar" },
};