#include <yaz/log.h>
#include <yaz/nmem.h>
#include <yaz/nmem_xml.h>
+#include <yaz/xml_get.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
if (xml_node && xml_node->type == XML_ELEMENT_NODE)
{
- xmlChar *xml_locale = xmlGetProp((xmlNode *) xml_node,
- (xmlChar *) "locale");
+ const char *xml_locale = yaz_xml_get_prop((xmlNode *) xml_node,
+ "locale");
if (xml_locale)
- {
chain = icu_chain_create((const char *) xml_locale, sort, status);
- xmlFree(xml_locale);
- }
}
if (!chain)
{
char *rule = 0;
struct icu_chain_step *step = 0;
- struct _xmlAttr *attr;
+ const char *attr_str;
nmem_reset(nmem);
if (node->type != XML_ELEMENT_NODE)
continue;
-
- for (attr = node->properties; attr; attr = attr->next)
+ attr_str = yaz_xml_get_prop(node, "rule%s", &rule);
+ if (attr_str)
{
- 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++;
- }
+ yaz_log(YLOG_WARN, "Unsupported attribute '%s' for "
+ "element '%s'", attr_str, node->name);
+ no_errors++;
}
if (!rule && node->children)
rule = nmem_text_node_cdata(node->children, nmem);
struct icu_chain *chain;
struct icu_buf_utf16 *last;
struct icu_buf_utf16 *org;
+ struct icu_buf_utf8 *org8;
UErrorCode status;
struct icu_buf_utf8 *display;
struct icu_buf_utf8 *sort8;
struct icu_buf_utf16 *src = dst;
icu_tokenizer_attach(step->u.tokenizer, src, &iter->status);
+ if (step->previous)
+ { /* no need to copy if it's already the same */
+ iter->utf8_base = iter->utf16_base = 0;
+ icu_buf_utf16_copy(iter->org, src);
+ }
icu_buf_utf16_destroy(src);
}
dst = icu_buf_utf16_create(0);
iter->sort8 = icu_buf_utf8_create(0);
iter->result = icu_buf_utf8_create(0);
iter->org = icu_buf_utf16_create(0);
+ iter->org8 = 0;
iter->last = 0; /* no last returned string (yet) */
iter->steps = icu_chain_step_clone(chain->csteps);
iter->token_count = 0;
icu_buf_utf8_destroy(iter->sort8);
icu_buf_utf8_destroy(iter->result);
icu_buf_utf16_destroy(iter->org);
+ icu_buf_utf8_destroy(iter->org8);
icu_chain_step_destroy(iter->steps);
xfree(iter);
}
}
-void icu_iter_get_org_info(yaz_icu_iter_t iter, size_t *start, size_t *len)
+void icu_iter_get_org_info2(yaz_icu_iter_t iter, size_t *start, size_t *len,
+ const char **cstr)
{
int32_t len1 = 0, len2 = 0;
UErrorCode status = U_ZERO_ERROR;
*len = len2 - len1;
+ if (cstr)
+ {
+ if (!iter->org8)
+ iter->org8 = icu_buf_utf8_create(0);
+ status = U_ZERO_ERROR;
+ icu_utf16_to_utf8(iter->org8, iter->org, &status);
+ *cstr = icu_buf_utf8_to_cstr(iter->org8);
+ }
iter->utf8_base = *start;
iter->utf16_base = iter->org_start;
}
+void icu_iter_get_org_info(yaz_icu_iter_t iter, size_t *start, size_t *len)
+{
+ icu_iter_get_org_info2(iter, start, len, 0);
+}
+
int icu_chain_assign_cstr(struct icu_chain *chain, const char *src8cstr,
UErrorCode *status)
{
icu_iter_get_org_info(chain->iter, start, len);
}
+void icu_chain_get_org_info2(struct icu_chain *chain, size_t *start,
+ size_t *len, const char **cstr)
+{
+ if (chain->iter)
+ icu_iter_get_org_info2(chain->iter, start, len, cstr);
+}
+
#endif /* YAZ_HAVE_ICU */