2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: icu_I18N.c,v 1.12 2007-11-07 10:19:12 adam Exp $
14 #include <yaz/timing.h>
19 #include <yaz/icu_I18N.h>
27 #include <unicode/ustring.h> /* some more string fcns*/
28 #include <unicode/uchar.h> /* char names */
31 #include <unicode/ucol.h>
34 int icu_check_status (UErrorCode status)
36 if(U_FAILURE(status)){
38 "ICU: %d %s\n", status, u_errorName(status));
47 struct icu_buf_utf16 * icu_buf_utf16_create(size_t capacity)
49 struct icu_buf_utf16 * buf16
50 = (struct icu_buf_utf16 *) malloc(sizeof(struct icu_buf_utf16));
57 buf16->utf16 = (UChar *) malloc(sizeof(UChar) * capacity);
58 buf16->utf16[0] = (UChar) 0;
59 buf16->utf16_cap = capacity;
64 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,
81 if (0 == buf16->utf16)
82 buf16->utf16 = (UChar *) malloc(sizeof(UChar) * capacity);
85 = (UChar *) realloc(buf16->utf16, sizeof(UChar) * capacity);
87 icu_buf_utf16_clear(buf16);
88 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)
133 struct icu_buf_utf8 * icu_buf_utf8_create(size_t capacity)
135 struct icu_buf_utf8 * buf8
136 = (struct icu_buf_utf8 *) malloc(sizeof(struct icu_buf_utf8));
143 buf8->utf8 = (uint8_t *) malloc(sizeof(uint8_t) * capacity);
144 buf8->utf8[0] = (uint8_t) 0;
145 buf8->utf8_cap = capacity;
151 struct icu_buf_utf8 * icu_buf_utf8_clear(struct icu_buf_utf8 * buf8)
155 buf8->utf8[0] = (uint8_t) 0;
162 struct icu_buf_utf8 * icu_buf_utf8_resize(struct icu_buf_utf8 * buf8,
170 buf8->utf8 = (uint8_t *) malloc(sizeof(uint8_t) * capacity);
173 = (uint8_t *) realloc(buf8->utf8, sizeof(uint8_t) * capacity);
175 icu_buf_utf8_clear(buf8);
176 buf8->utf8_cap = capacity;
190 struct icu_buf_utf8 * icu_buf_utf8_copy(struct icu_buf_utf8 * dest8,
191 struct icu_buf_utf8 * src8)
198 if (dest8->utf8_cap < src8->utf8_len)
199 icu_buf_utf8_resize(dest8, src8->utf8_len * 2);
201 strncpy((char*) dest8->utf8, (char*) src8->utf8, src8->utf8_len);
207 const char *icu_buf_utf8_to_cstr(struct icu_buf_utf8 *src8)
209 if (!src8 || src8->utf8_len == 0)
212 if (src8->utf8_len == src8->utf8_cap)
213 src8 = icu_buf_utf8_resize(src8, src8->utf8_len * 2 + 1);
215 src8->utf8[src8->utf8_len] = '\0';
217 return (const char *) src8->utf8;
221 void icu_buf_utf8_destroy(struct icu_buf_utf8 * buf8)
232 UErrorCode icu_utf16_from_utf8(struct icu_buf_utf16 * dest16,
233 struct icu_buf_utf8 * src8,
236 int32_t utf16_len = 0;
238 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
240 (const char *) src8->utf8, src8->utf8_len, status);
242 /* check for buffer overflow, resize and retry */
243 if (*status == U_BUFFER_OVERFLOW_ERROR)
245 icu_buf_utf16_resize(dest16, utf16_len * 2);
246 *status = U_ZERO_ERROR;
247 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
249 (const char *) src8->utf8, src8->utf8_len, status);
252 if (U_SUCCESS(*status)
253 && utf16_len <= dest16->utf16_cap)
254 dest16->utf16_len = utf16_len;
256 icu_buf_utf16_clear(dest16);
263 UErrorCode icu_utf16_from_utf8_cstr(struct icu_buf_utf16 * dest16,
264 const char * src8cstr,
267 size_t src8cstr_len = 0;
268 int32_t utf16_len = 0;
270 *status = U_ZERO_ERROR;
271 src8cstr_len = strlen(src8cstr);
273 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
275 src8cstr, src8cstr_len, status);
277 /* check for buffer overflow, resize and retry */
278 if (*status == U_BUFFER_OVERFLOW_ERROR)
280 icu_buf_utf16_resize(dest16, utf16_len * 2);
281 *status = U_ZERO_ERROR;
282 u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
284 src8cstr, src8cstr_len, status);
287 if (U_SUCCESS(*status)
288 && utf16_len <= dest16->utf16_cap)
289 dest16->utf16_len = utf16_len;
291 icu_buf_utf16_clear(dest16);
299 UErrorCode icu_utf16_to_utf8(struct icu_buf_utf8 * dest8,
300 struct icu_buf_utf16 * src16,
303 int32_t utf8_len = 0;
305 u_strToUTF8((char *) dest8->utf8, dest8->utf8_cap,
307 src16->utf16, src16->utf16_len, status);
309 /* check for buffer overflow, resize and retry */
310 if (*status == U_BUFFER_OVERFLOW_ERROR)
312 icu_buf_utf8_resize(dest8, utf8_len * 2);
313 *status = U_ZERO_ERROR;
314 u_strToUTF8((char *) dest8->utf8, dest8->utf8_cap,
316 src16->utf16, src16->utf16_len, status);
320 if (U_SUCCESS(*status)
321 && utf8_len <= dest8->utf8_cap)
322 dest8->utf8_len = utf8_len;
324 icu_buf_utf8_clear(dest8);
331 struct icu_casemap * icu_casemap_create(const char *locale, char action,
334 struct icu_casemap * casemap
335 = (struct icu_casemap *) malloc(sizeof(struct icu_casemap));
336 strcpy(casemap->locale, locale);
337 casemap->action = action;
339 switch(casemap->action) {
350 icu_casemap_destroy(casemap);
357 void icu_casemap_destroy(struct icu_casemap * casemap)
364 int icu_casemap_casemap(struct icu_casemap * casemap,
365 struct icu_buf_utf16 * dest16,
366 struct icu_buf_utf16 * src16,
372 return icu_utf16_casemap(dest16, src16,
373 casemap->locale, casemap->action, status);
377 int icu_utf16_casemap(struct icu_buf_utf16 * dest16,
378 struct icu_buf_utf16 * src16,
379 const char *locale, char action,
382 int32_t dest16_len = 0;
385 if (!src16->utf16_len){ //guarding for empty source string
387 dest16->utf16[0] = (UChar) 0;
388 dest16->utf16_len = 0;
396 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
397 src16->utf16, src16->utf16_len,
402 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
403 src16->utf16, src16->utf16_len,
408 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
409 src16->utf16, src16->utf16_len,
414 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
415 src16->utf16, src16->utf16_len,
416 U_FOLD_CASE_DEFAULT, status);
420 return U_UNSUPPORTED_ERROR;
424 /* check for buffer overflow, resize and retry */
425 if (*status == U_BUFFER_OVERFLOW_ERROR
426 && dest16 != src16 /* do not resize if in-place conversion */
428 icu_buf_utf16_resize(dest16, dest16_len * 2);
429 *status = U_ZERO_ERROR;
435 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
436 src16->utf16, src16->utf16_len,
441 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
442 src16->utf16, src16->utf16_len,
447 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
448 src16->utf16, src16->utf16_len,
453 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
454 src16->utf16, src16->utf16_len,
455 U_FOLD_CASE_DEFAULT, status);
459 return U_UNSUPPORTED_ERROR;
464 if (U_SUCCESS(*status)
465 && dest16_len <= dest16->utf16_cap)
466 dest16->utf16_len = dest16_len;
469 dest16->utf16[0] = (UChar) 0;
470 dest16->utf16_len = 0;
478 UErrorCode icu_sortkey8_from_utf16(UCollator *coll,
479 struct icu_buf_utf8 * dest8,
480 struct icu_buf_utf16 * src16,
484 int32_t sortkey_len = 0;
486 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
487 dest8->utf8, dest8->utf8_cap);
489 /* check for buffer overflow, resize and retry */
490 if (sortkey_len > dest8->utf8_cap) {
491 icu_buf_utf8_resize(dest8, sortkey_len * 2);
492 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
493 dest8->utf8, dest8->utf8_cap);
496 if (U_SUCCESS(*status)
498 dest8->utf8_len = sortkey_len;
500 icu_buf_utf8_clear(dest8);
507 struct icu_tokenizer * icu_tokenizer_create(const char *locale, char action,
510 struct icu_tokenizer * tokenizer
511 = (struct icu_tokenizer *) malloc(sizeof(struct icu_tokenizer));
513 strcpy(tokenizer->locale, locale);
514 tokenizer->action = action;
516 tokenizer->buf16 = 0;
517 tokenizer->token_count = 0;
518 tokenizer->token_id = 0;
519 tokenizer->token_start = 0;
520 tokenizer->token_end = 0;
523 switch(tokenizer->action) {
527 = ubrk_open(UBRK_LINE, tokenizer->locale,
533 = ubrk_open(UBRK_SENTENCE, tokenizer->locale,
539 = ubrk_open(UBRK_WORD, tokenizer->locale,
545 = ubrk_open(UBRK_CHARACTER, tokenizer->locale,
551 = ubrk_open(UBRK_TITLE, tokenizer->locale,
555 *status = U_UNSUPPORTED_ERROR;
560 /* ICU error stuff is a very funny business */
561 if (U_SUCCESS(*status))
564 /* freeing if failed */
565 icu_tokenizer_destroy(tokenizer);
569 void icu_tokenizer_destroy(struct icu_tokenizer * tokenizer)
573 ubrk_close(tokenizer->bi);
578 int icu_tokenizer_attach(struct icu_tokenizer * tokenizer,
579 struct icu_buf_utf16 * src16,
582 if (!tokenizer || !tokenizer->bi || !src16)
586 tokenizer->buf16 = src16;
587 tokenizer->token_count = 0;
588 tokenizer->token_id = 0;
589 tokenizer->token_start = 0;
590 tokenizer->token_end = 0;
592 ubrk_setText(tokenizer->bi, src16->utf16, src16->utf16_len, status);
595 if (U_FAILURE(*status))
601 int32_t icu_tokenizer_next_token(struct icu_tokenizer * tokenizer,
602 struct icu_buf_utf16 * tkn16,
605 int32_t tkn_start = 0;
610 if (!tokenizer || !tokenizer->bi
611 || !tokenizer->buf16 || !tokenizer->buf16->utf16_len)
615 never change tokenizer->buf16 and keep always invariant
616 0 <= tokenizer->token_start
617 <= tokenizer->token_end
618 <= tokenizer->buf16->utf16_len
619 returns length of token
622 if (0 == tokenizer->token_end) /* first call */
623 tkn_start = ubrk_first(tokenizer->bi);
624 else /* successive calls */
625 tkn_start = tokenizer->token_end;
627 /* get next position */
628 tkn_end = ubrk_next(tokenizer->bi);
630 /* repairing invariant at end of ubrk, which is UBRK_DONE = -1 */
631 if (UBRK_DONE == tkn_end)
632 tkn_end = tokenizer->buf16->utf16_len;
634 /* copy out if everything is well */
635 if(U_FAILURE(*status))
638 /* everything OK, now update internal state */
639 tkn_len = tkn_end - tkn_start;
642 tokenizer->token_count++;
643 tokenizer->token_id++;
645 tokenizer->token_id = 0;
647 tokenizer->token_start = tkn_start;
648 tokenizer->token_end = tkn_end;
651 /* copying into token buffer if it exists */
653 if (tkn16->utf16_cap < tkn_len)
654 icu_buf_utf16_resize(tkn16, (size_t) tkn_len * 2);
656 u_strncpy(tkn16->utf16, &(tokenizer->buf16->utf16)[tkn_start],
659 tkn16->utf16_len = tkn_len;
666 int32_t icu_tokenizer_token_id(struct icu_tokenizer * tokenizer)
668 return tokenizer->token_id;
671 int32_t icu_tokenizer_token_start(struct icu_tokenizer * tokenizer)
673 return tokenizer->token_start;
676 int32_t icu_tokenizer_token_end(struct icu_tokenizer * tokenizer)
678 return tokenizer->token_end;
681 int32_t icu_tokenizer_token_length(struct icu_tokenizer * tokenizer)
683 return (tokenizer->token_end - tokenizer->token_start);
686 int32_t icu_tokenizer_token_count(struct icu_tokenizer * tokenizer)
688 return tokenizer->token_count;
693 struct icu_normalizer * icu_normalizer_create(const char *rules, char action,
697 struct icu_normalizer * normalizer
698 = (struct icu_normalizer *) malloc(sizeof(struct icu_normalizer));
700 normalizer->action = action;
701 normalizer->trans = 0;
702 normalizer->rules16 = icu_buf_utf16_create(0);
703 icu_utf16_from_utf8_cstr(normalizer->rules16, rules, status);
705 switch(normalizer->action) {
709 = utrans_openU(normalizer->rules16->utf16,
710 normalizer->rules16->utf16_len,
713 normalizer->parse_error, status);
718 = utrans_openU(normalizer->rules16->utf16,
719 normalizer->rules16->utf16_len,
722 normalizer->parse_error, status);
725 *status = U_UNSUPPORTED_ERROR;
730 if (U_SUCCESS(*status))
733 /* freeing if failed */
734 icu_normalizer_destroy(normalizer);
739 void icu_normalizer_destroy(struct icu_normalizer * normalizer){
741 if (normalizer->rules16)
742 icu_buf_utf16_destroy(normalizer->rules16);
743 if (normalizer->trans)
744 utrans_close(normalizer->trans);
751 int icu_normalizer_normalize(struct icu_normalizer * normalizer,
752 struct icu_buf_utf16 * dest16,
753 struct icu_buf_utf16 * src16,
756 if (!normalizer || !normalizer->trans
761 if (!src16->utf16_len){ //guarding for empty source string
762 icu_buf_utf16_clear(dest16);
766 if (!icu_buf_utf16_copy(dest16, src16))
770 utrans_transUChars (normalizer->trans,
771 dest16->utf16, &(dest16->utf16_len),
773 0, &(src16->utf16_len), status);
775 if (U_FAILURE(*status))
776 icu_buf_utf16_clear(dest16);
778 return dest16->utf16_len;
784 struct icu_chain_step * icu_chain_step_create(struct icu_chain * chain,
785 enum icu_chain_step_type type,
786 const uint8_t * rule,
787 struct icu_buf_utf16 * buf16,
790 struct icu_chain_step * step = 0;
792 if(!chain || !type || !rule)
795 step = (struct icu_chain_step *) malloc(sizeof(struct icu_chain_step));
801 /* create auxilary objects */
803 case ICU_chain_step_type_display:
805 case ICU_chain_step_type_casemap:
806 step->u.casemap = icu_casemap_create((char *) chain->locale,
807 (char) rule[0], status);
809 case ICU_chain_step_type_normalize:
810 step->u.normalizer = icu_normalizer_create((char *) rule, 'f', status);
812 case ICU_chain_step_type_tokenize:
813 step->u.tokenizer = icu_tokenizer_create((char *) chain->locale,
814 (char) rule[0], status);
824 void icu_chain_step_destroy(struct icu_chain_step * step){
829 icu_chain_step_destroy(step->previous);
832 case ICU_chain_step_type_display:
834 case ICU_chain_step_type_casemap:
835 icu_casemap_destroy(step->u.casemap);
836 icu_buf_utf16_destroy(step->buf16);
838 case ICU_chain_step_type_normalize:
839 icu_normalizer_destroy(step->u.normalizer);
840 icu_buf_utf16_destroy(step->buf16);
842 case ICU_chain_step_type_tokenize:
843 icu_tokenizer_destroy(step->u.tokenizer);
844 icu_buf_utf16_destroy(step->buf16);
854 struct icu_chain * icu_chain_create(const char *locale,
859 struct icu_chain * chain
860 = (struct icu_chain *) malloc(sizeof(struct icu_chain));
862 *status = U_ZERO_ERROR;
864 strncpy((char *) chain->locale, (const char *) locale, 16);
865 chain->locale[16 - 1] = '\0';
869 chain->coll = ucol_open((const char *) chain->locale, status);
871 if (U_FAILURE(*status))
875 chain->token_count = 0;
879 chain->display8 = icu_buf_utf8_create(0);
880 chain->norm8 = icu_buf_utf8_create(0);
881 chain->sort8 = icu_buf_utf8_create(0);
883 chain->src16 = icu_buf_utf16_create(0);
891 void icu_chain_destroy(struct icu_chain * chain)
896 ucol_close(chain->coll);
898 icu_buf_utf8_destroy(chain->display8);
899 icu_buf_utf8_destroy(chain->norm8);
900 icu_buf_utf8_destroy(chain->sort8);
902 icu_buf_utf16_destroy(chain->src16);
904 icu_chain_step_destroy(chain->steps);
911 struct icu_chain * icu_chain_xml_config(const xmlNode *xml_node,
914 UErrorCode * status){
917 struct icu_chain * chain = 0;
919 *status = U_ZERO_ERROR;
922 ||xml_node->type != XML_ELEMENT_NODE
923 // || strcmp((const char *) xml_node->name, "icu_chain")
928 chain = icu_chain_create(locale, sort, status);
934 for (node = xml_node->children; node; node = node->next)
937 struct icu_chain_step * step = 0;
939 if (node->type != XML_ELEMENT_NODE)
942 xml_rule = xmlGetProp(node, (xmlChar *) "rule");
944 if (!strcmp((const char *) node->name,
945 (const char *) "casemap")){
946 step = icu_chain_insert_step(chain, ICU_chain_step_type_casemap,
947 (const uint8_t *) xml_rule, status);
949 else if (!strcmp((const char *) node->name,
950 (const char *) "normalize")){
951 step = icu_chain_insert_step(chain, ICU_chain_step_type_normalize,
952 (const uint8_t *) xml_rule, status);
954 else if (!strcmp((const char *) node->name,
955 (const char *) "tokenize")){
956 step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize,
957 (const uint8_t *) xml_rule, status);
959 else if (!strcmp((const char *) node->name,
960 (const char *) "display")){
961 step = icu_chain_insert_step(chain, ICU_chain_step_type_display,
962 (const uint8_t *) "", status);
965 if (!step || U_FAILURE(*status)){
966 icu_chain_destroy(chain);
978 struct icu_chain_step * icu_chain_insert_step(struct icu_chain * chain,
979 enum icu_chain_step_type type,
980 const uint8_t * rule,
983 struct icu_chain_step * step = 0;
984 struct icu_buf_utf16 * src16 = 0;
985 struct icu_buf_utf16 * buf16 = 0;
987 if (!chain || !type || !rule)
990 /* assign utf16 src buffers as needed */
991 if (chain->steps && chain->steps->buf16)
992 src16 = chain->steps->buf16;
993 else if (chain->src16)
994 src16 = chain->src16;
999 /* create utf16 destination buffers as needed, or */
1001 case ICU_chain_step_type_display:
1004 case ICU_chain_step_type_casemap:
1005 buf16 = icu_buf_utf16_create(0);
1007 case ICU_chain_step_type_normalize:
1008 buf16 = icu_buf_utf16_create(0);
1010 case ICU_chain_step_type_tokenize:
1011 buf16 = icu_buf_utf16_create(0);
1017 /* create actual chain step with this buffer */
1018 step = icu_chain_step_create(chain, type, rule, buf16, status);
1020 step->previous = chain->steps;
1021 chain->steps = step;
1027 int icu_chain_step_next_token(struct icu_chain * chain,
1028 struct icu_chain_step * step,
1031 struct icu_buf_utf16 * src16 = 0;
1032 int got_new_token = 0;
1034 if (!chain || !chain->src16 || !step || !step->more_tokens)
1037 /* assign utf16 src buffers as neeed, advance in previous steps
1038 tokens until non-zero token met, and setting stop condition */
1040 if (step->previous){
1041 src16 = step->previous->buf16;
1042 /* tokens might be killed in previous steps, therefore looping */
1044 while (step->need_new_token
1045 && step->previous->more_tokens
1048 = icu_chain_step_next_token(chain, step->previous, status);
1050 else { /* first step can only work once on chain->src16 input buffer */
1051 src16 = chain->src16;
1052 step->more_tokens = 0;
1059 /* stop if nothing to process */
1060 if (step->need_new_token && !got_new_token){
1061 step->more_tokens = 0;
1065 /* either an old token not finished yet, or a new token, thus
1066 perform the work, eventually put this steps output in
1067 step->buf16 or the chains UTF8 output buffers */
1069 switch(step->type) {
1070 case ICU_chain_step_type_display:
1071 icu_utf16_to_utf8(chain->display8, src16, status);
1073 case ICU_chain_step_type_casemap:
1074 icu_casemap_casemap(step->u.casemap,
1075 step->buf16, src16, status);
1077 case ICU_chain_step_type_normalize:
1078 icu_normalizer_normalize(step->u.normalizer,
1079 step->buf16, src16, status);
1081 case ICU_chain_step_type_tokenize:
1082 /* attach to new src16 token only first time during splitting */
1083 if (step->need_new_token){
1084 icu_tokenizer_attach(step->u.tokenizer, src16, status);
1085 step->need_new_token = 0;
1089 /* splitting one src16 token into multiple buf16 tokens */
1091 = icu_tokenizer_next_token(step->u.tokenizer,
1092 step->buf16, status);
1094 /* make sure to get new previous token if this one had been used up
1095 by recursive call to _same_ step */
1097 if (!step->more_tokens){
1098 step->more_tokens = icu_chain_step_next_token(chain, step, status);
1099 return step->more_tokens; // avoid one token count too much!
1108 if (U_FAILURE(*status))
1111 /* if token disappered into thin air, tell caller */
1112 /* if (!step->buf16->utf16_len && !step->more_tokens) */
1119 int icu_chain_assign_cstr(struct icu_chain * chain,
1120 const char * src8cstr,
1123 struct icu_chain_step * stp = 0;
1125 if (!chain || !src8cstr)
1128 chain->src8cstr = src8cstr;
1132 /* clear token count */
1133 chain->token_count = 0;
1135 /* clear all steps stop states */
1137 stp->more_tokens = 1;
1138 stp->need_new_token = 1;
1139 stp = stp->previous;
1142 /* finally convert UTF8 to UTF16 string if needed */
1143 if (chain->steps || chain->sort)
1144 icu_utf16_from_utf8_cstr(chain->src16, chain->src8cstr, status);
1146 if (U_FAILURE(*status))
1154 int icu_chain_next_token(struct icu_chain * chain,
1159 *status = U_ZERO_ERROR;
1164 /* special case with no steps - same as index type binary */
1166 if (chain->token_count)
1169 chain->token_count++;
1172 icu_sortkey8_from_utf16(chain->coll,
1173 chain->sort8, chain->steps->buf16,
1175 return chain->token_count;
1178 /* usual case, one or more icu chain steps existing */
1181 while(!got_token && chain->steps && chain->steps->more_tokens)
1182 got_token = icu_chain_step_next_token(chain, chain->steps, status);
1185 chain->token_count++;
1187 icu_utf16_to_utf8(chain->norm8, chain->steps->buf16, status);
1190 icu_sortkey8_from_utf16(chain->coll,
1191 chain->sort8, chain->steps->buf16,
1194 return chain->token_count;
1201 int icu_chain_token_number(struct icu_chain * chain)
1206 return chain->token_count;
1210 const char * icu_chain_token_display(struct icu_chain * chain)
1212 if (chain->display8)
1213 return icu_buf_utf8_to_cstr(chain->display8);
1218 const char * icu_chain_token_norm(struct icu_chain * chain)
1221 return chain->src8cstr;
1224 return icu_buf_utf8_to_cstr(chain->norm8);
1229 const char * icu_chain_token_sortkey(struct icu_chain * chain)
1232 return icu_buf_utf8_to_cstr(chain->sort8);
1237 const UCollator * icu_chain_get_coll(struct icu_chain * chain)
1245 #endif /* HAVE_ICU */
1253 * indent-tabs-mode: nil
1255 * vim: shiftwidth=4 tabstop=8 expandtab