moved working ICU sorting into YAZ unittest test_icu_I18N.c
[pazpar2-moved-to-github.git] / src / icu_I18N.h
1 /* $Id: icu_I18N.h,v 1.5 2007-05-07 09:31:36 marc Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #ifndef ICU_I18NL_H
23 #define ICU_I18NL_H
24
25 #ifdef HAVE_ICU
26
27 #include <yaz/nmem.h>
28
29
30 #include <unicode/utypes.h>   /* Basic ICU data types */
31 #include <unicode/uchar.h>    /* char names           */
32
33 //#include <unicode/ustdio.h>
34 #include <unicode/ucol.h> 
35 //#include <unicode/ucnv.h>     /* C   Converter API    */
36 //#include <unicode/ustring.h>  /* some more string fcns*/
37 //#include <unicode/uloc.h>
38 //#include <unicode/ubrk.h>
39 //#include <unicode/unistr.h>
40
41
42 int icu_check_status (UErrorCode status);
43
44 struct icu_buf_utf16
45 {
46   UChar * utf16;
47   int32_t utf16_len;
48   int32_t utf16_cap;
49 };
50
51 struct icu_buf_utf16 * icu_buf_utf16_create(size_t capacity);
52 struct icu_buf_utf16 * icu_buf_utf16_resize(struct icu_buf_utf16 * buf16,
53                                             size_t capacity);
54 void icu_buf_utf16_destroy(struct icu_buf_utf16 * buf16);
55
56
57
58 struct icu_buf_utf8
59 {
60   uint8_t * utf8;
61   int32_t utf8_len;
62   int32_t utf8_cap;
63 };
64
65 struct icu_buf_utf8 * icu_buf_utf8_create(size_t capacity);
66 struct icu_buf_utf8 * icu_buf_utf8_resize(struct icu_buf_utf8 * buf8,
67                                           size_t capacity);
68 void icu_buf_utf8_destroy(struct icu_buf_utf8 * buf8);
69
70
71 UErrorCode icu_utf16_from_utf8(struct icu_buf_utf16 * dest16,
72                                struct icu_buf_utf8 * src8,
73                                UErrorCode * status);
74
75 UErrorCode icu_utf16_from_utf8_cstr(struct icu_buf_utf16 * dest16,
76                                     const char * src8cstr,
77                                     UErrorCode * status);
78
79 UErrorCode icu_sortkey8_from_utf16(UCollator *coll,
80                                    struct icu_buf_utf8 * dest8, 
81                                    struct icu_buf_utf16 * src16,
82                                    UErrorCode * status);
83
84
85
86
87
88
89
90
91
92 // CRAP to Follow here ...
93
94 #if 0
95 struct icu_termmap
96 {
97     char * sort_key;   // standard C string '\0' terminated 
98     char * norm_term;  // standard C utf-8 string
99     char * disp_term;  // standard C utf-8 string
100 };
101
102 struct icu_termmap * icu_termmap_create(NMEM nmem);
103
104 int icu_termmap_cmp(const void *vp1, const void *vp2);
105
106 char * icu_casemap(NMEM nmem, char *buf, size_t buf_cap, 
107                    size_t *dest8_len,  const char *src8,
108                    const char *locale, char action);
109
110 char * icu_sortmap(NMEM nmem, char *buf, size_t buf_cap, 
111                    size_t *dest8_len,  const char *src8,
112                    const char *locale);
113
114 #endif // 0
115
116
117 #endif // HAVE_ICU
118 #endif // ICU_I18NL_H