1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 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 struct icu_casemap *icu_casemap_clone(struct icu_casemap *old)
59 struct icu_casemap * casemap
60 = (struct icu_casemap *) xmalloc(sizeof(struct icu_casemap));
61 casemap->action = old->action;
65 void icu_casemap_destroy(struct icu_casemap * casemap)
70 int icu_casemap_casemap(struct icu_casemap * casemap,
71 struct icu_buf_utf16 * dest16,
72 struct icu_buf_utf16 * src16,
79 return icu_utf16_casemap(dest16, src16, locale,
80 casemap->action, status);
83 int icu_utf16_casemap(struct icu_buf_utf16 * dest16,
84 struct icu_buf_utf16 * src16,
85 const char *locale, char action,
88 int32_t dest16_len = 0;
90 if (!src16->utf16_len)
91 { /* guarding for empty source string */
93 dest16->utf16[0] = (UChar) 0;
94 dest16->utf16_len = 0;
102 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
103 src16->utf16, src16->utf16_len,
108 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
109 src16->utf16, src16->utf16_len,
114 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
115 src16->utf16, src16->utf16_len,
120 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
121 src16->utf16, src16->utf16_len,
122 U_FOLD_CASE_DEFAULT, status);
126 return U_UNSUPPORTED_ERROR;
130 /* check for buffer overflow, resize and retry */
131 if (*status == U_BUFFER_OVERFLOW_ERROR
132 && dest16 != src16 /* do not resize if in-place conversion */
135 icu_buf_utf16_resize(dest16, dest16_len * 2);
136 *status = U_ZERO_ERROR;
141 dest16_len = u_strToLower(dest16->utf16, dest16->utf16_cap,
142 src16->utf16, src16->utf16_len,
147 dest16_len = u_strToUpper(dest16->utf16, dest16->utf16_cap,
148 src16->utf16, src16->utf16_len,
153 dest16_len = u_strToTitle(dest16->utf16, dest16->utf16_cap,
154 src16->utf16, src16->utf16_len,
159 dest16_len = u_strFoldCase(dest16->utf16, dest16->utf16_cap,
160 src16->utf16, src16->utf16_len,
161 U_FOLD_CASE_DEFAULT, status);
165 return U_UNSUPPORTED_ERROR;
170 if (U_SUCCESS(*status)
171 && dest16_len <= dest16->utf16_cap)
172 dest16->utf16_len = dest16_len;
176 dest16->utf16[0] = (UChar) 0;
177 dest16->utf16_len = 0;
184 #endif /* YAZ_HAVE_ICU */
189 * c-file-style: "Stroustrup"
190 * indent-tabs-mode: nil
192 * vim: shiftwidth=4 tabstop=8 expandtab