* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: icu_I18N.c,v 1.7 2007-10-25 08:40:06 marc Exp $
+ * $Id: icu_I18N.c,v 1.8 2007-10-25 10:04:32 marc Exp $
*/
#if HAVE_CONFIG_H
chain->token_count = 0;
+ chain->src8cstr = 0;
+
chain->display8 = icu_buf_utf8_create(0);
chain->norm8 = icu_buf_utf8_create(0);
chain->sort8 = icu_buf_utf8_create(0);
chain->steps = 0;
-
return chain;
}
if (!chain || !src8cstr)
return 0;
+ chain->src8cstr = src8cstr;
+
stp = chain->steps;
/* clear token count */
stp = stp->previous;
}
- /* finally convert UTF8 to UTF16 string */
- icu_utf16_from_utf8_cstr(chain->src16, src8cstr, status);
+ /* finally convert UTF8 to UTF16 string if needed */
+ if (chain->steps || chain->sort)
+ icu_utf16_from_utf8_cstr(chain->src16, chain->src8cstr, status);
if (U_FAILURE(*status))
return 0;
{
int got_token = 0;
- if (!chain || !chain->steps)
+ if (!chain)
return 0;
- while(!got_token && chain->steps->more_tokens)
- got_token = icu_chain_step_next_token(chain, chain->steps, status);
-
- if (got_token){
- chain->token_count++;
-
- icu_utf16_to_utf8(chain->norm8, chain->steps->buf16, status);
+ /* special case with no steps - same as index type binary */
+ if (!chain->steps){
+ if (chain->token_count)
+ return 0;
+ else {
+ chain->token_count++;
+
+ if (chain->sort)
+ icu_sortkey8_from_utf16(chain->coll,
+ chain->sort8, chain->steps->buf16,
+ status);
+ return chain->token_count;
+ }
+ }
+ /* usual case, one or more icu chain steps existing */
+ else {
- icu_sortkey8_from_utf16(chain->coll,
- chain->sort8, chain->steps->buf16, status);
+ while(!got_token && chain->steps && chain->steps->more_tokens)
+ got_token = icu_chain_step_next_token(chain, chain->steps, status);
+
+ if (got_token){
+ chain->token_count++;
- return chain->token_count;
+ icu_utf16_to_utf8(chain->norm8, chain->steps->buf16, status);
+
+ if (chain->sort)
+ icu_sortkey8_from_utf16(chain->coll,
+ chain->sort8, chain->steps->buf16,
+ status);
+
+ return chain->token_count;
+ }
}
-
+
return 0;
}
}
-
const char * icu_chain_get_display(struct icu_chain * chain)
{
if (chain->display8)
const char * icu_chain_get_norm(struct icu_chain * chain)
{
+ if (!chain->steps)
+ return chain->src8cstr;
+
if (chain->norm8)
return icu_buf_utf8_to_cstr(chain->norm8);
-/* $Id: tst_icu_I18N.c,v 1.8 2007-10-25 08:42:21 marc Exp $
+/* $Id: tst_icu_I18N.c,v 1.9 2007-10-25 10:04:33 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
icu_chain_destroy(chain);
}
+void test_chain_empty_chain(void)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ struct icu_chain * chain = 0;
+
+ const char * xml_str = "<icu>"
+ "</icu>";
+
+ const char * src8 = "some 5487 weired !ยค%&(/& sTuFf";
+ char * dest8 = 0;
+
+ xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+ xmlNode *xml_node = xmlDocGetRootElement(doc);
+ YAZ_CHECK(xml_node);
+
+ chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status);
+
+ xmlFreeDoc(doc);
+ YAZ_CHECK(chain);
+
+ YAZ_CHECK(icu_chain_assign_cstr(
+ chain, src8,
+ &status));
+
+ while (icu_chain_next_token(chain, &status)){
+ ;
+ //printf("%d '%s' '%s'\n",
+ // icu_chain_get_token_count(chain),
+ // icu_chain_get_norm(chain),
+ // icu_chain_get_display(chain));
+ }
+
+ YAZ_CHECK_EQ(icu_chain_get_token_count(chain), 1);
+
+ dest8 = icu_chain_get_norm(chain);
+ YAZ_CHECK_EQ(strcmp(src8, dest8), 0);
+
+
+ icu_chain_destroy(chain);
+}
+
#endif // HAVE_ICU
/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */
test_icu_I18N_tokenizer(argc, argv);
test_icu_I18N_chain(argc, argv);
test_chain_empty_token();
+ test_chain_empty_chain();
test_bug_1140();
#else /* HAVE_ICU */