annotate lib/mbmemcasecoll.c @ 17605:23cb5b2fd95b

relocatable-perl: like relocatable-script, but for Perl scripts * build-aux/relocatable.pl.in: Add. * doc/relocatable-maint.texi: Add documentation. * modules/relocatable-perl: Add.
author Reuben Thomas <rrt@sc3d.org>
date Thu, 09 Jan 2014 22:31:42 +0000
parents 344018b6e5d7
children ab58d4870664
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Locale-specific case-ignoring memory comparison.
17587
344018b6e5d7 maint: update copyright
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
2 Copyright (C) 2001, 2009-2014 Free Software Foundation, Inc.
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2001.
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 under the terms of the GNU Lesser General Public License as published
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 by the Free Software Foundation; either version 3 of the License, or
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 Lesser General Public License for more details.
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public License
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "mbmemcasecoll.h"
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <errno.h>
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdlib.h>
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <string.h>
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 /* Get tolower(). */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <ctype.h>
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* Get mbstate_t, mbrtowc(), wcrtomb(). */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #include <wchar.h>
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 /* Get towlower(). */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #include <wctype.h>
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #include "malloca.h"
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 #include "memcmp2.h"
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #include "memcoll.h"
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 /* Apply towlower() to the multibyte character sequence in INBUF, storing the
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 result as a multibyte character sequence in OUTBUF. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 static size_t
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 apply_towlower (const char *inbuf, size_t inbufsize,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
46 char *outbuf, size_t outbufsize)
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 char *outbuf_orig = outbuf;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 size_t remaining;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 remaining = inbufsize;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 while (remaining > 0)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 wchar_t wc1;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 size_t n1;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 mbstate_t state;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 memset (&state, '\0', sizeof (mbstate_t));
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 n1 = mbrtowc (&wc1, inbuf, remaining, &state);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 if (n1 == (size_t)(-2))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
61 break;
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 if (n1 != (size_t)(-1))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
63 {
13721
5cea8d40bf2c Fix endless loop in mbmemcasecoll.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
64 wint_t wc2;
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65
13721
5cea8d40bf2c Fix endless loop in mbmemcasecoll.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
66 if (n1 == 0) /* NUL character? */
5cea8d40bf2c Fix endless loop in mbmemcasecoll.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
67 n1 = 1;
5cea8d40bf2c Fix endless loop in mbmemcasecoll.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
68
5cea8d40bf2c Fix endless loop in mbmemcasecoll.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
69 wc2 = towlower (wc1);
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
70 if (wc2 != wc1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
71 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
72 size_t n2;
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
74 memset (&state, '\0', sizeof (mbstate_t));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
75 n2 = wcrtomb (outbuf, wc2, &state);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
76 if (n2 != (size_t)(-1))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
77 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
78 /* Store the translated multibyte character. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
79 inbuf += n1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
80 remaining -= n1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
81 outbuf += n2;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
82 continue;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
83 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
84 }
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
86 /* Nothing to translate. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
87 memcpy (outbuf, inbuf, n1);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
88 inbuf += n1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
89 remaining -= n1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
90 outbuf += n1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
91 continue;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
92 }
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 /* Invalid multibyte character on input.
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
95 Copy one byte without modification. */
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 *outbuf++ = *inbuf++;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 remaining -= 1;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 /* Incomplete multibyte sequence on input.
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 Pass it through unmodified. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 while (remaining > 0)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 *outbuf++ = *inbuf++;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 remaining -= 1;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 /* Verify the output buffer was large enough. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 if (outbuf - outbuf_orig > outbufsize)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 abort ();
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 /* Return the number of written output bytes. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 return outbuf - outbuf_orig;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 /* Apply tolower() to the unibyte character sequence in INBUF, storing the
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 result as a unibyte character sequence in OUTBUF. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 static void
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 apply_tolower (const char *inbuf, char *outbuf, size_t bufsize)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 for (; bufsize > 0; bufsize--)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 *outbuf = TOLOWER ((unsigned char) *inbuf);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 inbuf++;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 outbuf++;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 int
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 mbmemcasecoll (const char *s1, size_t s1len, const char *s2, size_t s2len,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
130 bool hard_LC_COLLATE)
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 char *t1;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 size_t t1len;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 char *t2;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 size_t t2len;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 char *memory;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 int cmp;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 if (MB_CUR_MAX > 1)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 /* Application of towlower grows each character by a factor 2
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11393
diff changeset
142 at most. */
11393
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 t1len = 2 * s1len;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 t2len = 2 * s2len;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 else
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 /* Application of tolower doesn't change the size. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 t1len = s1len;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 t2len = s2len;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 /* Allocate memory for t1 and t2. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 memory = (char *) malloca (t1len + 1 + t2len + 1);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 if (memory == NULL)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 errno = ENOMEM;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 return 0;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 t1 = memory;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 t2 = memory + t1len + 1;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 /* Csae-fold the two argument strings. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 if (MB_CUR_MAX > 1)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 t1len = apply_towlower (s1, s1len, t1, t1len);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 t2len = apply_towlower (s2, s2len, t2, t2len);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 else
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 apply_tolower (s1, t1, s1len);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 apply_tolower (s2, t2, s2len);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 /* Compare the two case-folded strings. */
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 if (hard_LC_COLLATE)
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 cmp = memcoll (t1, t1len, t2, t2len);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 else
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 cmp = memcmp2 (t1, t1len, t2, t2len);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 errno = 0;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 {
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 int saved_errno = errno;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 freea (memory);
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 errno = saved_errno;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 }
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 return cmp;
fed5074dc3ea New module 'mbmemcasecoll'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 }