2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: icu_I18N.c,v 1.21 2007-11-30 11:43:47 adam Exp $
14 #include <yaz/timing.h>
18 #include <yaz/xmalloc.h>
20 #include <yaz/icu_I18N.h>
28 #include <unicode/ustring.h> /* some more string fcns*/
29 #include <unicode/uchar.h> /* char names */
32 #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));
48 struct icu_buf_utf16 * icu_buf_utf16_create(size_t capacity)
50 struct icu_buf_utf16 * buf16
51 = (struct icu_buf_utf16 *) xmalloc(sizeof(struct icu_buf_utf16));
58 buf16->utf16 = (UChar *) xmalloc(sizeof(UChar) * capacity);
59 buf16->utf16[0] = (UChar) 0;
60 buf16->utf16_cap = capacity;
65 struct icu_buf_utf16 * icu_buf_utf16_clear(struct icu_buf_utf16 * buf16)
69 buf16->utf16[0] = (UChar) 0;
75 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;
102 struct icu_buf_utf16 * icu_buf_utf16_copy(struct icu_buf_utf16 * dest16,
103 struct icu_buf_utf16 * 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;
119 void icu_buf_utf16_destroy(struct icu_buf_utf16 * buf16)
128 struct icu_buf_utf8 * icu_buf_utf8_create(size_t capacity)
130 struct icu_buf_utf8 * buf8
131 = (struct icu_buf_utf8 *) xmalloc(sizeof(struct icu_buf_utf8));
138 buf8->utf8 = (uint8_t *) xmalloc(sizeof(uint8_t) * capacity);
139 buf8->utf8[0] = (uint8_t) 0;
140 buf8->utf8_cap = capacity;
146 struct icu_buf_utf8 * icu_buf_utf8_clear(struct icu_buf_utf8 * buf8)
150 buf8->utf8[0] = (uint8_t) 0;
157 struct icu_buf_utf8 * icu_buf_utf8_resize(struct icu_buf_utf8 * buf8,
165 buf8->utf8 = (uint8_t *) xmalloc(sizeof(uint8_t) * capacity);
168 = (uint8_t *) xrealloc(buf8->utf8, sizeof(uint8_t) * capacity);
170 icu_buf_utf8_clear(buf8);
171 buf8->utf8_cap = capacity;
184 struct icu_buf_utf8 * icu_buf_utf8_copy(struct icu_buf_utf8 * dest8,
185 struct icu_buf_utf8 * src8)
192 if (dest8->utf8_cap < src8->utf8_len)
193 icu_buf_utf8_resize(dest8, src8->utf8_len * 2);
195 strncpy((char*) dest8->utf8, (char*) src8->utf8, src8->utf8_len);
201 const char *icu_buf_utf8_to_cstr(struct icu_buf_utf8 *src8)
203 if (!src8 || src8->utf8_len == 0)
206 if (src8->utf8_len == src8->utf8_cap)
207 src8 = icu_buf_utf8_resize(src8, src8->utf8_len * 2 + 1);
209 src8->utf8[src8->utf8_len] = '\0';
211 return (const char *) src8->utf8;
215 void icu_buf_utf8_destroy(struct icu_buf_utf8 * buf8)
224 UErrorCode icu_utf16_from_utf8(struct icu_buf_utf16 * dest16,
225 struct icu_buf_utf8 * src8,
228 int32_t utf16_len = 0;
230 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
232 (const char *) src8->utf8, src8->utf8_len, status);
234 /* check for buffer overflow, resize and retry */
235 if (*status == U_BUFFER_OVERFLOW_ERROR)
237 icu_buf_utf16_resize(dest16, utf16_len * 2);
238 *status = U_ZERO_ERROR;
239 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
241 (const char *) src8->utf8, src8->utf8_len, status);
244 if (U_SUCCESS(*status)
245 && utf16_len <= dest16->utf16_cap)
246 dest16->utf16_len = utf16_len;
248 icu_buf_utf16_clear(dest16);
255 UErrorCode icu_utf16_from_utf8_cstr(struct icu_buf_utf16 * dest16,
256 const char * src8cstr,
259 size_t src8cstr_len = 0;
260 int32_t utf16_len = 0;
262 *status = U_ZERO_ERROR;
263 src8cstr_len = strlen(src8cstr);
265 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
267 src8cstr, src8cstr_len, status);
269 /* check for buffer overflow, resize and retry */
270 if (*status == U_BUFFER_OVERFLOW_ERROR)
272 icu_buf_utf16_resize(dest16, utf16_len * 2);
273 *status = U_ZERO_ERROR;
274 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
276 src8cstr, src8cstr_len, status);
279 if (U_SUCCESS(*status)
280 && utf16_len <= dest16->utf16_cap)
281 dest16->utf16_len = utf16_len;
283 icu_buf_utf16_clear(dest16);
291 UErrorCode icu_utf16_to_utf8(struct icu_buf_utf8 * dest8,
292 struct icu_buf_utf16 * src16,
295 int32_t utf8_len = 0;
297 u_strToUTF8((char *) dest8->utf8, dest8->utf8_cap,
299 src16->utf16, src16->utf16_len, status);
301 /* check for buffer overflow, resize and retry */
302 if (*status == U_BUFFER_OVERFLOW_ERROR)
304 icu_buf_utf8_resize(dest8, utf8_len * 2);
305 *status = U_ZERO_ERROR;
306 u_strToUTF8((char *) dest8->utf8, dest8->utf8_cap,
308 src16->utf16, src16->utf16_len, status);
312 if (U_SUCCESS(*status)
313 && utf8_len <= dest8->utf8_cap)
314 dest8->utf8_len = utf8_len;
316 icu_buf_utf8_clear(dest8);
323 struct icu_casemap * icu_casemap_create(char action, UErrorCode *status)
325 struct icu_casemap * casemap
326 = (struct icu_casemap *) xmalloc(sizeof(struct icu_casemap));
327 casemap->action = action;
329 switch(casemap->action) {
340 icu_casemap_destroy(casemap);
347 void icu_casemap_destroy(struct icu_casemap * casemap)
353 int icu_casemap_casemap(struct icu_casemap * casemap,
354 struct icu_buf_utf16 * dest16,
355 struct icu_buf_utf16 * src16,
362 return icu_utf16_casemap(dest16, src16, locale,
363 casemap->action, status);
367 int icu_utf16_casemap(struct icu_buf_utf16 * dest16,
368 struct icu_buf_utf16 * src16,
369 const char *locale, char action,
372 int32_t dest16_len = 0;
375 if (!src16->utf16_len){ /* guarding for empty source string */
377 dest16->utf16[0] = (UChar) 0;
378 dest16->utf16_len = 0;
386 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
387 src16->utf16, src16->utf16_len,
392 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
393 src16->utf16, src16->utf16_len,
398 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
399 src16->utf16, src16->utf16_len,
404 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
405 src16->utf16, src16->utf16_len,
406 U_FOLD_CASE_DEFAULT, status);
410 return U_UNSUPPORTED_ERROR;
414 /* check for buffer overflow, resize and retry */
415 if (*status == U_BUFFER_OVERFLOW_ERROR
416 && dest16 != src16 /* do not resize if in-place conversion */
418 icu_buf_utf16_resize(dest16, dest16_len * 2);
419 *status = U_ZERO_ERROR;
425 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
426 src16->utf16, src16->utf16_len,
431 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
432 src16->utf16, src16->utf16_len,
437 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
438 src16->utf16, src16->utf16_len,
443 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
444 src16->utf16, src16->utf16_len,
445 U_FOLD_CASE_DEFAULT, status);
449 return U_UNSUPPORTED_ERROR;
454 if (U_SUCCESS(*status)
455 && dest16_len <= dest16->utf16_cap)
456 dest16->utf16_len = dest16_len;
459 dest16->utf16[0] = (UChar) 0;
460 dest16->utf16_len = 0;
468 void icu_sortkey8_from_utf16(UCollator *coll,
469 struct icu_buf_utf8 * dest8,
470 struct icu_buf_utf16 * src16,
474 int32_t sortkey_len = 0;
476 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
477 dest8->utf8, dest8->utf8_cap);
479 /* check for buffer overflow, resize and retry */
480 if (sortkey_len > dest8->utf8_cap) {
481 icu_buf_utf8_resize(dest8, sortkey_len * 2);
482 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
483 dest8->utf8, dest8->utf8_cap);
486 if (U_SUCCESS(*status)
488 dest8->utf8_len = sortkey_len;
490 icu_buf_utf8_clear(dest8);
495 struct icu_tokenizer * icu_tokenizer_create(const char *locale, char action,
498 struct icu_tokenizer * tokenizer
499 = (struct icu_tokenizer *) xmalloc(sizeof(struct icu_tokenizer));
501 tokenizer->action = action;
503 tokenizer->buf16 = 0;
504 tokenizer->token_count = 0;
505 tokenizer->token_id = 0;
506 tokenizer->token_start = 0;
507 tokenizer->token_end = 0;
510 switch(tokenizer->action) {
513 tokenizer->bi = ubrk_open(UBRK_LINE, locale, 0, 0, status);
517 tokenizer->bi = ubrk_open(UBRK_SENTENCE, locale, 0, 0, status);
521 tokenizer->bi = ubrk_open(UBRK_WORD, locale, 0, 0, status);
525 tokenizer->bi = ubrk_open(UBRK_CHARACTER, locale, 0, 0, status);
529 tokenizer->bi = ubrk_open(UBRK_TITLE, locale, 0, 0, status);
532 *status = U_UNSUPPORTED_ERROR;
537 /* ICU error stuff is a very funny business */
538 if (U_SUCCESS(*status))
541 /* freeing if failed */
542 icu_tokenizer_destroy(tokenizer);
546 void icu_tokenizer_destroy(struct icu_tokenizer * tokenizer)
550 ubrk_close(tokenizer->bi);
555 int icu_tokenizer_attach(struct icu_tokenizer * tokenizer,
556 struct icu_buf_utf16 * src16,
559 if (!tokenizer || !tokenizer->bi || !src16)
563 tokenizer->buf16 = src16;
564 tokenizer->token_count = 0;
565 tokenizer->token_id = 0;
566 tokenizer->token_start = 0;
567 tokenizer->token_end = 0;
569 ubrk_setText(tokenizer->bi, src16->utf16, src16->utf16_len, status);
572 if (U_FAILURE(*status))
578 int32_t icu_tokenizer_next_token(struct icu_tokenizer * tokenizer,
579 struct icu_buf_utf16 * tkn16,
582 int32_t tkn_start = 0;
587 if (!tokenizer || !tokenizer->bi
588 || !tokenizer->buf16 || !tokenizer->buf16->utf16_len)
592 never change tokenizer->buf16 and keep always invariant
593 0 <= tokenizer->token_start
594 <= tokenizer->token_end
595 <= tokenizer->buf16->utf16_len
596 returns length of token
599 if (0 == tokenizer->token_end) /* first call */
600 tkn_start = ubrk_first(tokenizer->bi);
601 else /* successive calls */
602 tkn_start = tokenizer->token_end;
604 /* get next position */
605 tkn_end = ubrk_next(tokenizer->bi);
607 /* repairing invariant at end of ubrk, which is UBRK_DONE = -1 */
608 if (UBRK_DONE == tkn_end)
609 tkn_end = tokenizer->buf16->utf16_len;
611 /* copy out if everything is well */
612 if(U_FAILURE(*status))
615 /* everything OK, now update internal state */
616 tkn_len = tkn_end - tkn_start;
619 tokenizer->token_count++;
620 tokenizer->token_id++;
622 tokenizer->token_id = 0;
624 tokenizer->token_start = tkn_start;
625 tokenizer->token_end = tkn_end;
628 /* copying into token buffer if it exists */
630 if (tkn16->utf16_cap < tkn_len)
631 icu_buf_utf16_resize(tkn16, (size_t) tkn_len * 2);
633 u_strncpy(tkn16->utf16, &(tokenizer->buf16->utf16)[tkn_start],
636 tkn16->utf16_len = tkn_len;
643 int32_t icu_tokenizer_token_id(struct icu_tokenizer * tokenizer)
645 return tokenizer->token_id;
648 int32_t icu_tokenizer_token_start(struct icu_tokenizer * tokenizer)
650 return tokenizer->token_start;
653 int32_t icu_tokenizer_token_end(struct icu_tokenizer * tokenizer)
655 return tokenizer->token_end;
658 int32_t icu_tokenizer_token_length(struct icu_tokenizer * tokenizer)
660 return (tokenizer->token_end - tokenizer->token_start);
663 int32_t icu_tokenizer_token_count(struct icu_tokenizer * tokenizer)
665 return tokenizer->token_count;
670 struct icu_normalizer * icu_normalizer_create(const char *rules, char action,
674 struct icu_normalizer * normalizer
675 = (struct icu_normalizer *) xmalloc(sizeof(struct icu_normalizer));
677 normalizer->action = action;
678 normalizer->trans = 0;
679 normalizer->rules16 = icu_buf_utf16_create(0);
680 icu_utf16_from_utf8_cstr(normalizer->rules16, rules, status);
682 switch(normalizer->action) {
686 = utrans_openU(normalizer->rules16->utf16,
687 normalizer->rules16->utf16_len,
690 normalizer->parse_error, status);
695 = utrans_openU(normalizer->rules16->utf16,
696 normalizer->rules16->utf16_len,
699 normalizer->parse_error, status);
702 *status = U_UNSUPPORTED_ERROR;
707 if (U_SUCCESS(*status))
710 /* freeing if failed */
711 icu_normalizer_destroy(normalizer);
716 void icu_normalizer_destroy(struct icu_normalizer * normalizer){
718 if (normalizer->rules16)
719 icu_buf_utf16_destroy(normalizer->rules16);
720 if (normalizer->trans)
721 utrans_close(normalizer->trans);
728 int icu_normalizer_normalize(struct icu_normalizer * normalizer,
729 struct icu_buf_utf16 * dest16,
730 struct icu_buf_utf16 * src16,
733 if (!normalizer || !normalizer->trans
738 if (!src16->utf16_len){ /* guarding for empty source string */
739 icu_buf_utf16_clear(dest16);
743 if (!icu_buf_utf16_copy(dest16, src16))
747 utrans_transUChars (normalizer->trans,
748 dest16->utf16, &(dest16->utf16_len),
750 0, &(src16->utf16_len), status);
752 if (U_FAILURE(*status))
753 icu_buf_utf16_clear(dest16);
755 return dest16->utf16_len;
761 struct icu_chain_step * icu_chain_step_create(struct icu_chain * chain,
762 enum icu_chain_step_type type,
763 const uint8_t * rule,
764 struct icu_buf_utf16 * buf16,
767 struct icu_chain_step * step = 0;
769 if(!chain || !type || !rule)
772 step = (struct icu_chain_step *) xmalloc(sizeof(struct icu_chain_step));
778 /* create auxilary objects */
780 case ICU_chain_step_type_display:
782 case ICU_chain_step_type_casemap:
783 step->u.casemap = icu_casemap_create(rule[0], status);
785 case ICU_chain_step_type_normalize:
786 step->u.normalizer = icu_normalizer_create((char *) rule, 'f', status);
788 case ICU_chain_step_type_tokenize:
789 step->u.tokenizer = icu_tokenizer_create((char *) chain->locale,
790 (char) rule[0], status);
800 void icu_chain_step_destroy(struct icu_chain_step * step){
805 icu_chain_step_destroy(step->previous);
808 case ICU_chain_step_type_display:
810 case ICU_chain_step_type_casemap:
811 icu_casemap_destroy(step->u.casemap);
812 icu_buf_utf16_destroy(step->buf16);
814 case ICU_chain_step_type_normalize:
815 icu_normalizer_destroy(step->u.normalizer);
816 icu_buf_utf16_destroy(step->buf16);
818 case ICU_chain_step_type_tokenize:
819 icu_tokenizer_destroy(step->u.tokenizer);
820 icu_buf_utf16_destroy(step->buf16);
830 struct icu_chain * icu_chain_create(const char *locale, int sort,
833 struct icu_chain * chain
834 = (struct icu_chain *) xmalloc(sizeof(struct icu_chain));
836 *status = U_ZERO_ERROR;
838 chain->locale = xstrdup(locale);
842 chain->coll = ucol_open((const char *) chain->locale, status);
844 if (U_FAILURE(*status))
847 chain->token_count = 0;
851 chain->display8 = icu_buf_utf8_create(0);
852 chain->norm8 = icu_buf_utf8_create(0);
853 chain->sort8 = icu_buf_utf8_create(0);
855 chain->src16 = icu_buf_utf16_create(0);
863 void icu_chain_destroy(struct icu_chain * chain)
868 ucol_close(chain->coll);
870 icu_buf_utf8_destroy(chain->display8);
871 icu_buf_utf8_destroy(chain->norm8);
872 icu_buf_utf8_destroy(chain->sort8);
874 icu_buf_utf16_destroy(chain->src16);
876 icu_chain_step_destroy(chain->steps);
877 xfree(chain->locale);
884 struct icu_chain * icu_chain_xml_config(const xmlNode *xml_node,
889 struct icu_chain * chain = 0;
891 *status = U_ZERO_ERROR;
893 if (!xml_node ||xml_node->type != XML_ELEMENT_NODE)
897 xmlChar * xml_locale = xmlGetProp((xmlNode *) xml_node,
898 (xmlChar *) "locale");
902 chain = icu_chain_create((const char *) xml_locale, sort, status);
910 for (node = xml_node->children; node; node = node->next)
913 struct icu_chain_step * step = 0;
915 if (node->type != XML_ELEMENT_NODE)
918 xml_rule = xmlGetProp(node, (xmlChar *) "rule");
920 if (!strcmp((const char *) node->name, "casemap"))
921 step = icu_chain_insert_step(chain, ICU_chain_step_type_casemap,
922 (const uint8_t *) xml_rule, status);
923 else if (!strcmp((const char *) node->name, "transform"))
924 step = icu_chain_insert_step(chain, ICU_chain_step_type_normalize,
925 (const uint8_t *) xml_rule, status);
926 else if (!strcmp((const char *) node->name, "tokenize"))
927 step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize,
928 (const uint8_t *) xml_rule, status);
929 else if (!strcmp((const char *) node->name, "display"))
930 step = icu_chain_insert_step(chain, ICU_chain_step_type_display,
931 (const uint8_t *) "", status);
933 if (!step || U_FAILURE(*status))
935 icu_chain_destroy(chain);
946 struct icu_chain_step * icu_chain_insert_step(struct icu_chain * chain,
947 enum icu_chain_step_type type,
948 const uint8_t * rule,
951 struct icu_chain_step * step = 0;
952 struct icu_buf_utf16 * src16 = 0;
953 struct icu_buf_utf16 * buf16 = 0;
955 if (!chain || !type || !rule)
958 /* assign utf16 src buffers as needed */
959 if (chain->steps && chain->steps->buf16)
960 src16 = chain->steps->buf16;
961 else if (chain->src16)
962 src16 = chain->src16;
967 /* create utf16 destination buffers as needed, or */
970 case ICU_chain_step_type_display:
973 case ICU_chain_step_type_casemap:
974 buf16 = icu_buf_utf16_create(0);
976 case ICU_chain_step_type_normalize:
977 buf16 = icu_buf_utf16_create(0);
979 case ICU_chain_step_type_tokenize:
980 buf16 = icu_buf_utf16_create(0);
986 /* create actual chain step with this buffer */
987 step = icu_chain_step_create(chain, type, rule, buf16, status);
989 step->previous = chain->steps;
996 int icu_chain_step_next_token(struct icu_chain * chain,
997 struct icu_chain_step * step,
1000 struct icu_buf_utf16 * src16 = 0;
1001 int got_new_token = 0;
1003 if (!chain || !chain->src16 || !step || !step->more_tokens)
1006 /* assign utf16 src buffers as neeed, advance in previous steps
1007 tokens until non-zero token met, and setting stop condition */
1011 src16 = step->previous->buf16;
1012 /* tokens might be killed in previous steps, therefore looping */
1014 while (step->need_new_token
1015 && step->previous->more_tokens
1018 = icu_chain_step_next_token(chain, step->previous, status);
1021 { /* first step can only work once on chain->src16 input buffer */
1022 src16 = chain->src16;
1023 step->more_tokens = 0;
1030 /* stop if nothing to process */
1031 if (step->need_new_token && !got_new_token)
1033 step->more_tokens = 0;
1037 /* either an old token not finished yet, or a new token, thus
1038 perform the work, eventually put this steps output in
1039 step->buf16 or the chains UTF8 output buffers */
1043 case ICU_chain_step_type_display:
1044 icu_utf16_to_utf8(chain->display8, src16, status);
1046 case ICU_chain_step_type_casemap:
1047 icu_casemap_casemap(step->u.casemap,
1048 step->buf16, src16, status,
1051 case ICU_chain_step_type_normalize:
1052 icu_normalizer_normalize(step->u.normalizer,
1053 step->buf16, src16, status);
1055 case ICU_chain_step_type_tokenize:
1056 /* attach to new src16 token only first time during splitting */
1057 if (step->need_new_token)
1059 icu_tokenizer_attach(step->u.tokenizer, src16, status);
1060 step->need_new_token = 0;
1063 /* splitting one src16 token into multiple buf16 tokens */
1065 = icu_tokenizer_next_token(step->u.tokenizer,
1066 step->buf16, status);
1068 /* make sure to get new previous token if this one had been used up
1069 by recursive call to _same_ step */
1071 if (!step->more_tokens)
1073 step->more_tokens = icu_chain_step_next_token(chain, step, status);
1074 return step->more_tokens; /* avoid one token count too much! */
1082 if (U_FAILURE(*status))
1085 /* if token disappered into thin air, tell caller */
1086 /* if (!step->buf16->utf16_len && !step->more_tokens) */
1093 int icu_chain_assign_cstr(struct icu_chain * chain,
1094 const char * src8cstr,
1097 struct icu_chain_step * stp = 0;
1099 if (!chain || !src8cstr)
1102 chain->src8cstr = src8cstr;
1106 /* clear token count */
1107 chain->token_count = 0;
1109 /* clear all steps stop states */
1112 stp->more_tokens = 1;
1113 stp->need_new_token = 1;
1114 stp = stp->previous;
1117 /* finally convert UTF8 to UTF16 string if needed */
1118 if (chain->steps || chain->sort)
1119 icu_utf16_from_utf8_cstr(chain->src16, chain->src8cstr, status);
1121 if (U_FAILURE(*status))
1129 int icu_chain_next_token(struct icu_chain * chain,
1134 *status = U_ZERO_ERROR;
1139 /* special case with no steps - same as index type binary */
1142 if (chain->token_count)
1146 chain->token_count++;
1149 icu_sortkey8_from_utf16(chain->coll,
1150 chain->sort8, chain->steps->buf16,
1152 return chain->token_count;
1155 /* usual case, one or more icu chain steps existing */
1158 while(!got_token && chain->steps && chain->steps->more_tokens)
1159 got_token = icu_chain_step_next_token(chain, chain->steps, status);
1163 chain->token_count++;
1165 icu_utf16_to_utf8(chain->norm8, chain->steps->buf16, status);
1168 icu_sortkey8_from_utf16(chain->coll,
1169 chain->sort8, chain->steps->buf16,
1172 return chain->token_count;
1179 int icu_chain_token_number(struct icu_chain * chain)
1184 return chain->token_count;
1188 const char * icu_chain_token_display(struct icu_chain * chain)
1190 if (chain->display8)
1191 return icu_buf_utf8_to_cstr(chain->display8);
1196 const char * icu_chain_token_norm(struct icu_chain * chain)
1199 return chain->src8cstr;
1202 return icu_buf_utf8_to_cstr(chain->norm8);
1207 const char * icu_chain_token_sortkey(struct icu_chain * chain)
1210 return icu_buf_utf8_to_cstr(chain->sort8);
1215 const UCollator * icu_chain_get_coll(struct icu_chain * chain)
1220 #endif /* YAZ_HAVE_ICU */
1225 * indent-tabs-mode: nil
1227 * vim: shiftwidth=4 tabstop=8 expandtab