author | Ryan C. Gordon <icculus@icculus.org> |
Fri, 20 Aug 2010 02:38:32 -0400 | |
changeset 1094 | aa12a958cc47 |
parent 1093 | 738b2ee912b9 |
child 1114 | db75213cb4b5 |
permissions | -rw-r--r-- |
787 | 1 |
#include "physfs.h" |
2 |
||
3 |
#define __PHYSICSFS_INTERNAL__ |
|
4 |
#include "physfs_internal.h" |
|
5 |
||
6 |
||
7 |
/* |
|
8 |
* From rfc3629, the UTF-8 spec: |
|
9 |
* http://www.ietf.org/rfc/rfc3629.txt |
|
10 |
* |
|
11 |
* Char. number range | UTF-8 octet sequence |
|
12 |
* (hexadecimal) | (binary) |
|
13 |
* --------------------+--------------------------------------------- |
|
14 |
* 0000 0000-0000 007F | 0xxxxxxx |
|
15 |
* 0000 0080-0000 07FF | 110xxxxx 10xxxxxx |
|
16 |
* 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx |
|
17 |
* 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
|
18 |
*/ |
|
19 |
||
20 |
||
21 |
/* |
|
22 |
* This may not be the best value, but it's one that isn't represented |
|
23 |
* in Unicode (0x10FFFF is the largest codepoint value). We return this |
|
24 |
* value from utf8codepoint() if there's bogus bits in the |
|
25 |
* stream. utf8codepoint() will turn this value into something |
|
26 |
* reasonable (like a question mark), for text that wants to try to recover, |
|
27 |
* whereas utf8valid() will use the value to determine if a string has bad |
|
28 |
* bits. |
|
29 |
*/ |
|
30 |
#define UNICODE_BOGUS_CHAR_VALUE 0xFFFFFFFF |
|
31 |
||
32 |
/* |
|
33 |
* This is the codepoint we currently return when there was bogus bits in a |
|
34 |
* UTF-8 string. May not fly in Asian locales? |
|
35 |
*/ |
|
36 |
#define UNICODE_BOGUS_CHAR_CODEPOINT '?' |
|
37 |
||
38 |
static PHYSFS_uint32 utf8codepoint(const char **_str) |
|
39 |
{ |
|
40 |
const char *str = *_str; |
|
41 |
PHYSFS_uint32 retval = 0; |
|
42 |
PHYSFS_uint32 octet = (PHYSFS_uint32) ((PHYSFS_uint8) *str); |
|
43 |
PHYSFS_uint32 octet2, octet3, octet4; |
|
44 |
||
45 |
if (octet == 0) /* null terminator, end of string. */ |
|
46 |
return 0; |
|
47 |
||
48 |
else if (octet < 128) /* one octet char: 0 to 127 */ |
|
49 |
{ |
|
50 |
(*_str)++; /* skip to next possible start of codepoint. */ |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
998
diff
changeset
|
51 |
return octet; |
787 | 52 |
} /* else if */ |
53 |
||
54 |
else if ((octet > 127) && (octet < 192)) /* bad (starts with 10xxxxxx). */ |
|
55 |
{ |
|
56 |
/* |
|
57 |
* Apparently each of these is supposed to be flagged as a bogus |
|
58 |
* char, instead of just resyncing to the next valid codepoint. |
|
59 |
*/ |
|
60 |
(*_str)++; /* skip to next possible start of codepoint. */ |
|
61 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
62 |
} /* else if */ |
|
63 |
||
64 |
else if (octet < 224) /* two octets */ |
|
65 |
{ |
|
66 |
octet -= (128+64); |
|
67 |
octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
68 |
if ((octet2 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
69 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
70 |
||
71 |
*_str += 2; /* skip to next possible start of codepoint. */ |
|
72 |
retval = ((octet << 6) | (octet2 - 128)); |
|
73 |
if ((retval >= 0x80) && (retval <= 0x7FF)) |
|
74 |
return retval; |
|
75 |
} /* else if */ |
|
76 |
||
77 |
else if (octet < 240) /* three octets */ |
|
78 |
{ |
|
79 |
octet -= (128+64+32); |
|
80 |
octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
81 |
if ((octet2 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
82 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
83 |
||
84 |
octet3 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
85 |
if ((octet3 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
86 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
87 |
||
88 |
*_str += 3; /* skip to next possible start of codepoint. */ |
|
89 |
retval = ( ((octet << 12)) | ((octet2-128) << 6) | ((octet3-128)) ); |
|
90 |
||
91 |
/* There are seven "UTF-16 surrogates" that are illegal in UTF-8. */ |
|
92 |
switch (retval) |
|
93 |
{ |
|
94 |
case 0xD800: |
|
95 |
case 0xDB7F: |
|
96 |
case 0xDB80: |
|
97 |
case 0xDBFF: |
|
98 |
case 0xDC00: |
|
99 |
case 0xDF80: |
|
100 |
case 0xDFFF: |
|
101 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
102 |
} /* switch */ |
|
103 |
||
104 |
/* 0xFFFE and 0xFFFF are illegal, too, so we check them at the edge. */ |
|
105 |
if ((retval >= 0x800) && (retval <= 0xFFFD)) |
|
106 |
return retval; |
|
107 |
} /* else if */ |
|
108 |
||
109 |
else if (octet < 248) /* four octets */ |
|
110 |
{ |
|
111 |
octet -= (128+64+32+16); |
|
112 |
octet2 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
113 |
if ((octet2 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
114 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
115 |
||
116 |
octet3 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
117 |
if ((octet3 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
118 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
119 |
||
120 |
octet4 = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
121 |
if ((octet4 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
122 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
123 |
||
124 |
*_str += 4; /* skip to next possible start of codepoint. */ |
|
125 |
retval = ( ((octet << 18)) | ((octet2 - 128) << 12) | |
|
126 |
((octet3 - 128) << 6) | ((octet4 - 128)) ); |
|
127 |
if ((retval >= 0x10000) && (retval <= 0x10FFFF)) |
|
128 |
return retval; |
|
129 |
} /* else if */ |
|
130 |
||
131 |
/* |
|
132 |
* Five and six octet sequences became illegal in rfc3629. |
|
133 |
* We throw the codepoint away, but parse them to make sure we move |
|
134 |
* ahead the right number of bytes and don't overflow the buffer. |
|
135 |
*/ |
|
136 |
||
137 |
else if (octet < 252) /* five octets */ |
|
138 |
{ |
|
139 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
140 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
141 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
142 |
||
143 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
144 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
145 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
146 |
||
147 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
148 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
149 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
150 |
||
151 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
152 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
153 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
154 |
||
155 |
*_str += 5; /* skip to next possible start of codepoint. */ |
|
156 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
157 |
} /* else if */ |
|
158 |
||
159 |
else /* six octets */ |
|
160 |
{ |
|
161 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
162 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
163 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
164 |
||
165 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
166 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
167 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
168 |
||
169 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
170 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
171 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
172 |
||
173 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
174 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
175 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
176 |
||
177 |
octet = (PHYSFS_uint32) ((PHYSFS_uint8) *(++str)); |
|
178 |
if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ |
|
179 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
180 |
||
181 |
*_str += 6; /* skip to next possible start of codepoint. */ |
|
182 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
183 |
} /* else if */ |
|
184 |
||
185 |
return UNICODE_BOGUS_CHAR_VALUE; |
|
186 |
} /* utf8codepoint */ |
|
187 |
||
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
188 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
189 |
void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, PHYSFS_uint64 len) |
787 | 190 |
{ |
191 |
len -= sizeof (PHYSFS_uint32); /* save room for null char. */ |
|
192 |
while (len >= sizeof (PHYSFS_uint32)) |
|
193 |
{ |
|
194 |
PHYSFS_uint32 cp = utf8codepoint(&src); |
|
195 |
if (cp == 0) |
|
196 |
break; |
|
197 |
else if (cp == UNICODE_BOGUS_CHAR_VALUE) |
|
198 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
|
199 |
*(dst++) = cp; |
|
200 |
len -= sizeof (PHYSFS_uint32); |
|
201 |
} /* while */ |
|
202 |
||
203 |
*dst = 0; |
|
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
204 |
} /* PHYSFS_utf8ToUcs4 */ |
787 | 205 |
|
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
206 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
207 |
void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len) |
787 | 208 |
{ |
209 |
len -= sizeof (PHYSFS_uint16); /* save room for null char. */ |
|
210 |
while (len >= sizeof (PHYSFS_uint16)) |
|
211 |
{ |
|
212 |
PHYSFS_uint32 cp = utf8codepoint(&src); |
|
213 |
if (cp == 0) |
|
214 |
break; |
|
215 |
else if (cp == UNICODE_BOGUS_CHAR_VALUE) |
|
216 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
|
217 |
||
1094
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
218 |
if (cp > 0xFFFF) /* UTF-16 surrogates (bogus chars in UCS-2) */ |
787 | 219 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
220 |
||
221 |
*(dst++) = cp; |
|
222 |
len -= sizeof (PHYSFS_uint16); |
|
223 |
} /* while */ |
|
224 |
||
225 |
*dst = 0; |
|
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
226 |
} /* PHYSFS_utf8ToUcs2 */ |
787 | 227 |
|
1094
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
228 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
229 |
void PHYSFS_utf8ToUtf16(const char *src, PHYSFS_uint16 *dst, PHYSFS_uint64 len) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
230 |
{ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
231 |
len -= sizeof (PHYSFS_uint16); /* save room for null char. */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
232 |
while (len >= sizeof (PHYSFS_uint16)) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
233 |
{ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
234 |
PHYSFS_uint32 cp = utf8codepoint(&src); |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
235 |
if (cp == 0) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
236 |
break; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
237 |
else if (cp == UNICODE_BOGUS_CHAR_VALUE) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
238 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
239 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
240 |
if (cp > 0xFFFF) /* encode as surrogate pair */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
241 |
{ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
242 |
if (len < (sizeof (PHYSFS_uint16) * 2)) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
243 |
break; /* not enough room for the pair, stop now. */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
244 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
245 |
cp -= 0x10000; /* Make this a 20-bit value */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
246 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
247 |
*(dst++) = 0xD800 + ((cp >> 10) & 0x3FF); |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
248 |
len -= sizeof (PHYSFS_uint16); |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
249 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
250 |
cp = 0xDC00 + (cp & 0x3FF); |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
251 |
} /* if */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
252 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
253 |
*(dst++) = cp; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
254 |
len -= sizeof (PHYSFS_uint16); |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
255 |
} /* while */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
256 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
257 |
*dst = 0; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
258 |
} /* PHYSFS_utf8ToUtf16 */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
259 |
|
787 | 260 |
static void utf8fromcodepoint(PHYSFS_uint32 cp, char **_dst, PHYSFS_uint64 *_len) |
261 |
{ |
|
262 |
char *dst = *_dst; |
|
263 |
PHYSFS_uint64 len = *_len; |
|
264 |
||
265 |
if (len == 0) |
|
266 |
return; |
|
267 |
||
268 |
if (cp > 0x10FFFF) |
|
269 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
|
270 |
else if ((cp == 0xFFFE) || (cp == 0xFFFF)) /* illegal values. */ |
|
271 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
|
272 |
else |
|
273 |
{ |
|
274 |
/* There are seven "UTF-16 surrogates" that are illegal in UTF-8. */ |
|
275 |
switch (cp) |
|
276 |
{ |
|
277 |
case 0xD800: |
|
278 |
case 0xDB7F: |
|
279 |
case 0xDB80: |
|
280 |
case 0xDBFF: |
|
281 |
case 0xDC00: |
|
282 |
case 0xDF80: |
|
283 |
case 0xDFFF: |
|
284 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
|
285 |
} /* switch */ |
|
286 |
} /* else */ |
|
287 |
||
288 |
/* Do the encoding... */ |
|
289 |
if (cp < 0x80) |
|
290 |
{ |
|
291 |
*(dst++) = (char) cp; |
|
292 |
len--; |
|
293 |
} /* if */ |
|
294 |
||
295 |
else if (cp < 0x800) |
|
296 |
{ |
|
297 |
if (len < 2) |
|
298 |
len = 0; |
|
299 |
else |
|
300 |
{ |
|
301 |
*(dst++) = (char) ((cp >> 6) | 128 | 64); |
|
302 |
*(dst++) = (char) (cp & 0x3F) | 128; |
|
303 |
len -= 2; |
|
304 |
} /* else */ |
|
305 |
} /* else if */ |
|
306 |
||
307 |
else if (cp < 0x10000) |
|
308 |
{ |
|
309 |
if (len < 3) |
|
310 |
len = 0; |
|
311 |
else |
|
312 |
{ |
|
313 |
*(dst++) = (char) ((cp >> 12) | 128 | 64 | 32); |
|
314 |
*(dst++) = (char) ((cp >> 6) & 0x3F) | 128; |
|
315 |
*(dst++) = (char) (cp & 0x3F) | 128; |
|
316 |
len -= 3; |
|
317 |
} /* else */ |
|
318 |
} /* else if */ |
|
319 |
||
320 |
else |
|
321 |
{ |
|
322 |
if (len < 4) |
|
323 |
len = 0; |
|
324 |
else |
|
325 |
{ |
|
326 |
*(dst++) = (char) ((cp >> 18) | 128 | 64 | 32 | 16); |
|
327 |
*(dst++) = (char) ((cp >> 12) & 0x3F) | 128; |
|
328 |
*(dst++) = (char) ((cp >> 6) & 0x3F) | 128; |
|
329 |
*(dst++) = (char) (cp & 0x3F) | 128; |
|
330 |
len -= 4; |
|
331 |
} /* else if */ |
|
332 |
} /* else */ |
|
333 |
||
334 |
*_dst = dst; |
|
335 |
*_len = len; |
|
336 |
} /* utf8fromcodepoint */ |
|
337 |
||
338 |
#define UTF8FROMTYPE(typ, src, dst, len) \ |
|
1092
12c87d886a75
Zero-sized destination buffers when converting to UTF-8 shouldn't overflow.
Ryan C. Gordon <icculus@icculus.org>
parents:
1016
diff
changeset
|
339 |
if (len == 0) return; \ |
787 | 340 |
len--; \ |
341 |
while (len) \ |
|
342 |
{ \ |
|
998
974b90b56c43
Fixed latin1 to UTF-8 conversion (sign conversion was broken).
Ryan C. Gordon <icculus@icculus.org>
parents:
986
diff
changeset
|
343 |
const PHYSFS_uint32 cp = (PHYSFS_uint32) ((typ) (*(src++))); \ |
787 | 344 |
if (cp == 0) break; \ |
345 |
utf8fromcodepoint(cp, &dst, &len); \ |
|
346 |
} \ |
|
347 |
*dst = '\0'; \ |
|
348 |
||
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
349 |
void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, PHYSFS_uint64 len) |
787 | 350 |
{ |
351 |
UTF8FROMTYPE(PHYSFS_uint32, src, dst, len); |
|
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
352 |
} /* PHYSFS_utf8FromUcs4 */ |
787 | 353 |
|
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
354 |
void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len) |
787 | 355 |
{ |
356 |
UTF8FROMTYPE(PHYSFS_uint64, src, dst, len); |
|
1093
738b2ee912b9
Fixed incorrect comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
1092
diff
changeset
|
357 |
} /* PHYSFS_utf8FromUcs2 */ |
787 | 358 |
|
359 |
/* latin1 maps to unicode codepoints directly, we just utf-8 encode it. */ |
|
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
360 |
void PHYSFS_utf8FromLatin1(const char *src, char *dst, PHYSFS_uint64 len) |
787 | 361 |
{ |
362 |
UTF8FROMTYPE(PHYSFS_uint8, src, dst, len); |
|
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
363 |
} /* PHYSFS_utf8FromLatin1 */ |
787 | 364 |
|
365 |
#undef UTF8FROMTYPE |
|
366 |
||
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
367 |
|
1094
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
368 |
void PHYSFS_utf8FromUtf16(const PHYSFS_uint16 *src, char *dst, PHYSFS_uint64 len) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
369 |
{ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
370 |
if (len == 0) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
371 |
return; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
372 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
373 |
len--; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
374 |
while (len) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
375 |
{ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
376 |
PHYSFS_uint32 cp = (PHYSFS_uint32) *(src++); |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
377 |
if (cp == 0) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
378 |
break; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
379 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
380 |
/* Orphaned second half of surrogate pair? */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
381 |
if ((cp >= 0xDC00) && (cp <= 0xDFFF)) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
382 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
383 |
else if ((cp >= 0xD800) && (cp <= 0xDBFF)) /* start surrogate pair! */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
384 |
{ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
385 |
const PHYSFS_uint32 pair = (PHYSFS_uint32) *src; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
386 |
if ((pair < 0xDC00) || (pair > 0xDFFF)) |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
387 |
cp = UNICODE_BOGUS_CHAR_CODEPOINT; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
388 |
else |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
389 |
{ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
390 |
src++; // eat the other surrogate. |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
391 |
cp = (((cp - 0xD800) << 10) | (pair - 0xDC00)); |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
392 |
} /* else */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
393 |
} /* else if */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
394 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
395 |
utf8fromcodepoint(cp, &dst, &len); |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
396 |
} /* while */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
397 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
398 |
*dst = '\0'; |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
399 |
} /* PHYSFS_utf8FromUtf16 */ |
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
400 |
|
aa12a958cc47
Added UTF-16 support.
Ryan C. Gordon <icculus@icculus.org>
parents:
1093
diff
changeset
|
401 |
|
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
402 |
typedef struct CaseFoldMapping |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
403 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
404 |
PHYSFS_uint32 from; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
405 |
PHYSFS_uint32 to0; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
406 |
PHYSFS_uint32 to1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
407 |
PHYSFS_uint32 to2; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
408 |
} CaseFoldMapping; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
409 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
410 |
typedef struct CaseFoldHashBucket |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
411 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
412 |
const PHYSFS_uint8 count; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
413 |
const CaseFoldMapping *list; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
414 |
} CaseFoldHashBucket; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
415 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
416 |
#include "physfs_casefolding.h" |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
417 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
418 |
static void locate_case_fold_mapping(const PHYSFS_uint32 from, |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
419 |
PHYSFS_uint32 *to) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
420 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
421 |
PHYSFS_uint32 i; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
422 |
const PHYSFS_uint8 hashed = ((from ^ (from >> 8)) & 0xFF); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
423 |
const CaseFoldHashBucket *bucket = &case_fold_hash[hashed]; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
424 |
const CaseFoldMapping *mapping = bucket->list; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
425 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
426 |
for (i = 0; i < bucket->count; i++, mapping++) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
427 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
428 |
if (mapping->from == from) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
429 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
430 |
to[0] = mapping->to0; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
431 |
to[1] = mapping->to1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
432 |
to[2] = mapping->to2; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
433 |
return; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
434 |
} /* if */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
435 |
} /* for */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
436 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
437 |
/* Not found...there's no remapping for this codepoint. */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
438 |
to[0] = from; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
439 |
to[1] = 0; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
440 |
to[2] = 0; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
441 |
} /* locate_case_fold_mapping */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
442 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
443 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
444 |
static int utf8codepointcmp(const PHYSFS_uint32 cp1, const PHYSFS_uint32 cp2) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
445 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
446 |
PHYSFS_uint32 folded1[3], folded2[3]; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
447 |
locate_case_fold_mapping(cp1, folded1); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
448 |
locate_case_fold_mapping(cp2, folded2); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
449 |
return ( (folded1[0] == folded2[0]) && |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
450 |
(folded1[1] == folded2[1]) && |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
451 |
(folded1[2] == folded2[2]) ); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
452 |
} /* utf8codepointcmp */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
453 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
454 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
455 |
int __PHYSFS_utf8strcasecmp(const char *str1, const char *str2) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
456 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
457 |
while (1) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
458 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
459 |
const PHYSFS_uint32 cp1 = utf8codepoint(&str1); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
460 |
const PHYSFS_uint32 cp2 = utf8codepoint(&str2); |
986
e69d37f80ce2
Fixed some Sun Studio warnings about unreachable code.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
461 |
if (!utf8codepointcmp(cp1, cp2)) break; |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
462 |
if (cp1 == 0) return 1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
463 |
} /* while */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
464 |
|
986
e69d37f80ce2
Fixed some Sun Studio warnings about unreachable code.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
465 |
return 0; |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
466 |
} /* __PHYSFS_utf8strcasecmp */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
467 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
468 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
469 |
int __PHYSFS_utf8strnicmp(const char *str1, const char *str2, PHYSFS_uint32 n) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
470 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
471 |
while (n > 0) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
472 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
473 |
const PHYSFS_uint32 cp1 = utf8codepoint(&str1); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
474 |
const PHYSFS_uint32 cp2 = utf8codepoint(&str2); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
475 |
if (!utf8codepointcmp(cp1, cp2)) return 0; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
476 |
if (cp1 == 0) return 1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
477 |
n--; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
478 |
} /* while */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
479 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
480 |
return 1; /* matched to n chars. */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
481 |
} /* __PHYSFS_utf8strnicmp */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
482 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
483 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
484 |
int __PHYSFS_stricmpASCII(const char *str1, const char *str2) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
485 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
486 |
while (1) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
487 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
488 |
const char ch1 = *(str1++); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
489 |
const char ch2 = *(str2++); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
490 |
const char cp1 = ((ch1 >= 'A') && (ch1 <= 'Z')) ? (ch1+32) : ch1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
491 |
const char cp2 = ((ch2 >= 'A') && (ch2 <= 'Z')) ? (ch2+32) : ch2; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
492 |
if (cp1 < cp2) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
493 |
return -1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
494 |
else if (cp1 > cp2) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
495 |
return 1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
496 |
else if (cp1 == 0) /* they're both null chars? */ |
986
e69d37f80ce2
Fixed some Sun Studio warnings about unreachable code.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
497 |
break; |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
498 |
} /* while */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
499 |
|
986
e69d37f80ce2
Fixed some Sun Studio warnings about unreachable code.
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
500 |
return 0; |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
501 |
} /* __PHYSFS_stricmpASCII */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
502 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
503 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
504 |
int __PHYSFS_strnicmpASCII(const char *str1, const char *str2, PHYSFS_uint32 n) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
505 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
506 |
while (n-- > 0) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
507 |
{ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
508 |
const char ch1 = *(str1++); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
509 |
const char ch2 = *(str2++); |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
510 |
const char cp1 = ((ch1 >= 'A') && (ch1 <= 'Z')) ? (ch1+32) : ch1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
511 |
const char cp2 = ((ch2 >= 'A') && (ch2 <= 'Z')) ? (ch2+32) : ch2; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
512 |
if (cp1 < cp2) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
513 |
return -1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
514 |
else if (cp1 > cp2) |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
515 |
return 1; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
516 |
else if (cp1 == 0) /* they're both null chars? */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
517 |
return 0; |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
518 |
} /* while */ |
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
519 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
520 |
return 0; |
1093
738b2ee912b9
Fixed incorrect comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
1092
diff
changeset
|
521 |
} /* __PHYSFS_strnicmpASCII */ |
828
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
522 |
|
ee871d51510d
Bunch of work on Unicode...added case-folding stricmp, removed
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
523 |
|
787 | 524 |
/* end of physfs_unicode.c ... */ |
525 |