Mercurial > gnulib
annotate lib/unicase/u-casecmp.h @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
11335
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Case and normalization insensitive comparison of Unicode strings. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2009-2019 Free Software Foundation, Inc. |
11335
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 Written by Bruno Haible <bruno@clisp.org>, 2009. |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 under the terms of the GNU Lesser General Public License as published |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 by the Free Software Foundation; either version 3 of the License, or |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 (at your option) any later version. |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public License |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
11335
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 int |
11383
664a93b85ce6
New module 'unicase/ulc-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
11335
diff
changeset
|
19 FUNC (const SRC_UNIT *s1, size_t n1, const SRC_UNIT *s2, size_t n2, |
11335
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 const char *iso639_language, uninorm_t nf, int *resultp) |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 { |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 UNIT buf1[2048 / sizeof (UNIT)]; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 UNIT buf2[2048 / sizeof (UNIT)]; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 UNIT *norms1; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 size_t norms1_length; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 UNIT *norms2; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 size_t norms2_length; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 int cmp; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 /* Optimization: There is no need to do canonical composition of each string. |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 Decomposition is enough. */ |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 if (nf != NULL) |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 nf = uninorm_decomposing_form (nf); |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 /* Case-fold and normalize S1. */ |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 norms1_length = sizeof (buf1) / sizeof (UNIT); |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 norms1 = U_CASEFOLD (s1, n1, iso639_language, nf, buf1, &norms1_length); |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 if (norms1 == NULL) |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 /* errno is set here. */ |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 return -1; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 /* Case-fold and normalize S2. */ |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 norms2_length = sizeof (buf2) / sizeof (UNIT); |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 norms2 = U_CASEFOLD (s2, n2, iso639_language, nf, buf2, &norms2_length); |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 if (norms2 == NULL) |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 { |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 if (norms1 != buf1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11458
diff
changeset
|
48 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11458
diff
changeset
|
49 int saved_errno = errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11458
diff
changeset
|
50 free (norms1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11458
diff
changeset
|
51 errno = saved_errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11458
diff
changeset
|
52 } |
11335
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 return -1; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 } |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 /* Compare the normalized strings. */ |
11458
96c4e5d901b9
Use the new u*_cmp2 functions.
Bruno Haible <bruno@clisp.org>
parents:
11383
diff
changeset
|
57 cmp = U_CMP2 (norms1, norms1_length, norms2, norms2_length); |
96c4e5d901b9
Use the new u*_cmp2 functions.
Bruno Haible <bruno@clisp.org>
parents:
11383
diff
changeset
|
58 if (cmp > 0) |
11335
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 cmp = 1; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 else if (cmp < 0) |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 cmp = -1; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 if (norms2 != buf2) |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 free (norms2); |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 if (norms1 != buf1) |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 free (norms1); |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 *resultp = cmp; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 return 0; |
fdd1dfe176a5
New module 'unicase/u8-casecmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 } |