1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
8 * \brief ICU character case (u_strToUpper, etc)
16 #include <yaz/xmalloc.h>
18 #include <yaz/icu_I18N.h>
26 #include <unicode/ustring.h>
33 struct icu_casemap * icu_casemap_create(char action, UErrorCode *status)
35 struct icu_casemap * casemap
36 = (struct icu_casemap *) xmalloc(sizeof(struct icu_casemap));
37 casemap->action = action;
39 switch (casemap->action)
51 icu_casemap_destroy(casemap);
57 void icu_casemap_destroy(struct icu_casemap * casemap)
62 int icu_casemap_casemap(struct icu_casemap * casemap,
63 struct icu_buf_utf16 * dest16,
64 struct icu_buf_utf16 * src16,
71 return icu_utf16_casemap(dest16, src16, locale,
72 casemap->action, status);
75 int icu_utf16_casemap(struct icu_buf_utf16 * dest16,
76 struct icu_buf_utf16 * src16,
77 const char *locale, char action,
80 int32_t dest16_len = 0;
82 if (!src16->utf16_len)
83 { /* guarding for empty source string */
85 dest16->utf16[0] = (UChar) 0;
86 dest16->utf16_len = 0;
94 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
95 src16->utf16, src16->utf16_len,
100 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
101 src16->utf16, src16->utf16_len,
106 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
107 src16->utf16, src16->utf16_len,
112 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
113 src16->utf16, src16->utf16_len,
114 U_FOLD_CASE_DEFAULT, status);
118 return U_UNSUPPORTED_ERROR;
122 /* check for buffer overflow, resize and retry */
123 if (*status == U_BUFFER_OVERFLOW_ERROR
124 && dest16 != src16 /* do not resize if in-place conversion */
127 icu_buf_utf16_resize(dest16, dest16_len * 2);
128 *status = U_ZERO_ERROR;
133 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
134 src16->utf16, src16->utf16_len,
139 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
140 src16->utf16, src16->utf16_len,
145 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
146 src16->utf16, src16->utf16_len,
151 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
152 src16->utf16, src16->utf16_len,
153 U_FOLD_CASE_DEFAULT, status);
157 return U_UNSUPPORTED_ERROR;
162 if (U_SUCCESS(*status)
163 && dest16_len <= dest16->utf16_cap)
164 dest16->utf16_len = dest16_len;
168 dest16->utf16[0] = (UChar) 0;
169 dest16->utf16_len = 0;
176 #endif /* YAZ_HAVE_ICU */
181 * c-file-style: "Stroustrup"
182 * indent-tabs-mode: nil
184 * vim: shiftwidth=4 tabstop=8 expandtab