1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
17 #include <yaz/timing.h>
21 #include <yaz/xmalloc.h>
23 #include <yaz/icu_I18N.h>
31 #include <unicode/ustring.h> /* some more string fcns*/
32 #include <unicode/uchar.h> /* char names */
33 #include <unicode/ucol.h>
35 int icu_check_status(UErrorCode status)
37 if (U_FAILURE(status))
39 yaz_log(YLOG_WARN, "ICU: %d %s\n", status, u_errorName(status));
45 struct icu_buf_utf16 * icu_buf_utf16_create(size_t capacity)
47 struct icu_buf_utf16 * buf16
48 = (struct icu_buf_utf16 *) xmalloc(sizeof(struct icu_buf_utf16));
56 buf16->utf16 = (UChar *) xmalloc(sizeof(UChar) * capacity);
57 buf16->utf16[0] = (UChar) 0;
58 buf16->utf16_cap = capacity;
63 struct icu_buf_utf16 * icu_buf_utf16_clear(struct icu_buf_utf16 * buf16)
68 buf16->utf16[0] = (UChar) 0;
74 struct icu_buf_utf16 * icu_buf_utf16_resize(struct icu_buf_utf16 * buf16,
82 if (0 == buf16->utf16)
83 buf16->utf16 = (UChar *) xmalloc(sizeof(UChar) * capacity);
86 = (UChar *) xrealloc(buf16->utf16, sizeof(UChar) * capacity);
88 icu_buf_utf16_clear(buf16);
89 buf16->utf16_cap = capacity;
103 struct icu_buf_utf16 * icu_buf_utf16_copy(struct icu_buf_utf16 * dest16,
104 struct icu_buf_utf16 * src16)
106 if (!dest16 || !src16 || dest16 == src16)
109 if (dest16->utf16_cap < src16->utf16_len)
110 icu_buf_utf16_resize(dest16, src16->utf16_len * 2);
112 u_strncpy(dest16->utf16, src16->utf16, src16->utf16_len);
113 dest16->utf16_len = src16->utf16_len;
118 void icu_buf_utf16_destroy(struct icu_buf_utf16 * buf16)
125 struct icu_buf_utf8 * icu_buf_utf8_create(size_t capacity)
127 struct icu_buf_utf8 * buf8
128 = (struct icu_buf_utf8 *) xmalloc(sizeof(struct icu_buf_utf8));
136 buf8->utf8 = (uint8_t *) xmalloc(sizeof(uint8_t) * capacity);
137 buf8->utf8[0] = (uint8_t) 0;
138 buf8->utf8_cap = capacity;
143 struct icu_buf_utf8 * icu_buf_utf8_clear(struct icu_buf_utf8 * buf8)
148 buf8->utf8[0] = (uint8_t) 0;
154 struct icu_buf_utf8 * icu_buf_utf8_resize(struct icu_buf_utf8 * buf8,
162 buf8->utf8 = (uint8_t *) xmalloc(sizeof(uint8_t) * capacity);
165 = (uint8_t *) xrealloc(buf8->utf8, sizeof(uint8_t) * capacity);
167 buf8->utf8_cap = capacity;
179 const char *icu_buf_utf8_to_cstr(struct icu_buf_utf8 *src8)
181 if (!src8 || src8->utf8_len == 0)
184 if (src8->utf8_len == src8->utf8_cap)
185 src8 = icu_buf_utf8_resize(src8, src8->utf8_len * 2 + 1);
187 src8->utf8[src8->utf8_len] = '\0';
189 return (const char *) src8->utf8;
192 void icu_buf_utf8_destroy(struct icu_buf_utf8 * buf8)
199 UErrorCode icu_utf16_from_utf8_cstr(struct icu_buf_utf16 * dest16,
200 const char * src8cstr,
203 size_t src8cstr_len = 0;
204 int32_t utf16_len = 0;
206 *status = U_ZERO_ERROR;
207 src8cstr_len = strlen(src8cstr);
209 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
211 src8cstr, src8cstr_len, status);
213 /* check for buffer overflow, resize and retry */
214 if (*status == U_BUFFER_OVERFLOW_ERROR)
216 icu_buf_utf16_resize(dest16, utf16_len * 2);
217 *status = U_ZERO_ERROR;
218 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
220 src8cstr, src8cstr_len, status);
223 if (U_SUCCESS(*status)
224 && utf16_len <= dest16->utf16_cap)
225 dest16->utf16_len = utf16_len;
227 icu_buf_utf16_clear(dest16);
232 UErrorCode icu_utf16_to_utf8(struct icu_buf_utf8 * dest8,
233 struct icu_buf_utf16 * src16,
236 int32_t utf8_len = 0;
238 u_strToUTF8((char *) dest8->utf8, dest8->utf8_cap,
240 src16->utf16, src16->utf16_len, status);
242 /* check for buffer overflow, resize and retry */
243 if (*status == U_BUFFER_OVERFLOW_ERROR)
245 icu_buf_utf8_resize(dest8, utf8_len * 2);
246 *status = U_ZERO_ERROR;
247 u_strToUTF8((char *) dest8->utf8, dest8->utf8_cap,
249 src16->utf16, src16->utf16_len, status);
252 if (U_SUCCESS(*status)
253 && utf8_len <= dest8->utf8_cap)
254 dest8->utf8_len = utf8_len;
256 icu_buf_utf8_clear(dest8);
263 struct icu_casemap * icu_casemap_create(char action, UErrorCode *status)
265 struct icu_casemap * casemap
266 = (struct icu_casemap *) xmalloc(sizeof(struct icu_casemap));
267 casemap->action = action;
269 switch(casemap->action)
281 icu_casemap_destroy(casemap);
287 void icu_casemap_destroy(struct icu_casemap * casemap)
292 int icu_casemap_casemap(struct icu_casemap * casemap,
293 struct icu_buf_utf16 * dest16,
294 struct icu_buf_utf16 * src16,
301 return icu_utf16_casemap(dest16, src16, locale,
302 casemap->action, status);
305 int icu_utf16_casemap(struct icu_buf_utf16 * dest16,
306 struct icu_buf_utf16 * src16,
307 const char *locale, char action,
310 int32_t dest16_len = 0;
312 if (!src16->utf16_len)
313 { /* guarding for empty source string */
315 dest16->utf16[0] = (UChar) 0;
316 dest16->utf16_len = 0;
324 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
325 src16->utf16, src16->utf16_len,
330 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
331 src16->utf16, src16->utf16_len,
336 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
337 src16->utf16, src16->utf16_len,
342 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
343 src16->utf16, src16->utf16_len,
344 U_FOLD_CASE_DEFAULT, status);
348 return U_UNSUPPORTED_ERROR;
352 /* check for buffer overflow, resize and retry */
353 if (*status == U_BUFFER_OVERFLOW_ERROR
354 && dest16 != src16 /* do not resize if in-place conversion */
357 icu_buf_utf16_resize(dest16, dest16_len * 2);
358 *status = U_ZERO_ERROR;
363 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
364 src16->utf16, src16->utf16_len,
369 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
370 src16->utf16, src16->utf16_len,
375 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
376 src16->utf16, src16->utf16_len,
381 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
382 src16->utf16, src16->utf16_len,
383 U_FOLD_CASE_DEFAULT, status);
387 return U_UNSUPPORTED_ERROR;
392 if (U_SUCCESS(*status)
393 && dest16_len <= dest16->utf16_cap)
394 dest16->utf16_len = dest16_len;
398 dest16->utf16[0] = (UChar) 0;
399 dest16->utf16_len = 0;
405 void icu_sortkey8_from_utf16(UCollator *coll,
406 struct icu_buf_utf8 * dest8,
407 struct icu_buf_utf16 * src16,
410 int32_t sortkey_len = 0;
412 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
413 dest8->utf8, dest8->utf8_cap);
415 /* check for buffer overflow, resize and retry */
416 if (sortkey_len > dest8->utf8_cap)
418 icu_buf_utf8_resize(dest8, sortkey_len * 2);
419 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
420 dest8->utf8, dest8->utf8_cap);
423 if (U_SUCCESS(*status)
425 dest8->utf8_len = sortkey_len;
427 icu_buf_utf8_clear(dest8);
430 struct icu_tokenizer * icu_tokenizer_create(const char *locale, char action,
433 struct icu_tokenizer * tokenizer
434 = (struct icu_tokenizer *) xmalloc(sizeof(struct icu_tokenizer));
436 tokenizer->action = action;
438 tokenizer->buf16 = 0;
439 tokenizer->token_count = 0;
440 tokenizer->token_id = 0;
441 tokenizer->token_start = 0;
442 tokenizer->token_end = 0;
444 switch(tokenizer->action)
448 tokenizer->bi = ubrk_open(UBRK_LINE, locale, 0, 0, status);
452 tokenizer->bi = ubrk_open(UBRK_SENTENCE, locale, 0, 0, status);
456 tokenizer->bi = ubrk_open(UBRK_WORD, locale, 0, 0, status);
460 tokenizer->bi = ubrk_open(UBRK_CHARACTER, locale, 0, 0, status);
464 tokenizer->bi = ubrk_open(UBRK_TITLE, locale, 0, 0, status);
467 *status = U_UNSUPPORTED_ERROR;
472 /* ICU error stuff is a very funny business */
473 if (U_SUCCESS(*status))
476 /* freeing if failed */
477 icu_tokenizer_destroy(tokenizer);
481 void icu_tokenizer_destroy(struct icu_tokenizer * tokenizer)
485 ubrk_close(tokenizer->bi);
490 int icu_tokenizer_attach(struct icu_tokenizer * tokenizer,
491 struct icu_buf_utf16 * src16,
494 if (!tokenizer || !tokenizer->bi || !src16)
497 tokenizer->buf16 = src16;
498 tokenizer->token_count = 0;
499 tokenizer->token_id = 0;
500 tokenizer->token_start = 0;
501 tokenizer->token_end = 0;
503 ubrk_setText(tokenizer->bi, src16->utf16, src16->utf16_len, status);
505 if (U_FAILURE(*status))
511 int32_t icu_tokenizer_next_token(struct icu_tokenizer * tokenizer,
512 struct icu_buf_utf16 * tkn16,
515 int32_t tkn_start = 0;
519 if (!tokenizer || !tokenizer->bi
520 || !tokenizer->buf16 || !tokenizer->buf16->utf16_len)
523 never change tokenizer->buf16 and keep always invariant
524 0 <= tokenizer->token_start
525 <= tokenizer->token_end
526 <= tokenizer->buf16->utf16_len
527 returns length of token
530 if (0 == tokenizer->token_end) /* first call */
531 tkn_start = ubrk_first(tokenizer->bi);
532 else /* successive calls */
533 tkn_start = tokenizer->token_end;
535 /* get next position */
536 tkn_end = ubrk_next(tokenizer->bi);
538 /* repairing invariant at end of ubrk, which is UBRK_DONE = -1 */
539 if (UBRK_DONE == tkn_end)
540 tkn_end = tokenizer->buf16->utf16_len;
542 /* copy out if everything is well */
543 if (U_FAILURE(*status))
546 /* everything OK, now update internal state */
547 tkn_len = tkn_end - tkn_start;
551 tokenizer->token_count++;
552 tokenizer->token_id++;
554 tokenizer->token_id = 0;
556 tokenizer->token_start = tkn_start;
557 tokenizer->token_end = tkn_end;
559 /* copying into token buffer if it exists */
561 if (tkn16->utf16_cap < tkn_len)
562 icu_buf_utf16_resize(tkn16, (size_t) tkn_len * 2);
564 u_strncpy(tkn16->utf16, &(tokenizer->buf16->utf16)[tkn_start],
567 tkn16->utf16_len = tkn_len;
573 int32_t icu_tokenizer_token_id(struct icu_tokenizer * tokenizer)
575 return tokenizer->token_id;
578 int32_t icu_tokenizer_token_start(struct icu_tokenizer * tokenizer)
580 return tokenizer->token_start;
583 int32_t icu_tokenizer_token_end(struct icu_tokenizer * tokenizer)
585 return tokenizer->token_end;
588 int32_t icu_tokenizer_token_length(struct icu_tokenizer * tokenizer)
590 return (tokenizer->token_end - tokenizer->token_start);
593 int32_t icu_tokenizer_token_count(struct icu_tokenizer * tokenizer)
595 return tokenizer->token_count;
598 struct icu_transform * icu_transform_create(const char *id, char action,
602 struct icu_buf_utf16 *id16 = icu_buf_utf16_create(0);
603 struct icu_buf_utf16 *rules16 = icu_buf_utf16_create(0);
605 struct icu_transform * transform
606 = (struct icu_transform *) xmalloc(sizeof(struct icu_transform));
608 transform->action = action;
609 transform->trans = 0;
612 icu_utf16_from_utf8_cstr(id16, id, status);
614 icu_utf16_from_utf8_cstr(rules16, rules, status);
616 switch(transform->action)
621 = utrans_openU(id16->utf16,
626 &transform->parse_error, status);
631 = utrans_openU(id16->utf16,
636 &transform->parse_error, status);
639 *status = U_UNSUPPORTED_ERROR;
642 icu_buf_utf16_destroy(rules16);
643 icu_buf_utf16_destroy(id16);
645 if (U_SUCCESS(*status))
648 /* freeing if failed */
649 icu_transform_destroy(transform);
653 void icu_transform_destroy(struct icu_transform * transform)
657 if (transform->trans)
658 utrans_close(transform->trans);
663 int icu_transform_trans(struct icu_transform * transform,
664 struct icu_buf_utf16 * dest16,
665 struct icu_buf_utf16 * src16,
668 if (!transform || !transform->trans
669 || !src16 || !dest16)
672 if (!src16->utf16_len)
673 { /* guarding for empty source string */
674 icu_buf_utf16_clear(dest16);
678 if (!icu_buf_utf16_copy(dest16, src16))
681 utrans_transUChars (transform->trans,
682 dest16->utf16, &(dest16->utf16_len),
684 0, &(src16->utf16_len), status);
686 if (U_FAILURE(*status))
687 icu_buf_utf16_clear(dest16);
689 return dest16->utf16_len;
692 struct icu_chain_step * icu_chain_step_create(struct icu_chain * chain,
693 enum icu_chain_step_type type,
694 const uint8_t * rule,
695 struct icu_buf_utf16 * buf16,
698 struct icu_chain_step * step = 0;
700 if(!chain || !type || !rule)
703 step = (struct icu_chain_step *) xmalloc(sizeof(struct icu_chain_step));
709 /* create auxilary objects */
712 case ICU_chain_step_type_display:
714 case ICU_chain_step_type_casemap:
715 step->u.casemap = icu_casemap_create(rule[0], status);
717 case ICU_chain_step_type_transform:
718 /* rule omitted. Only ID used */
719 step->u.transform = icu_transform_create((const char *) rule, 'f',
722 case ICU_chain_step_type_tokenize:
723 step->u.tokenizer = icu_tokenizer_create((char *) chain->locale,
724 (char) rule[0], status);
726 case ICU_chain_step_type_transliterate:
727 /* we pass a dummy ID to utrans_openU.. */
728 step->u.transform = icu_transform_create("custom", 'f',
729 (const char *) rule, status);
738 void icu_chain_step_destroy(struct icu_chain_step * step)
743 icu_chain_step_destroy(step->previous);
747 case ICU_chain_step_type_display:
749 case ICU_chain_step_type_casemap:
750 icu_casemap_destroy(step->u.casemap);
751 icu_buf_utf16_destroy(step->buf16);
753 case ICU_chain_step_type_transform:
754 case ICU_chain_step_type_transliterate:
755 icu_transform_destroy(step->u.transform);
756 icu_buf_utf16_destroy(step->buf16);
758 case ICU_chain_step_type_tokenize:
759 icu_tokenizer_destroy(step->u.tokenizer);
760 icu_buf_utf16_destroy(step->buf16);
768 struct icu_chain * icu_chain_create(const char *locale, int sort,
771 struct icu_chain * chain
772 = (struct icu_chain *) xmalloc(sizeof(struct icu_chain));
774 *status = U_ZERO_ERROR;
776 chain->locale = xstrdup(locale);
780 chain->coll = ucol_open((const char *) chain->locale, status);
782 if (U_FAILURE(*status))
785 chain->token_count = 0;
789 chain->display8 = icu_buf_utf8_create(0);
790 chain->norm8 = icu_buf_utf8_create(0);
791 chain->sort8 = icu_buf_utf8_create(0);
793 chain->src16 = icu_buf_utf16_create(0);
800 void icu_chain_destroy(struct icu_chain * chain)
805 ucol_close(chain->coll);
807 icu_buf_utf8_destroy(chain->display8);
808 icu_buf_utf8_destroy(chain->norm8);
809 icu_buf_utf8_destroy(chain->sort8);
811 icu_buf_utf16_destroy(chain->src16);
813 icu_chain_step_destroy(chain->steps);
814 xfree(chain->locale);
819 struct icu_chain * icu_chain_xml_config(const xmlNode *xml_node,
824 struct icu_chain * chain = 0;
826 *status = U_ZERO_ERROR;
828 if (!xml_node ||xml_node->type != XML_ELEMENT_NODE)
832 xmlChar * xml_locale = xmlGetProp((xmlNode *) xml_node,
833 (xmlChar *) "locale");
837 chain = icu_chain_create((const char *) xml_locale, sort, status);
845 for (node = xml_node->children; node; node = node->next)
848 struct icu_chain_step * step = 0;
850 if (node->type != XML_ELEMENT_NODE)
853 xml_rule = xmlGetProp(node, (xmlChar *) "rule");
855 if (!strcmp((const char *) node->name, "casemap"))
856 step = icu_chain_insert_step(chain, ICU_chain_step_type_casemap,
857 (const uint8_t *) xml_rule, status);
858 else if (!strcmp((const char *) node->name, "transform"))
859 step = icu_chain_insert_step(chain, ICU_chain_step_type_transform,
860 (const uint8_t *) xml_rule, status);
861 else if (!strcmp((const char *) node->name, "transliterate"))
862 step = icu_chain_insert_step(chain, ICU_chain_step_type_transliterate,
863 (const uint8_t *) xml_rule, status);
864 else if (!strcmp((const char *) node->name, "tokenize"))
865 step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize,
866 (const uint8_t *) xml_rule, status);
867 else if (!strcmp((const char *) node->name, "display"))
868 step = icu_chain_insert_step(chain, ICU_chain_step_type_display,
869 (const uint8_t *) "", status);
870 else if (!strcmp((const char *) node->name, "normalize"))
872 yaz_log(YLOG_WARN, "Element %s is deprecated. "
873 "Use transform instead", node->name);
874 step = icu_chain_insert_step(chain, ICU_chain_step_type_transform,
875 (const uint8_t *) xml_rule, status);
877 else if (!strcmp((const char *) node->name, "index")
878 || !strcmp((const char *) node->name, "sortkey"))
880 yaz_log(YLOG_WARN, "Element %s is no longer needed. "
881 "Remove it from the configuration", node->name);
885 yaz_log(YLOG_WARN, "Unknown element %s", node->name);
886 icu_chain_destroy(chain);
890 if (step && U_FAILURE(*status))
892 icu_chain_destroy(chain);
899 struct icu_chain_step * icu_chain_insert_step(struct icu_chain * chain,
900 enum icu_chain_step_type type,
901 const uint8_t * rule,
904 struct icu_chain_step * step = 0;
905 struct icu_buf_utf16 * src16 = 0;
906 struct icu_buf_utf16 * buf16 = 0;
908 if (!chain || !type || !rule)
911 /* assign utf16 src buffers as needed */
912 if (chain->steps && chain->steps->buf16)
913 src16 = chain->steps->buf16;
914 else if (chain->src16)
915 src16 = chain->src16;
919 /* create utf16 destination buffers as needed, or */
922 case ICU_chain_step_type_display:
925 case ICU_chain_step_type_casemap:
926 buf16 = icu_buf_utf16_create(0);
928 case ICU_chain_step_type_transform:
929 case ICU_chain_step_type_transliterate:
930 buf16 = icu_buf_utf16_create(0);
932 case ICU_chain_step_type_tokenize:
933 buf16 = icu_buf_utf16_create(0);
939 /* create actual chain step with this buffer */
940 step = icu_chain_step_create(chain, type, rule, buf16, status);
942 step->previous = chain->steps;
948 static int icu_chain_step_next_token(struct icu_chain * chain,
949 struct icu_chain_step * step,
952 struct icu_buf_utf16 * src16 = 0;
953 int got_new_token = 0;
955 if (!chain || !chain->src16 || !step || !step->more_tokens)
958 /* assign utf16 src buffers as needed, advance in previous steps
959 tokens until non-zero token met, and setting stop condition */
963 src16 = step->previous->buf16;
964 /* tokens might be killed in previous steps, therefore looping */
966 while (step->need_new_token
967 && step->previous->more_tokens
970 = icu_chain_step_next_token(chain, step->previous, status);
973 { /* first step can only work once on chain->src16 input buffer */
974 src16 = chain->src16;
975 step->more_tokens = 0;
982 /* stop if nothing to process */
983 if (step->need_new_token && !got_new_token)
985 step->more_tokens = 0;
989 /* either an old token not finished yet, or a new token, thus
990 perform the work, eventually put this steps output in
991 step->buf16 or the chains UTF8 output buffers */
995 case ICU_chain_step_type_display:
996 icu_utf16_to_utf8(chain->display8, src16, status);
998 case ICU_chain_step_type_casemap:
999 icu_casemap_casemap(step->u.casemap,
1000 step->buf16, src16, status,
1003 case ICU_chain_step_type_transform:
1004 case ICU_chain_step_type_transliterate:
1005 icu_transform_trans(step->u.transform,
1006 step->buf16, src16, status);
1008 case ICU_chain_step_type_tokenize:
1009 /* attach to new src16 token only first time during splitting */
1010 if (step->need_new_token)
1012 icu_tokenizer_attach(step->u.tokenizer, src16, status);
1013 step->need_new_token = 0;
1016 /* splitting one src16 token into multiple buf16 tokens */
1018 = icu_tokenizer_next_token(step->u.tokenizer,
1019 step->buf16, status);
1021 /* make sure to get new previous token if this one had been used up
1022 by recursive call to _same_ step */
1024 if (!step->more_tokens)
1026 step->more_tokens = icu_chain_step_next_token(chain, step, status);
1027 return step->more_tokens; /* avoid one token count too much! */
1035 if (U_FAILURE(*status))
1038 /* if token disappered into thin air, tell caller */
1039 /* if (!step->buf16->utf16_len && !step->more_tokens) */
1045 int icu_chain_assign_cstr(struct icu_chain * chain, const char * src8cstr,
1048 struct icu_chain_step * stp = 0;
1050 if (!chain || !src8cstr)
1053 chain->src8cstr = src8cstr;
1057 /* clear token count */
1058 chain->token_count = 0;
1060 /* clear all steps stop states */
1063 stp->more_tokens = 1;
1064 stp->need_new_token = 1;
1065 stp = stp->previous;
1068 /* finally convert UTF8 to UTF16 string if needed */
1069 if (chain->steps || chain->sort)
1070 icu_utf16_from_utf8_cstr(chain->src16, chain->src8cstr, status);
1072 if (U_FAILURE(*status))
1078 int icu_chain_next_token(struct icu_chain * chain, UErrorCode *status)
1082 *status = U_ZERO_ERROR;
1087 /* special case with no steps - same as index type binary */
1090 if (chain->token_count)
1094 chain->token_count++;
1097 icu_sortkey8_from_utf16(chain->coll,
1098 chain->sort8, chain->steps->buf16,
1100 return chain->token_count;
1103 /* usual case, one or more icu chain steps existing */
1106 while (!got_token && chain->steps && chain->steps->more_tokens)
1107 got_token = icu_chain_step_next_token(chain, chain->steps, status);
1111 chain->token_count++;
1113 icu_utf16_to_utf8(chain->norm8, chain->steps->buf16, status);
1116 icu_sortkey8_from_utf16(chain->coll,
1117 chain->sort8, chain->steps->buf16,
1119 return chain->token_count;
1126 int icu_chain_token_number(struct icu_chain * chain)
1131 return chain->token_count;
1134 const char * icu_chain_token_display(struct icu_chain * chain)
1136 if (chain->display8)
1137 return icu_buf_utf8_to_cstr(chain->display8);
1142 const char * icu_chain_token_norm(struct icu_chain * chain)
1145 return chain->src8cstr;
1148 return icu_buf_utf8_to_cstr(chain->norm8);
1153 const char * icu_chain_token_sortkey(struct icu_chain * chain)
1156 return icu_buf_utf8_to_cstr(chain->sort8);
1161 const UCollator * icu_chain_get_coll(struct icu_chain * chain)
1166 #endif /* YAZ_HAVE_ICU */
1171 * c-file-style: "Stroustrup"
1172 * indent-tabs-mode: nil
1174 * vim: shiftwidth=4 tabstop=8 expandtab