1 /* Unicode character case mappings.
2 Copyright (C) 2002, 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 /* ========================================================================= */
37 /* Character case mappings.
38 These mappings are locale and context independent.
39 WARNING! These functions are not sufficient for languages such as German.
40 Better use the functions below that treat an entire string at once and are
43 /* Return the uppercase mapping of a Unicode character. */
45 uc_toupper (ucs4_t uc);
47 /* Return the lowercase mapping of a Unicode character. */
49 uc_tolower (ucs4_t uc);
51 /* Return the titlecase mapping of a Unicode character. */
53 uc_totitle (ucs4_t uc);
55 /* ========================================================================= */
57 /* String case mappings. */
59 /* These functions are locale dependent. The iso639_language argument
60 identifies the language (e.g. "tr" for Turkish). NULL means to use
61 locale independent case mappings. */
63 /* Return the ISO 639 language code of the current locale.
64 Return "" if it is unknown, or in the "C" locale. */
66 uc_locale_language (void);
70 All functions prefixed with u8_ operate on UTF-8 encoded strings.
71 Their unit is an uint8_t (1 byte).
73 All functions prefixed with u16_ operate on UTF-16 encoded strings.
74 Their unit is an uint16_t (a 2-byte word).
76 All functions prefixed with u32_ operate on UCS-4 encoded strings.
77 Their unit is an uint32_t (a 4-byte word).
79 All argument pairs (s, n) denote a Unicode string s[0..n-1] with exactly
82 Functions returning a string result take a (resultbuf, lengthp) argument
83 pair. If resultbuf is not NULL and the result fits into *lengthp units,
84 it is put in resultbuf, and resultbuf is returned. Otherwise, a freshly
85 allocated string is returned. In both cases, *lengthp is set to the
86 length (number of units) of the returned string. In case of error,
87 NULL is returned and errno is set. */
89 /* Return the uppercase mapping of a string.
90 The nf argument identifies the normalization form to apply after the
91 case-mapping. It can also be NULL, for no normalization. */
93 u8_toupper (const uint8_t *s, size_t n, const char *iso639_language,
95 uint8_t *resultbuf, size_t *lengthp);
97 u16_toupper (const uint16_t *s, size_t n, const char *iso639_language,
99 uint16_t *resultbuf, size_t *lengthp);
101 u32_toupper (const uint32_t *s, size_t n, const char *iso639_language,
103 uint32_t *resultbuf, size_t *lengthp);
105 /* Return the lowercase mapping of a string.
106 The nf argument identifies the normalization form to apply after the
107 case-mapping. It can also be NULL, for no normalization. */
109 u8_tolower (const uint8_t *s, size_t n, const char *iso639_language,
111 uint8_t *resultbuf, size_t *lengthp);
113 u16_tolower (const uint16_t *s, size_t n, const char *iso639_language,
115 uint16_t *resultbuf, size_t *lengthp);
117 u32_tolower (const uint32_t *s, size_t n, const char *iso639_language,
119 uint32_t *resultbuf, size_t *lengthp);
121 /* Return the titlecase mapping of a string.
122 The nf argument identifies the normalization form to apply after the
123 case-mapping. It can also be NULL, for no normalization. */
125 u8_totitle (const uint8_t *s, size_t n, const char *iso639_language,
127 uint8_t *resultbuf, size_t *lengthp);
129 u16_totitle (const uint16_t *s, size_t n, const char *iso639_language,
131 uint16_t *resultbuf, size_t *lengthp);
133 u32_totitle (const uint32_t *s, size_t n, const char *iso639_language,
135 uint32_t *resultbuf, size_t *lengthp);
137 /* Return the case folded string.
138 Comparing uN_casefold (S1) and uN_casefold (S2) with uN_cmp2() is equivalent
139 to comparing S1 and S2 with uN_casecmp().
140 The nf argument identifies the normalization form to apply after the
141 case-mapping. It can also be NULL, for no normalization. */
143 u8_casefold (const uint8_t *s, size_t n, const char *iso639_language,
145 uint8_t *resultbuf, size_t *lengthp);
147 u16_casefold (const uint16_t *s, size_t n, const char *iso639_language,
149 uint16_t *resultbuf, size_t *lengthp);
151 u32_casefold (const uint32_t *s, size_t n, const char *iso639_language,
153 uint32_t *resultbuf, size_t *lengthp);
155 /* Compare S1 and S2, ignoring differences in case and normalization.
156 The nf argument identifies the normalization form to apply after the
157 case-mapping. It can also be NULL, for no normalization.
158 If successful, set *RESULTP to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
159 return 0. Upon failure, return -1 with errno set. */
161 u8_casecmp (const uint8_t *s1, size_t n1,
162 const uint8_t *s2, size_t n2,
163 const char *iso639_language, uninorm_t nf, int *resultp);
165 u16_casecmp (const uint16_t *s1, size_t n1,
166 const uint16_t *s2, size_t n2,
167 const char *iso639_language, uninorm_t nf, int *resultp);
169 u32_casecmp (const uint32_t *s1, size_t n1,
170 const uint32_t *s2, size_t n2,
171 const char *iso639_language, uninorm_t nf, int *resultp);
173 ulc_casecmp (const char *s1, size_t n1,
174 const char *s2, size_t n2,
175 const char *iso639_language, uninorm_t nf, int *resultp);
177 /* Convert the string S of length N to a NUL-terminated byte sequence, in such
178 a way that comparing uN_casexfrm (S1) and uN_casexfrm (S2) with the gnulib
179 function memcmp2() is equivalent to comparing S1 and S2 with uN_casecoll().
180 NF must be either UNINORM_NFC, UNINORM_NFKC, or NULL for no normalization. */
182 u8_casexfrm (const uint8_t *s, size_t n, const char *iso639_language,
183 uninorm_t nf, char *resultbuf, size_t *lengthp);
185 u16_casexfrm (const uint16_t *s, size_t n, const char *iso639_language,
186 uninorm_t nf, char *resultbuf, size_t *lengthp);
188 u32_casexfrm (const uint32_t *s, size_t n, const char *iso639_language,
189 uninorm_t nf, char *resultbuf, size_t *lengthp);
191 ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
192 uninorm_t nf, char *resultbuf, size_t *lengthp);
194 /* Compare S1 and S2, ignoring differences in case and normalization, using the
195 collation rules of the current locale.
196 The nf argument identifies the normalization form to apply after the
197 case-mapping. It must be either UNINORM_NFC or UNINORM_NFKC. It can also
198 be NULL, for no normalization.
199 If successful, set *RESULTP to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
200 return 0. Upon failure, return -1 with errno set. */
202 u8_casecoll (const uint8_t *s1, size_t n1,
203 const uint8_t *s2, size_t n2,
204 const char *iso639_language, uninorm_t nf, int *resultp);
206 u16_casecoll (const uint16_t *s1, size_t n1,
207 const uint16_t *s2, size_t n2,
208 const char *iso639_language, uninorm_t nf, int *resultp);
210 u32_casecoll (const uint32_t *s1, size_t n1,
211 const uint32_t *s2, size_t n2,
212 const char *iso639_language, uninorm_t nf, int *resultp);
214 ulc_casecoll (const char *s1, size_t n1,
215 const char *s2, size_t n2,
216 const char *iso639_language, uninorm_t nf, int *resultp);
219 /* Set *RESULTP to true if mapping NFD(S) to upper case is a no-op, or to false
220 otherwise, and return 0. Upon failure, return -1 with errno set. */
222 u8_is_uppercase (const uint8_t *s, size_t n,
223 const char *iso639_language,
226 u16_is_uppercase (const uint16_t *s, size_t n,
227 const char *iso639_language,
230 u32_is_uppercase (const uint32_t *s, size_t n,
231 const char *iso639_language,
234 /* Set *RESULTP to true if mapping NFD(S) to lower case is a no-op, or to false
235 otherwise, and return 0. Upon failure, return -1 with errno set. */
237 u8_is_lowercase (const uint8_t *s, size_t n,
238 const char *iso639_language,
241 u16_is_lowercase (const uint16_t *s, size_t n,
242 const char *iso639_language,
245 u32_is_lowercase (const uint32_t *s, size_t n,
246 const char *iso639_language,
249 /* Set *RESULTP to true if mapping NFD(S) to title case is a no-op, or to false
250 otherwise, and return 0. Upon failure, return -1 with errno set. */
252 u8_is_titlecase (const uint8_t *s, size_t n,
253 const char *iso639_language,
256 u16_is_titlecase (const uint16_t *s, size_t n,
257 const char *iso639_language,
260 u32_is_titlecase (const uint32_t *s, size_t n,
261 const char *iso639_language,
264 /* Set *RESULTP to true if applying case folding to NFD(S) is a no-op, or to
265 false otherwise, and return 0. Upon failure, return -1 with errno set. */
267 u8_is_casefolded (const uint8_t *s, size_t n,
268 const char *iso639_language,
271 u16_is_casefolded (const uint16_t *s, size_t n,
272 const char *iso639_language,
275 u32_is_casefolded (const uint32_t *s, size_t n,
276 const char *iso639_language,
279 /* Set *RESULTP to true if case matters for S, that is, if mapping NFD(S) to
280 either upper case or lower case or title case is not a no-op.
281 Set *RESULTP to false if NFD(S) maps to itself under the upper case mapping,
282 under the lower case mapping, and under the title case mapping; in other
283 words, when NFD(S) consists entirely of caseless characters.
284 Upon failure, return -1 with errno set. */
286 u8_is_cased (const uint8_t *s, size_t n,
287 const char *iso639_language,
290 u16_is_cased (const uint16_t *s, size_t n,
291 const char *iso639_language,
294 u32_is_cased (const uint32_t *s, size_t n,
295 const char *iso639_language,
299 /* ========================================================================= */
305 #endif /* _UNICASE_H */