1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 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;
35 /* we'll fake a capacity of one less, because it turns out
36 that ucol_getSortKey writes ONE character too much */
37 int32_t cap = dest8->utf8_cap ? dest8->utf8_cap - 1 : 0;
39 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
42 /* check for buffer overflow, resize and retry */
43 if (sortkey_len > cap)
45 icu_buf_utf8_resize(dest8, sortkey_len * 2);
46 sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
47 dest8->utf8, dest8->utf8_cap);
50 if (U_SUCCESS(*status)
52 dest8->utf8_len = sortkey_len;
54 icu_buf_utf8_clear(dest8);
58 #endif /* YAZ_HAVE_ICU */
63 * c-file-style: "Stroustrup"
64 * indent-tabs-mode: nil
66 * vim: shiftwidth=4 tabstop=8 expandtab