From ed329d8fb558a860215b29aea90ff688488bcf45 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 8 Nov 2010 15:11:18 +0100 Subject: [PATCH] ICU rules may be specified as CDATA below the rule MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This allows for multi-line rules, such as ICU custom transliterators. For example: $back = \` ; $back $back > “ ; # generate right d.q.m. (double quotation mark) $back > ‘ ; --- src/icu_chain.c | 63 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/src/icu_chain.c b/src/icu_chain.c index 5354e89..c6f21ef 100644 --- a/src/icu_chain.c +++ b/src/icu_chain.c @@ -18,7 +18,8 @@ #include #include - +#include +#include #include #include #include @@ -218,7 +219,9 @@ struct icu_chain *icu_chain_xml_config(const xmlNode *xml_node, UErrorCode *status) { xmlNode *node = 0; + int no_errors = 0; struct icu_chain *chain = 0; + NMEM nmem = 0; *status = U_ZERO_ERROR; @@ -239,30 +242,53 @@ struct icu_chain *icu_chain_xml_config(const xmlNode *xml_node, if (!chain) return 0; + nmem = nmem_create(); for (node = xml_node->children; node; node = node->next) { - xmlChar *xml_rule; + char *rule = 0; struct icu_chain_step *step = 0; + struct _xmlAttr *attr; + nmem_reset(nmem); if (node->type != XML_ELEMENT_NODE) continue; - xml_rule = xmlGetProp(node, (xmlChar *) "rule"); - - yaz_log(YLOG_LOG, "rule=%s", xml_rule); - + for (attr = node->properties; attr; attr = attr->next) + { + if (!strcmp((const char *) attr->name, "rule")) + { + rule = nmem_text_node_cdata(attr->children, nmem); + } + else + { + yaz_log(YLOG_WARN, "Unsupported attribute '%s' for " + "element '%s'", attr->name, node->name); + no_errors++; + continue; + } + } + if (!rule && node->children) + rule = nmem_text_node_cdata(node->children, nmem); + + if (!rule || !*rule) + { + yaz_log(YLOG_WARN, "Missing rule for element '%s'", node->name); + no_errors++; + continue; + } + if (!strcmp((const char *) node->name, "casemap")) step = icu_chain_insert_step(chain, ICU_chain_step_type_casemap, - (const uint8_t *) xml_rule, status); + (const uint8_t *) rule, status); else if (!strcmp((const char *) node->name, "transform")) step = icu_chain_insert_step(chain, ICU_chain_step_type_transform, - (const uint8_t *) xml_rule, status); + (const uint8_t *) rule, status); else if (!strcmp((const char *) node->name, "transliterate")) step = icu_chain_insert_step(chain, ICU_chain_step_type_transliterate, - (const uint8_t *) xml_rule, status); + (const uint8_t *) rule, status); else if (!strcmp((const char *) node->name, "tokenize")) step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize, - (const uint8_t *) xml_rule, status); + (const uint8_t *) rule, status); else if (!strcmp((const char *) node->name, "display")) step = icu_chain_insert_step(chain, ICU_chain_step_type_display, (const uint8_t *) "", status); @@ -271,7 +297,7 @@ struct icu_chain *icu_chain_xml_config(const xmlNode *xml_node, yaz_log(YLOG_WARN, "Element %s is deprecated. " "Use transform instead", node->name); step = icu_chain_insert_step(chain, ICU_chain_step_type_transform, - (const uint8_t *) xml_rule, status); + (const uint8_t *) rule, status); } else if (!strcmp((const char *) node->name, "index") || !strcmp((const char *) node->name, "sortkey")) @@ -282,16 +308,21 @@ struct icu_chain *icu_chain_xml_config(const xmlNode *xml_node, else { yaz_log(YLOG_WARN, "Unknown element %s", node->name); - icu_chain_destroy(chain); - return 0; + no_errors++; + continue; } - xmlFree(xml_rule); if (step && U_FAILURE(*status)) { - icu_chain_destroy(chain); - return 0; + no_errors++; + break; } } + nmem_destroy(nmem); + if (no_errors) + { + icu_chain_destroy(chain); + return 0; + } return chain; } -- 1.7.10.4