From: Adam Dickmeiss Date: Thu, 8 Nov 2007 13:35:13 +0000 (+0000) Subject: Refactor ICU WRT locale. X-Git-Tag: YAZ.3.0.16~26 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=e089d89f38b4fc61fce16eb03150776844b053f8;p=yaz-moved-to-github.git Refactor ICU WRT locale. The locale parameter is no longer a parameter for icu_chain_xml_config and locale is read as an attribute for top XML node. The icu_casemap locale is no longer a member and a parater for icu_casemap_casemap instead. This saves a copy of a locale in each casemap. --- diff --git a/include/yaz/icu.h b/include/yaz/icu.h index 19ab4ce..7389d60 100644 --- a/include/yaz/icu.h +++ b/include/yaz/icu.h @@ -50,7 +50,6 @@ yaz_icu_chain_t icu_chain_create(const char * locale, void icu_chain_destroy(yaz_icu_chain_t chain); yaz_icu_chain_t icu_chain_xml_config(const xmlNode *xml_node, - const char *locale, int sort, UErrorCode * status); diff --git a/include/yaz/icu_I18N.h b/include/yaz/icu_I18N.h index 0b06dbd..2a1364d 100644 --- a/include/yaz/icu_I18N.h +++ b/include/yaz/icu_I18N.h @@ -102,7 +102,6 @@ UErrorCode icu_utf16_to_utf8(struct icu_buf_utf8 * dest8, struct icu_casemap { - char locale[16]; char action; }; @@ -114,7 +113,8 @@ void icu_casemap_destroy(struct icu_casemap * casemap); int icu_casemap_casemap(struct icu_casemap * casemap, struct icu_buf_utf16 * dest16, struct icu_buf_utf16 * src16, - UErrorCode *status); + UErrorCode *status, + const char *locale); int icu_utf16_casemap(struct icu_buf_utf16 * dest16, struct icu_buf_utf16 * src16, @@ -226,7 +226,7 @@ void icu_chain_step_destroy(struct icu_chain_step * step); struct icu_chain { - uint8_t locale[16]; + char locale[16]; int sort; const char * src8cstr; diff --git a/src/icu_I18N.c b/src/icu_I18N.c index 2259b46..4e9dcf7 100644 --- a/src/icu_I18N.c +++ b/src/icu_I18N.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: icu_I18N.c,v 1.13 2007-11-08 08:17:17 adam Exp $ + * $Id: icu_I18N.c,v 1.14 2007-11-08 13:35:13 adam Exp $ */ #if HAVE_CONFIG_H @@ -333,7 +333,6 @@ struct icu_casemap * icu_casemap_create(const char *locale, char action, { struct icu_casemap * casemap = (struct icu_casemap *) malloc(sizeof(struct icu_casemap)); - strcpy(casemap->locale, locale); casemap->action = action; switch(casemap->action) { @@ -356,7 +355,7 @@ struct icu_casemap * icu_casemap_create(const char *locale, char action, void icu_casemap_destroy(struct icu_casemap * casemap) { - if (casemap) + if (casemap) free(casemap); } @@ -364,13 +363,14 @@ void icu_casemap_destroy(struct icu_casemap * casemap) int icu_casemap_casemap(struct icu_casemap * casemap, struct icu_buf_utf16 * dest16, struct icu_buf_utf16 * src16, - UErrorCode *status) + UErrorCode *status, + const char *locale) { if(!casemap) return 0; - return icu_utf16_casemap(dest16, src16, - casemap->locale, casemap->action, status); + return icu_utf16_casemap(dest16, src16, locale, + casemap->action, status); } @@ -909,28 +909,31 @@ void icu_chain_destroy(struct icu_chain * chain) struct icu_chain * icu_chain_xml_config(const xmlNode *xml_node, - const char *locale, int sort, - UErrorCode * status){ - + UErrorCode * status) +{ xmlNode *node = 0; struct icu_chain * chain = 0; *status = U_ZERO_ERROR; - if (!xml_node - ||xml_node->type != XML_ELEMENT_NODE - // || strcmp((const char *) xml_node->name, "icu_chain") - ) - + if (!xml_node ||xml_node->type != XML_ELEMENT_NODE) return 0; - - chain = icu_chain_create(locale, sort, status); - + + { + xmlChar * xml_locale = xmlGetProp((xmlNode *) xml_node, + (xmlChar *) "locale"); + + if (xml_locale) + { + chain = icu_chain_create((const char *) xml_locale, sort, status); + xmlFree(xml_locale); + } + + } if (!chain) return 0; - for (node = xml_node->children; node; node = node->next) { xmlChar *xml_rule; @@ -1072,7 +1075,8 @@ int icu_chain_step_next_token(struct icu_chain * chain, break; case ICU_chain_step_type_casemap: icu_casemap_casemap(step->u.casemap, - step->buf16, src16, status); + step->buf16, src16, status, + chain->locale); break; case ICU_chain_step_type_normalize: icu_normalizer_normalize(step->u.normalizer, diff --git a/test/tst_icu_I18N.c b/test/tst_icu_I18N.c index 17c5a69..c58ac85 100644 --- a/test/tst_icu_I18N.c +++ b/test/tst_icu_I18N.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tst_icu_I18N.c,v 1.13 2007-11-08 09:03:11 adam Exp $ + * $Id: tst_icu_I18N.c,v 1.14 2007-11-08 13:35:14 adam Exp $ * */ @@ -480,7 +480,7 @@ void test_icu_I18N_chain(int argc, char **argv) struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" "" "" "" @@ -493,8 +493,7 @@ void test_icu_I18N_chain(int argc, char **argv) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - - chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status); + chain = icu_chain_xml_config(xml_node, 0, &status); xmlFreeDoc(doc); YAZ_CHECK(chain); @@ -534,7 +533,7 @@ void test_bug_1140(void) UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" /* if the first rule is normalize instead. Then it works */ #if 0 @@ -551,7 +550,7 @@ void test_bug_1140(void) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status); + chain = icu_chain_xml_config(xml_node, 0, &status); xmlFreeDoc(doc); YAZ_CHECK(chain); @@ -595,7 +594,7 @@ void test_chain_empty_token(void) UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" "" "" ""; @@ -604,7 +603,7 @@ void test_chain_empty_token(void) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status); + chain = icu_chain_xml_config(xml_node, 0, &status); xmlFreeDoc(doc); YAZ_CHECK(chain); @@ -631,7 +630,7 @@ void test_chain_empty_chain(void) UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" ""; const char * src8 = "some 5487 weired !¤%&(/& sTuFf"; @@ -641,7 +640,7 @@ void test_chain_empty_chain(void) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status); + chain = icu_chain_xml_config(xml_node, 0, &status); xmlFreeDoc(doc); YAZ_CHECK(chain); diff --git a/util/yaz-icu.c b/util/yaz-icu.c index c4fb91f..f41b93c 100644 --- a/util/yaz-icu.c +++ b/util/yaz-icu.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: yaz-icu.c,v 1.10 2007-11-08 09:29:39 adam Exp $ + * $Id: yaz-icu.c,v 1.11 2007-11-08 13:35:14 adam Exp $ */ #if HAVE_CONFIG_H @@ -428,7 +428,6 @@ static void process_text_file(const struct config_t *p_config) xmlDoc *doc = xmlParseFile(config.conffile); xmlNode *xml_node = xmlDocGetRootElement(doc); - xmlChar *xml_locale = xmlGetProp(xml_node, (xmlChar *) "locale"); long unsigned int token_count = 0; long unsigned int line_count = 0; @@ -442,14 +441,7 @@ static void process_text_file(const struct config_t *p_config) exit (1); } - if (!xml_locale || !strlen((const char *) xml_locale)) - return; - - config.chain = icu_chain_xml_config(xml_node, (const char *) xml_locale, 0, - &status); - - xmlFree(xml_locale); - + config.chain = icu_chain_xml_config(xml_node, 0, &status); if (config.chain && U_SUCCESS(status)) success = 1;