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/>. */
34 /* ========================================================================= */
36 /* Character case mappings.
37 These mappings are locale and context independent.
38 WARNING! These functions are not sufficient for languages such as German.
39 Better use the functions below that treat an entire string at once and are
42 /* Return the uppercase mapping of a Unicode character. */
44 uc_toupper (ucs4_t uc);
46 /* Return the lowercase mapping of a Unicode character. */
48 uc_tolower (ucs4_t uc);
50 /* Return the titlecase mapping of a Unicode character. */
52 uc_totitle (ucs4_t uc);
54 /* ========================================================================= */
56 /* String case mappings. */
58 /* These functions are locale dependent. The iso639_language argument
59 identifies the language (e.g. "tr" for Turkish). NULL means to use
60 locale independent case mappings. */
62 /* Return the ISO 639 language code of the current locale.
63 Return "" if it is unknown, or in the "C" locale. */
65 uc_locale_language (void);
69 All functions prefixed with u8_ operate on UTF-8 encoded strings.
70 Their unit is an uint8_t (1 byte).
72 All functions prefixed with u16_ operate on UTF-16 encoded strings.
73 Their unit is an uint16_t (a 2-byte word).
75 All functions prefixed with u32_ operate on UCS-4 encoded strings.
76 Their unit is an uint32_t (a 4-byte word).
78 All argument pairs (s, n) denote a Unicode string s[0..n-1] with exactly
81 Functions returning a string result take a (resultbuf, lengthp) argument
82 pair. If resultbuf is not NULL and the result fits into *lengthp units,
83 it is put in resultbuf, and resultbuf is returned. Otherwise, a freshly
84 allocated string is returned. In both cases, *lengthp is set to the
85 length (number of units) of the returned string. In case of error,
86 NULL is returned and errno is set. */
88 /* Return the uppercase mapping of a string.
89 The nf argument identifies the normalization form to apply after the
90 case-mapping. It can also be NULL, for no normalization. */
92 u8_toupper (const uint8_t *s, size_t n, const char *iso639_language,
94 uint8_t *resultbuf, size_t *lengthp);
96 u16_toupper (const uint16_t *s, size_t n, const char *iso639_language,
98 uint16_t *resultbuf, size_t *lengthp);
100 u32_toupper (const uint32_t *s, size_t n, const char *iso639_language,
102 uint32_t *resultbuf, size_t *lengthp);
104 /* Return the lowercase mapping of a string.
105 The nf argument identifies the normalization form to apply after the
106 case-mapping. It can also be NULL, for no normalization. */
108 u8_tolower (const uint8_t *s, size_t n, const char *iso639_language,
110 uint8_t *resultbuf, size_t *lengthp);
112 u16_tolower (const uint16_t *s, size_t n, const char *iso639_language,
114 uint16_t *resultbuf, size_t *lengthp);
116 u32_tolower (const uint32_t *s, size_t n, const char *iso639_language,
118 uint32_t *resultbuf, size_t *lengthp);
120 /* Return the titlecase mapping of a string.
121 The nf argument identifies the normalization form to apply after the
122 case-mapping. It can also be NULL, for no normalization. */
124 u8_totitle (const uint8_t *s, size_t n, const char *iso639_language,
126 uint8_t *resultbuf, size_t *lengthp);
128 u16_totitle (const uint16_t *s, size_t n, const char *iso639_language,
130 uint16_t *resultbuf, size_t *lengthp);
132 u32_totitle (const uint32_t *s, size_t n, const char *iso639_language,
134 uint32_t *resultbuf, size_t *lengthp);
136 /* Return the case folded string.
137 The nf argument identifies the normalization form to apply after the
138 case-mapping. It can also be NULL, for no normalization. */
140 u8_casefold (const uint8_t *s, size_t n, const char *iso639_language,
142 uint8_t *resultbuf, size_t *lengthp);
144 u16_casefold (const uint16_t *s, size_t n, const char *iso639_language,
146 uint16_t *resultbuf, size_t *lengthp);
148 u32_casefold (const uint32_t *s, size_t n, const char *iso639_language,
150 uint32_t *resultbuf, size_t *lengthp);
152 /* Compare S1 and S2, ignoring differences in case and normalization.
153 The nf argument identifies the normalization form to apply after the
154 case-mapping. It can also be NULL, for no normalization.
155 If successful, set *RESULTP to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
156 return 0. Upon failure, return -1 with errno set. */
158 u8_casecmp (const uint8_t *s1, size_t n1,
159 const uint8_t *s2, size_t n2,
160 const char *iso639_language, uninorm_t nf, int *resultp);
162 u16_casecmp (const uint16_t *s1, size_t n1,
163 const uint16_t *s2, size_t n2,
164 const char *iso639_language, uninorm_t nf, int *resultp);
166 u32_casecmp (const uint32_t *s1, size_t n1,
167 const uint32_t *s2, size_t n2,
168 const char *iso639_language, uninorm_t nf, int *resultp);
170 /* Converts the string S of length N to a string in locale encoding, in such a
171 way that comparing uN_casexfrm (S1) and uN_casexfrm (S2) with memcmp2() is
172 equivalent to comparing S1 and S2 with uN_casecoll().
173 NF must be either UNINORM_NFC, UNINORM_NFKC, or NULL for no normalization. */
175 u8_casexfrm (const uint8_t *s, size_t n, const char *iso639_language,
176 uninorm_t nf, char *resultbuf, size_t *lengthp);
178 u16_casexfrm (const uint16_t *s, size_t n, const char *iso639_language,
179 uninorm_t nf, char *resultbuf, size_t *lengthp);
181 u32_casexfrm (const uint32_t *s, size_t n, const char *iso639_language,
182 uninorm_t nf, char *resultbuf, size_t *lengthp);
184 /* Compare S1 and S2, ignoring differences in case and normalization, using the
185 collation rules of the current locale.
186 The nf argument identifies the normalization form to apply after the
187 case-mapping. It must be either UNINORM_NFC or UNINORM_NFKC. It can also
188 be NULL, for no normalization.
189 If successful, set *RESULTP to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
190 return 0. Upon failure, return -1 with errno set. */
192 u8_casecoll (const uint8_t *s1, size_t n1,
193 const uint8_t *s2, size_t n2,
194 const char *iso639_language, uninorm_t nf, int *resultp);
196 u16_casecoll (const uint16_t *s1, size_t n1,
197 const uint16_t *s2, size_t n2,
198 const char *iso639_language, uninorm_t nf, int *resultp);
200 u32_casecoll (const uint32_t *s1, size_t n1,
201 const uint32_t *s2, size_t n2,
202 const char *iso639_language, uninorm_t nf, int *resultp);
205 /* Set *RESULTP to true if mapping NFD(S) to upper case is a no-op, or to false
206 otherwise, and return 0. Upon failure, return -1 with errno set. */
208 u8_is_uppercase (const uint8_t *s, size_t n,
209 const char *iso639_language,
212 u16_is_uppercase (const uint16_t *s, size_t n,
213 const char *iso639_language,
216 u32_is_uppercase (const uint32_t *s, size_t n,
217 const char *iso639_language,
220 /* Set *RESULTP to true if mapping NFD(S) to lower case is a no-op, or to false
221 otherwise, and return 0. Upon failure, return -1 with errno set. */
223 u8_is_lowercase (const uint8_t *s, size_t n,
224 const char *iso639_language,
227 u16_is_lowercase (const uint16_t *s, size_t n,
228 const char *iso639_language,
231 u32_is_lowercase (const uint32_t *s, size_t n,
232 const char *iso639_language,
235 /* Set *RESULTP to true if mapping NFD(S) to title case is a no-op, or to false
236 otherwise, and return 0. Upon failure, return -1 with errno set. */
238 u8_is_titlecase (const uint8_t *s, size_t n,
239 const char *iso639_language,
242 u16_is_titlecase (const uint16_t *s, size_t n,
243 const char *iso639_language,
246 u32_is_titlecase (const uint32_t *s, size_t n,
247 const char *iso639_language,
250 /* Set *RESULTP to true if applying case folding to NFD(S) is a no-op, or to
251 false otherwise, and return 0. Upon failure, return -1 with errno set. */
253 u8_is_casefolded (const uint8_t *s, size_t n,
254 const char *iso639_language,
257 u16_is_casefolded (const uint16_t *s, size_t n,
258 const char *iso639_language,
261 u32_is_casefolded (const uint32_t *s, size_t n,
262 const char *iso639_language,
265 /* Set *RESULTP to true if case matters for S, that is, if mapping NFD(S) to
266 either upper case or lower case or title case is not a no-op.
267 Set *RESULTP to false if NFD(S) maps to itself under the upper case mapping,
268 under the lower case mapping, and under the title case mapping; in other
269 words, when NFD(S) consists entirely of caseless characters.
270 Upon failure, return -1 with errno set. */
272 u8_is_cased (const uint8_t *s, size_t n,
273 const char *iso639_language,
276 u16_is_cased (const uint16_t *s, size_t n,
277 const char *iso639_language,
280 u32_is_cased (const uint32_t *s, size_t n,
281 const char *iso639_language,
285 /* ========================================================================= */
291 #endif /* _UNICASE_H */