Fixed the asn1 for facets
[yaz-moved-to-github.git] / src / icu_sortkey.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2010 Index Data
3  * See the file LICENSE for details.
4  */
5
6 /**
7  * \file
8  * \brief sortkey utility based on ICU Collator
9  */
10
11 #if HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14
15 #if YAZ_HAVE_ICU
16 #include <yaz/xmalloc.h>
17
18 #include <yaz/icu_I18N.h>
19
20 #include <yaz/log.h>
21
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25
26 #include <unicode/ustring.h>  /* some more string fcns*/
27 #include <unicode/uchar.h>    /* char names           */
28
29 void icu_sortkey8_from_utf16(UCollator *coll,
30                              struct icu_buf_utf8 * dest8, 
31                              struct icu_buf_utf16 * src16,
32                              UErrorCode * status)
33
34     int32_t sortkey_len = 0;
35
36     sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
37                                   dest8->utf8, dest8->utf8_cap);
38
39     /* check for buffer overflow, resize and retry */
40     if (sortkey_len > dest8->utf8_cap)
41     {
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);
45     }
46
47     if (U_SUCCESS(*status)
48         && sortkey_len > 0)
49         dest8->utf8_len = sortkey_len;
50     else 
51         icu_buf_utf8_clear(dest8);
52 }
53
54
55 #endif /* YAZ_HAVE_ICU */
56
57 /*
58  * Local variables:
59  * c-basic-offset: 4
60  * c-file-style: "Stroustrup"
61  * indent-tabs-mode: nil
62  * End:
63  * vim: shiftwidth=4 tabstop=8 expandtab
64  */
65