mirror of https://github.com/djcb/mu.git
* use the new strip option for list->str
This commit is contained in:
parent
86d7968bc2
commit
0ec6df6369
|
@ -92,7 +92,7 @@ mu_msg_doc_get_str_list_field (MuMsgDoc *self, MuMsgFieldId mfid,
|
|||
try {
|
||||
/* return a comma-separated string as a GSList */
|
||||
const std::string s (self->doc().get_value(mfid));
|
||||
return s.empty() ? NULL : mu_str_to_list(s.c_str(),',');
|
||||
return s.empty() ? NULL : mu_str_to_list(s.c_str(),',',TRUE);
|
||||
|
||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(NULL);
|
||||
}
|
||||
|
|
|
@ -394,9 +394,26 @@ add_terms_values_string_list (Xapian::Document& doc, MuMsg *msg,
|
|||
|
||||
if (lst && mu_msg_field_xapian_term (mfid)) {
|
||||
while (lst) {
|
||||
size_t len;
|
||||
char *val;
|
||||
/* try stack-allocation, it's much faster*/
|
||||
len = strlen ((char*)lst->data);
|
||||
if (G_LIKELY(len < 1024))
|
||||
val = (char*)g_alloca(len+1);
|
||||
else
|
||||
val = (char*)g_malloc(len+1);
|
||||
|
||||
strcpy (val, (char*)lst->data);
|
||||
|
||||
if (mu_msg_field_normalize (mfid))
|
||||
mu_str_normalize_in_place (val, TRUE);
|
||||
|
||||
doc.add_term (prefix(mfid) +
|
||||
std::string((char*)lst->data, 0,
|
||||
MU_STORE_MAX_TERM_LENGTH));
|
||||
std::string(val, 0, MU_STORE_MAX_TERM_LENGTH));
|
||||
|
||||
if (!(G_LIKELY(len < 1024)))
|
||||
g_free (val);
|
||||
|
||||
lst = g_slist_next ((GSList*)lst);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,19 +323,31 @@ static void
|
|||
test_mu_str_to_list (void)
|
||||
{
|
||||
{
|
||||
const char *items[]= {"foo", "bar", "cuux", NULL};
|
||||
GSList *lst = mu_str_to_list ("foo@bar@cuux",'@');
|
||||
const char *items[]= {"foo", "bar ", "cuux", NULL};
|
||||
GSList *lst = mu_str_to_list ("foo@bar @cuux",'@', FALSE);
|
||||
assert_cmplst (lst, items);
|
||||
mu_str_free_list (lst);
|
||||
}
|
||||
|
||||
{
|
||||
GSList *lst = mu_str_to_list (NULL,'x');
|
||||
GSList *lst = mu_str_to_list (NULL,'x',FALSE);
|
||||
g_assert (lst == NULL);
|
||||
mu_str_free_list (lst);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_mu_str_to_list_strip (void)
|
||||
{
|
||||
{
|
||||
const char *items[]= {"foo", "bar", "cuux", NULL};
|
||||
GSList *lst = mu_str_to_list ("foo@bar @cuux",'@', TRUE);
|
||||
assert_cmplst (lst, items);
|
||||
mu_str_free_list (lst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
|
@ -474,6 +486,8 @@ main (int argc, char *argv[])
|
|||
test_mu_str_from_list);
|
||||
g_test_add_func ("/mu-str/mu-str-to-list",
|
||||
test_mu_str_to_list);
|
||||
g_test_add_func ("/mu-str/mu-str-to-list-strip",
|
||||
test_mu_str_to_list_strip);
|
||||
|
||||
g_test_add_func ("/mu-str/mu_str_date_parse_hdwmy",
|
||||
test_mu_str_date_parse_hdwmy);
|
||||
|
|
Loading…
Reference in New Issue