annotate lib/uninorm/u-normcmp.h @ 16201:8250f2777afc

maint: update all copyright year number ranges Run "make update-copyright".
author Jim Meyering <meyering@redhat.com>
date Sun, 01 Jan 2012 10:04:58 +0100
parents 97fc9a21a8fb
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11279
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
1 /* Normalization insensitive comparison of Unicode strings.
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
2 Copyright (C) 2009-2012 Free Software Foundation, Inc.
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2009.
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 under the terms of the GNU Lesser General Public License as published
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 by the Free Software Foundation; either version 3 of the License, or
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 Lesser General Public License for more details.
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public License
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 int
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
11301
fb09a686a3f1 Rename argument.
Bruno Haible <bruno@clisp.org>
parents: 11300
diff changeset
20 uninorm_t nf, int *resultp)
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 {
11279
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
22 UNIT buf1[2048 / sizeof (UNIT)];
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
23 UNIT buf2[2048 / sizeof (UNIT)];
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 UNIT *norms1;
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 size_t norms1_length;
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 UNIT *norms2;
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 size_t norms2_length;
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 int cmp;
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* Normalize S1. */
11279
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
31 norms1_length = sizeof (buf1) / sizeof (UNIT);
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
32 norms1 = U_NORMALIZE (nf, s1, n1, buf1, &norms1_length);
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 if (norms1 == NULL)
11300
8ac7c72b439b Adjust u*_normcmp, u*_normcoll API.
Bruno Haible <bruno@clisp.org>
parents: 11279
diff changeset
34 /* errno is set here. */
8ac7c72b439b Adjust u*_normcmp, u*_normcoll API.
Bruno Haible <bruno@clisp.org>
parents: 11279
diff changeset
35 return -1;
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 /* Normalize S2. */
11279
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
38 norms2_length = sizeof (buf2) / sizeof (UNIT);
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
39 norms2 = U_NORMALIZE (nf, s2, n2, buf2, &norms2_length);
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 if (norms2 == NULL)
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
11279
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
42 if (norms1 != buf1)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11457
diff changeset
43 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11457
diff changeset
44 int saved_errno = errno;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11457
diff changeset
45 free (norms1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11457
diff changeset
46 errno = saved_errno;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11457
diff changeset
47 }
11300
8ac7c72b439b Adjust u*_normcmp, u*_normcoll API.
Bruno Haible <bruno@clisp.org>
parents: 11279
diff changeset
48 return -1;
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 }
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 /* Compare the normalized strings. */
11457
cc6b3eba9118 Use the u*_cmp functions.
Bruno Haible <bruno@clisp.org>
parents: 11301
diff changeset
52 cmp = U_CMP2 (norms1, norms1_length, norms2, norms2_length);
cc6b3eba9118 Use the u*_cmp functions.
Bruno Haible <bruno@clisp.org>
parents: 11301
diff changeset
53 if (cmp > 0)
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 cmp = 1;
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 else if (cmp < 0)
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 cmp = -1;
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
11279
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
58 if (norms2 != buf2)
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
59 free (norms2);
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
60 if (norms1 != buf1)
a73b4f6432c4 Optimize memory allocation.
Bruno Haible <bruno@clisp.org>
parents: 11272
diff changeset
61 free (norms1);
11301
fb09a686a3f1 Rename argument.
Bruno Haible <bruno@clisp.org>
parents: 11300
diff changeset
62 *resultp = cmp;
11272
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 return 0;
eb9960d53334 New module 'uninorm/u8-normcmp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 }