* use the new strip option for list->str
This commit is contained in:
@ -92,7 +92,7 @@ mu_msg_doc_get_str_list_field (MuMsgDoc *self, MuMsgFieldId mfid,
|
|||||||
try {
|
try {
|
||||||
/* return a comma-separated string as a GSList */
|
/* return a comma-separated string as a GSList */
|
||||||
const std::string s (self->doc().get_value(mfid));
|
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);
|
} 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)) {
|
if (lst && mu_msg_field_xapian_term (mfid)) {
|
||||||
while (lst) {
|
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) +
|
doc.add_term (prefix(mfid) +
|
||||||
std::string((char*)lst->data, 0,
|
std::string(val, 0, MU_STORE_MAX_TERM_LENGTH));
|
||||||
MU_STORE_MAX_TERM_LENGTH));
|
|
||||||
|
if (!(G_LIKELY(len < 1024)))
|
||||||
|
g_free (val);
|
||||||
|
|
||||||
lst = g_slist_next ((GSList*)lst);
|
lst = g_slist_next ((GSList*)lst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -324,18 +324,30 @@ test_mu_str_to_list (void)
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
const char *items[]= {"foo", "bar ", "cuux", NULL};
|
const char *items[]= {"foo", "bar ", "cuux", NULL};
|
||||||
GSList *lst = mu_str_to_list ("foo@bar@cuux",'@');
|
GSList *lst = mu_str_to_list ("foo@bar @cuux",'@', FALSE);
|
||||||
assert_cmplst (lst, items);
|
assert_cmplst (lst, items);
|
||||||
mu_str_free_list (lst);
|
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);
|
g_assert (lst == NULL);
|
||||||
mu_str_free_list (lst);
|
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
|
static void
|
||||||
@ -474,6 +486,8 @@ main (int argc, char *argv[])
|
|||||||
test_mu_str_from_list);
|
test_mu_str_from_list);
|
||||||
g_test_add_func ("/mu-str/mu-str-to-list",
|
g_test_add_func ("/mu-str/mu-str-to-list",
|
||||||
test_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",
|
g_test_add_func ("/mu-str/mu_str_date_parse_hdwmy",
|
||||||
test_mu_str_date_parse_hdwmy);
|
test_mu_str_date_parse_hdwmy);
|
||||||
|
|||||||
Reference in New Issue
Block a user