1 /* Test whether case matters for a Unicode string.
2 Copyright (C) 2009-2012 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2009.
5 This program is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 FUNC (const UNIT *s, size_t n, const char *iso639_language,
22 UNIT normsbuf[2048 / sizeof (UNIT)];
25 UNIT mappedbuf[2048 / sizeof (UNIT)];
31 /* Apply canonical decomposition to S. */
32 norms_length = sizeof (normsbuf) / sizeof (UNIT);
33 norms = U_NORMALIZE (UNINORM_NFD, s, n, normsbuf, &norms_length);
35 /* errno is set here. */
38 mapped_length = sizeof (mappedbuf) / sizeof (UNIT);
40 /* Apply toupper mapping. */
41 mapped_toupper = U_TOUPPER (norms, norms_length, iso639_language, NULL,
42 mappedbuf, &mapped_length);
43 if (mapped_toupper == NULL)
47 if (!(mapped_length == norms_length
48 && U_CMP (mapped_toupper, norms, norms_length) == 0))
50 if (mapped_toupper != mappedbuf)
51 free (mapped_toupper);
55 /* Apply tolower mapping. */
56 mapped_tolower = U_TOLOWER (norms, norms_length, iso639_language, NULL,
57 mapped_toupper, &mapped_length);
58 if (mapped_tolower == NULL)
60 if (mapped_toupper != mappedbuf)
62 int saved_errno = errno;
63 free (mapped_toupper);
69 if (mapped_toupper != mapped_tolower && mapped_toupper != mappedbuf)
70 free (mapped_toupper);
73 if (!(mapped_length == norms_length
74 && U_CMP (mapped_tolower, norms, norms_length) == 0))
76 if (mapped_tolower != mappedbuf)
77 free (mapped_tolower);
81 /* Apply totitle mapping. */
82 mapped_totitle = U_TOTITLE (norms, norms_length, iso639_language, NULL,
83 mapped_tolower, &mapped_length);
84 if (mapped_totitle == NULL)
86 if (mapped_tolower != mappedbuf)
88 int saved_errno = errno;
89 free (mapped_tolower);
95 if (mapped_tolower != mapped_totitle && mapped_tolower != mappedbuf)
96 free (mapped_tolower);
99 if (!(mapped_length == norms_length
100 && U_CMP (mapped_totitle, norms, norms_length) == 0))
102 if (mapped_totitle != mappedbuf)
103 free (mapped_totitle);
107 if (mapped_totitle != mappedbuf)
108 free (mapped_totitle);
109 if (norms != normsbuf)
115 if (norms != normsbuf)
121 if (norms != normsbuf)
123 int saved_errno = errno;