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 The nf argument identifies the normalization form to apply after the
139 case-mapping. It can also be NULL, for no normalization. */
141 u8_casefold (const uint8_t *s, size_t n, const char *iso639_language,
143 uint8_t *resultbuf, size_t *lengthp);
145 u16_casefold (const uint16_t *s, size_t n, const char *iso639_language,
147 uint16_t *resultbuf, size_t *lengthp);
149 u32_casefold (const uint32_t *s, size_t n, const char *iso639_language,
151 uint32_t *resultbuf, size_t *lengthp);
153 /* Compare S1 and S2, ignoring differences in case and normalization.
154 The nf argument identifies the normalization form to apply after the
155 case-mapping. It can also be NULL, for no normalization.
156 If successful, set *RESULTP to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
157 return 0. Upon failure, return -1 with errno set. */
159 u8_casecmp (const uint8_t *s1, size_t n1,
160 const uint8_t *s2, size_t n2,
161 const char *iso639_language, uninorm_t nf, int *resultp);
163 u16_casecmp (const uint16_t *s1, size_t n1,
164 const uint16_t *s2, size_t n2,
165 const char *iso639_language, uninorm_t nf, int *resultp);
167 u32_casecmp (const uint32_t *s1, size_t n1,
168 const uint32_t *s2, size_t n2,
169 const char *iso639_language, uninorm_t nf, int *resultp);
171 ulc_casecmp (const char *s1, size_t n1,
172 const char *s2, size_t n2,
173 const char *iso639_language, uninorm_t nf, int *resultp);
175 /* Converts the string S of length N to a string in locale encoding, in such a
176 way that comparing uN_casexfrm (S1) and uN_casexfrm (S2) with uN_cmp2() is
177 equivalent to comparing S1 and S2 with uN_casecoll().
178 NF must be either UNINORM_NFC, UNINORM_NFKC, or NULL for no normalization. */
180 u8_casexfrm (const uint8_t *s, size_t n, const char *iso639_language,
181 uninorm_t nf, char *resultbuf, size_t *lengthp);
183 u16_casexfrm (const uint16_t *s, size_t n, const char *iso639_language,
184 uninorm_t nf, char *resultbuf, size_t *lengthp);
186 u32_casexfrm (const uint32_t *s, size_t n, const char *iso639_language,
187 uninorm_t nf, char *resultbuf, size_t *lengthp);
189 ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
190 uninorm_t nf, char *resultbuf, size_t *lengthp);
192 /* Compare S1 and S2, ignoring differences in case and normalization, using the
193 collation rules of the current locale.
194 The nf argument identifies the normalization form to apply after the
195 case-mapping. It must be either UNINORM_NFC or UNINORM_NFKC. It can also
196 be NULL, for no normalization.
197 If successful, set *RESULTP to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
198 return 0. Upon failure, return -1 with errno set. */
200 u8_casecoll (const uint8_t *s1, size_t n1,
201 const uint8_t *s2, size_t n2,
202 const char *iso639_language, uninorm_t nf, int *resultp);
204 u16_casecoll (const uint16_t *s1, size_t n1,
205 const uint16_t *s2, size_t n2,
206 const char *iso639_language, uninorm_t nf, int *resultp);
208 u32_casecoll (const uint32_t *s1, size_t n1,
209 const uint32_t *s2, size_t n2,
210 const char *iso639_language, uninorm_t nf, int *resultp);
212 ulc_casecoll (const char *s1, size_t n1,
213 const char *s2, size_t n2,
214 const char *iso639_language, uninorm_t nf, int *resultp);
217 /* Set *RESULTP to true if mapping NFD(S) to upper case is a no-op, or to false
218 otherwise, and return 0. Upon failure, return -1 with errno set. */
220 u8_is_uppercase (const uint8_t *s, size_t n,
221 const char *iso639_language,
224 u16_is_uppercase (const uint16_t *s, size_t n,
225 const char *iso639_language,
228 u32_is_uppercase (const uint32_t *s, size_t n,
229 const char *iso639_language,
232 /* Set *RESULTP to true if mapping NFD(S) to lower case is a no-op, or to false
233 otherwise, and return 0. Upon failure, return -1 with errno set. */
235 u8_is_lowercase (const uint8_t *s, size_t n,
236 const char *iso639_language,
239 u16_is_lowercase (const uint16_t *s, size_t n,
240 const char *iso639_language,
243 u32_is_lowercase (const uint32_t *s, size_t n,
244 const char *iso639_language,
247 /* Set *RESULTP to true if mapping NFD(S) to title case is a no-op, or to false
248 otherwise, and return 0. Upon failure, return -1 with errno set. */
250 u8_is_titlecase (const uint8_t *s, size_t n,
251 const char *iso639_language,
254 u16_is_titlecase (const uint16_t *s, size_t n,
255 const char *iso639_language,
258 u32_is_titlecase (const uint32_t *s, size_t n,
259 const char *iso639_language,
262 /* Set *RESULTP to true if applying case folding to NFD(S) is a no-op, or to
263 false otherwise, and return 0. Upon failure, return -1 with errno set. */
265 u8_is_casefolded (const uint8_t *s, size_t n,
266 const char *iso639_language,
269 u16_is_casefolded (const uint16_t *s, size_t n,
270 const char *iso639_language,
273 u32_is_casefolded (const uint32_t *s, size_t n,
274 const char *iso639_language,
277 /* Set *RESULTP to true if case matters for S, that is, if mapping NFD(S) to
278 either upper case or lower case or title case is not a no-op.
279 Set *RESULTP to false if NFD(S) maps to itself under the upper case mapping,
280 under the lower case mapping, and under the title case mapping; in other
281 words, when NFD(S) consists entirely of caseless characters.
282 Upon failure, return -1 with errno set. */
284 u8_is_cased (const uint8_t *s, size_t n,
285 const char *iso639_language,
288 u16_is_cased (const uint16_t *s, size_t n,
289 const char *iso639_language,
292 u32_is_cased (const uint32_t *s, size_t n,
293 const char *iso639_language,
297 /* ========================================================================= */
303 #endif /* _UNICASE_H */