1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
8 * \brief sortkey utility based on ICU Collator
16 #include <yaz/xmalloc.h>
18 #include <yaz/icu_I18N.h>
26 #include <unicode/ustring.h> /* some more string fcns*/
27 #include <unicode/uchar.h> /* char names */
29 void icu_sortkey8_from_utf16(UCollator *coll,
30 struct icu_buf_utf8 * dest8,
31 struct icu_buf_utf16 * src16,
34 int32_t sortkey_len = 0;
36 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
37 dest8->utf8, dest8->utf8_cap);
39 /* check for buffer overflow, resize and retry */
40 if (sortkey_len > dest8->utf8_cap)
42 icu_buf_utf8_resize(dest8, sortkey_len * 2);
43 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
44 dest8->utf8, dest8->utf8_cap);
47 if (U_SUCCESS(*status)
49 dest8->utf8_len = sortkey_len;
51 icu_buf_utf8_clear(dest8);
55 #endif /* YAZ_HAVE_ICU */
60 * c-file-style: "Stroustrup"
61 * indent-tabs-mode: nil
63 * vim: shiftwidth=4 tabstop=8 expandtab