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 ulc_casecmp (const char *s1, size_t n1,
171 const char *s2, size_t n2,
172 const char *iso639_language, uninorm_t nf, int *resultp);
174 /* Converts the string S of length N to a string in locale encoding, in such a
175 way that comparing uN_casexfrm (S1) and uN_casexfrm (S2) with memcmp2() is
176 equivalent to comparing S1 and S2 with uN_casecoll().
177 NF must be either UNINORM_NFC, UNINORM_NFKC, or NULL for no normalization. */
179 u8_casexfrm (const uint8_t *s, size_t n, const char *iso639_language,
180 uninorm_t nf, char *resultbuf, size_t *lengthp);
182 u16_casexfrm (const uint16_t *s, size_t n, const char *iso639_language,
183 uninorm_t nf, char *resultbuf, size_t *lengthp);
185 u32_casexfrm (const uint32_t *s, size_t n, const char *iso639_language,
186 uninorm_t nf, char *resultbuf, size_t *lengthp);
188 ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
189 uninorm_t nf, char *resultbuf, size_t *lengthp);
191 /* Compare S1 and S2, ignoring differences in case and normalization, using the
192 collation rules of the current locale.
193 The nf argument identifies the normalization form to apply after the
194 case-mapping. It must be either UNINORM_NFC or UNINORM_NFKC. It can also
195 be NULL, for no normalization.
196 If successful, set *RESULTP to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
197 return 0. Upon failure, return -1 with errno set. */
199 u8_casecoll (const uint8_t *s1, size_t n1,
200 const uint8_t *s2, size_t n2,
201 const char *iso639_language, uninorm_t nf, int *resultp);
203 u16_casecoll (const uint16_t *s1, size_t n1,
204 const uint16_t *s2, size_t n2,
205 const char *iso639_language, uninorm_t nf, int *resultp);
207 u32_casecoll (const uint32_t *s1, size_t n1,
208 const uint32_t *s2, size_t n2,
209 const char *iso639_language, uninorm_t nf, int *resultp);
212 /* Set *RESULTP to true if mapping NFD(S) to upper case is a no-op, or to false
213 otherwise, and return 0. Upon failure, return -1 with errno set. */
215 u8_is_uppercase (const uint8_t *s, size_t n,
216 const char *iso639_language,
219 u16_is_uppercase (const uint16_t *s, size_t n,
220 const char *iso639_language,
223 u32_is_uppercase (const uint32_t *s, size_t n,
224 const char *iso639_language,
227 /* Set *RESULTP to true if mapping NFD(S) to lower case is a no-op, or to false
228 otherwise, and return 0. Upon failure, return -1 with errno set. */
230 u8_is_lowercase (const uint8_t *s, size_t n,
231 const char *iso639_language,
234 u16_is_lowercase (const uint16_t *s, size_t n,
235 const char *iso639_language,
238 u32_is_lowercase (const uint32_t *s, size_t n,
239 const char *iso639_language,
242 /* Set *RESULTP to true if mapping NFD(S) to title case is a no-op, or to false
243 otherwise, and return 0. Upon failure, return -1 with errno set. */
245 u8_is_titlecase (const uint8_t *s, size_t n,
246 const char *iso639_language,
249 u16_is_titlecase (const uint16_t *s, size_t n,
250 const char *iso639_language,
253 u32_is_titlecase (const uint32_t *s, size_t n,
254 const char *iso639_language,
257 /* Set *RESULTP to true if applying case folding to NFD(S) is a no-op, or to
258 false otherwise, and return 0. Upon failure, return -1 with errno set. */
260 u8_is_casefolded (const uint8_t *s, size_t n,
261 const char *iso639_language,
264 u16_is_casefolded (const uint16_t *s, size_t n,
265 const char *iso639_language,
268 u32_is_casefolded (const uint32_t *s, size_t n,
269 const char *iso639_language,
272 /* Set *RESULTP to true if case matters for S, that is, if mapping NFD(S) to
273 either upper case or lower case or title case is not a no-op.
274 Set *RESULTP to false if NFD(S) maps to itself under the upper case mapping,
275 under the lower case mapping, and under the title case mapping; in other
276 words, when NFD(S) consists entirely of caseless characters.
277 Upon failure, return -1 with errno set. */
279 u8_is_cased (const uint8_t *s, size_t n,
280 const char *iso639_language,
283 u16_is_cased (const uint16_t *s, size_t n,
284 const char *iso639_language,
287 u32_is_cased (const uint32_t *s, size_t n,
288 const char *iso639_language,
292 /* ========================================================================= */
298 #endif /* _UNICASE_H */