1 | /*
|
---|
2 | * msvcrt.dll mbcs functions
|
---|
3 | *
|
---|
4 | * Copyright 1999 Alexandre Julliard
|
---|
5 | * Copyright 2000 Jon Griffths
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Lesser General Public
|
---|
9 | * License as published by the Free Software Foundation; either
|
---|
10 | * version 2.1 of the License, or (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Lesser General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU Lesser General Public
|
---|
18 | * License along with this library; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
20 | *
|
---|
21 | * FIXME
|
---|
22 | * Not currently binary compatible with win32. MSVCRT_mbctype must be
|
---|
23 | * populated correctly and the ismb* functions should reference it.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #include "msvcrt.h"
|
---|
27 |
|
---|
28 | #include "msvcrt/mbctype.h"
|
---|
29 | #include "msvcrt/mbstring.h"
|
---|
30 | #include "msvcrt/stdlib.h"
|
---|
31 | #include "msvcrt/string.h"
|
---|
32 | #include "msvcrt/wctype.h"
|
---|
33 |
|
---|
34 | #include "wine/unicode.h"
|
---|
35 | #include "wine/debug.h"
|
---|
36 |
|
---|
37 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
---|
38 |
|
---|
39 | unsigned char MSVCRT_mbctype[257];
|
---|
40 | int MSVCRT___mb_cur_max = 1;
|
---|
41 |
|
---|
42 | static MSVCRT_wchar_t msvcrt_mbc_to_wc(unsigned int ch)
|
---|
43 | {
|
---|
44 | MSVCRT_wchar_t chW;
|
---|
45 | char mbch[2];
|
---|
46 | int n_chars;
|
---|
47 |
|
---|
48 | if (ch <= 0xff) {
|
---|
49 | mbch[0] = ch;
|
---|
50 | n_chars = 1;
|
---|
51 | } else {
|
---|
52 | mbch[0] = (ch >> 8) & 0xff;
|
---|
53 | mbch[1] = ch & 0xff;
|
---|
54 | n_chars = 2;
|
---|
55 | }
|
---|
56 | if (!MultiByteToWideChar(MSVCRT_current_lc_all_cp, 0, mbch, n_chars, &chW, 1))
|
---|
57 | {
|
---|
58 | WARN("MultiByteToWideChar failed on %x\n", ch);
|
---|
59 | return 0;
|
---|
60 | }
|
---|
61 | return chW;
|
---|
62 | }
|
---|
63 |
|
---|
64 | /*********************************************************************
|
---|
65 | * __p__mbctype (MSVCRT.@)
|
---|
66 | */
|
---|
67 | unsigned char* __p__mbctype(void)
|
---|
68 | {
|
---|
69 | dprintf(("MSVCRT: Query for __p__mbctype"));
|
---|
70 | return MSVCRT_mbctype;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /*********************************************************************
|
---|
74 | * __p___mb_cur_max(MSVCRT.@)
|
---|
75 | */
|
---|
76 | int* __p___mb_cur_max(void)
|
---|
77 | {
|
---|
78 | dprintf(("MSVCRT: Query for __p__mb_cur_max"));
|
---|
79 | return &MSVCRT___mb_cur_max;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /*********************************************************************
|
---|
83 | * _mbsnextc(MSVCRT.@)
|
---|
84 | */
|
---|
85 | unsigned int _mbsnextc(const unsigned char* str)
|
---|
86 | {
|
---|
87 | dprintf(("MSVCRT: _mbsnextc"));
|
---|
88 | if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*str))
|
---|
89 | return *str << 8 | str[1];
|
---|
90 | return *str; /* ASCII CP or SB char */
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*********************************************************************
|
---|
94 | * _mbctolower(MSVCRT.@)
|
---|
95 | */
|
---|
96 | unsigned int _mbctolower(unsigned int c)
|
---|
97 | {
|
---|
98 | dprintf(("MSVCRT: _mbctolower"));
|
---|
99 | if (MSVCRT_isleadbyte(c))
|
---|
100 | {
|
---|
101 | FIXME("Handle MBC chars\n");
|
---|
102 | return c;
|
---|
103 | }
|
---|
104 | return tolower(c); /* ASCII CP or SB char */
|
---|
105 | }
|
---|
106 |
|
---|
107 | /*********************************************************************
|
---|
108 | * _mbctoupper(MSVCRT.@)
|
---|
109 | */
|
---|
110 | unsigned int _mbctoupper(unsigned int c)
|
---|
111 | {
|
---|
112 | dprintf(("MSVCRT: _mbctoupper"));
|
---|
113 | if (MSVCRT_isleadbyte(c))
|
---|
114 | {
|
---|
115 | FIXME("Handle MBC chars\n");
|
---|
116 | return c;
|
---|
117 | }
|
---|
118 | return toupper(c); /* ASCII CP or SB char */
|
---|
119 | }
|
---|
120 |
|
---|
121 | /*********************************************************************
|
---|
122 | * _mbsdec(MSVCRT.@)
|
---|
123 | */
|
---|
124 | unsigned char* _mbsdec(const unsigned char* start, const unsigned char* cur)
|
---|
125 | {
|
---|
126 | dprintf(("MSVCRT: _mbsdec"));
|
---|
127 | if(MSVCRT___mb_cur_max > 1)
|
---|
128 | return (char *)(_ismbstrail(start,cur-1) ? cur - 2 : cur -1);
|
---|
129 |
|
---|
130 | return (char *)cur - 1; /* ASCII CP or SB char */
|
---|
131 | }
|
---|
132 |
|
---|
133 | /*********************************************************************
|
---|
134 | * _mbsinc(MSVCRT.@)
|
---|
135 | */
|
---|
136 | unsigned char* _mbsinc(const unsigned char* str)
|
---|
137 | {
|
---|
138 | dprintf(("MSVCRT: _mbsinc"));
|
---|
139 | if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*str))
|
---|
140 | return (unsigned char*)str + 2; /* MB char */
|
---|
141 |
|
---|
142 | return (unsigned char*)str + 1; /* ASCII CP or SB char */
|
---|
143 | }
|
---|
144 |
|
---|
145 | /*********************************************************************
|
---|
146 | * _mbsninc(MSVCRT.@)
|
---|
147 | */
|
---|
148 | unsigned char* _mbsninc(const unsigned char* str, MSVCRT_size_t num)
|
---|
149 | {
|
---|
150 | dprintf(("MSVCRT: _mbsninc"));
|
---|
151 | if(!str || num < 1)
|
---|
152 | return NULL;
|
---|
153 | if(MSVCRT___mb_cur_max > 1)
|
---|
154 | {
|
---|
155 | while(num--)
|
---|
156 | str = _mbsinc(str);
|
---|
157 | return (unsigned char*)str;
|
---|
158 | }
|
---|
159 | return (unsigned char*)str + num; /* ASCII CP */
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*********************************************************************
|
---|
163 | * _mbclen(MSVCRT.@)
|
---|
164 | */
|
---|
165 | unsigned int _mbclen(const unsigned char* str)
|
---|
166 | {
|
---|
167 | dprintf(("MSVCRT: _mbclen"));
|
---|
168 | return MSVCRT_isleadbyte(*str) ? 2 : 1;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /*********************************************************************
|
---|
172 | * mblen(MSVCRT.@)
|
---|
173 | */
|
---|
174 | int MSVCRT_mblen(const char* str, MSVCRT_size_t size)
|
---|
175 | {
|
---|
176 | dprintf(("MSVCRT: mblen"));
|
---|
177 | if (str && *str && size)
|
---|
178 | {
|
---|
179 | if(MSVCRT___mb_cur_max == 1)
|
---|
180 | return 1; /* ASCII CP */
|
---|
181 |
|
---|
182 | return !MSVCRT_isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
|
---|
183 | }
|
---|
184 | return 0;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /*********************************************************************
|
---|
188 | * _mbslen(MSVCRT.@)
|
---|
189 | */
|
---|
190 | MSVCRT_size_t _mbslen(const unsigned char* str)
|
---|
191 | {
|
---|
192 | dprintf(("MSVCRT: _mbslen"));
|
---|
193 | if(MSVCRT___mb_cur_max > 1)
|
---|
194 | {
|
---|
195 | MSVCRT_size_t len = 0;
|
---|
196 | while(*str)
|
---|
197 | {
|
---|
198 | str += MSVCRT_isleadbyte(*str) ? 2 : 1;
|
---|
199 | len++;
|
---|
200 | }
|
---|
201 | return len;
|
---|
202 | }
|
---|
203 | return strlen(str); /* ASCII CP */
|
---|
204 | }
|
---|
205 |
|
---|
206 | /*********************************************************************
|
---|
207 | * _mbstrlen(MSVCRT.@)
|
---|
208 | */
|
---|
209 | MSVCRT_size_t _mbstrlen(const char* str)
|
---|
210 | {
|
---|
211 | dprintf(("MSVCRT: _mbstrlen"));
|
---|
212 | if(MSVCRT___mb_cur_max > 1)
|
---|
213 | {
|
---|
214 | MSVCRT_size_t len = 0;
|
---|
215 | while(*str)
|
---|
216 | {
|
---|
217 | /* FIXME: According to the documentation we are supposed to test for
|
---|
218 | * multi-byte character validity. Whatever that means
|
---|
219 | */
|
---|
220 | str += MSVCRT_isleadbyte(*str) ? 2 : 1;
|
---|
221 | len++;
|
---|
222 | }
|
---|
223 | return len;
|
---|
224 | }
|
---|
225 | return strlen(str); /* ASCII CP */
|
---|
226 | }
|
---|
227 |
|
---|
228 | /*********************************************************************
|
---|
229 | * _mbccpy(MSVCRT.@)
|
---|
230 | */
|
---|
231 | void _mbccpy(unsigned char* dest, const unsigned char* src)
|
---|
232 | {
|
---|
233 | dprintf(("MSVCRT: _mbccpy"));
|
---|
234 | *dest++ = *src;
|
---|
235 | if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*src))
|
---|
236 | *dest = *++src; /* MB char */
|
---|
237 | else
|
---|
238 | ERR("failure.. is this ok?\n");
|
---|
239 | }
|
---|
240 |
|
---|
241 | /*********************************************************************
|
---|
242 | * _mbsncpy(MSVCRT.@)
|
---|
243 | */
|
---|
244 | unsigned char* _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
---|
245 | {
|
---|
246 | dprintf(("MSVCRT: _mbsncpy"));
|
---|
247 | if(!n)
|
---|
248 | return dst;
|
---|
249 | if(MSVCRT___mb_cur_max > 1)
|
---|
250 | {
|
---|
251 | unsigned char* ret = dst;
|
---|
252 | while (*src && n--)
|
---|
253 | {
|
---|
254 | *dst++ = *src;
|
---|
255 | if (MSVCRT_isleadbyte(*src++))
|
---|
256 | *dst++ = *src++;
|
---|
257 | }
|
---|
258 | while(n--)
|
---|
259 | *dst++ = '\0';
|
---|
260 | return ret;
|
---|
261 | }
|
---|
262 | return strncpy(dst, src, n); /* ASCII CP */
|
---|
263 | }
|
---|
264 |
|
---|
265 | /*********************************************************************
|
---|
266 | * _mbsnbcpy(MSVCRT.@)
|
---|
267 | */
|
---|
268 | unsigned char* _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
---|
269 | {
|
---|
270 | dprintf(("MSVCRT: _mbsnbcpy"));
|
---|
271 | if(!n)
|
---|
272 | return dst;
|
---|
273 | if(MSVCRT___mb_cur_max > 1)
|
---|
274 | {
|
---|
275 | unsigned char* ret = dst;
|
---|
276 | while (*src && (n-- > 1))
|
---|
277 | {
|
---|
278 | *dst++ = *src;
|
---|
279 | if (MSVCRT_isleadbyte(*src++))
|
---|
280 | {
|
---|
281 | *dst++ = *src++;
|
---|
282 | n--;
|
---|
283 | }
|
---|
284 | }
|
---|
285 | if (*src && n && !MSVCRT_isleadbyte(*src))
|
---|
286 | {
|
---|
287 | /* If the last character is a multi-byte character then
|
---|
288 | * we cannot copy it since we have only one byte left
|
---|
289 | */
|
---|
290 | *dst++ = *src;
|
---|
291 | n--;
|
---|
292 | }
|
---|
293 | while (n--)
|
---|
294 | *dst++ = '\0';
|
---|
295 | return ret;
|
---|
296 | }
|
---|
297 | return strncpy(dst, src, n); /* ASCII CP */
|
---|
298 | }
|
---|
299 |
|
---|
300 | /*********************************************************************
|
---|
301 | * _mbscmp(MSVCRT.@)
|
---|
302 | */
|
---|
303 | int _mbscmp(const unsigned char* str, const unsigned char* cmp)
|
---|
304 | {
|
---|
305 | dprintf(("MSVCRT: _mbscmp"));
|
---|
306 | if(MSVCRT___mb_cur_max > 1)
|
---|
307 | {
|
---|
308 | unsigned int strc, cmpc;
|
---|
309 | do {
|
---|
310 | if(!*str)
|
---|
311 | return *cmp ? -1 : 0;
|
---|
312 | if(!*cmp)
|
---|
313 | return 1;
|
---|
314 | strc = _mbsnextc(str);
|
---|
315 | cmpc = _mbsnextc(cmp);
|
---|
316 | if(strc != cmpc)
|
---|
317 | return strc < cmpc ? -1 : 1;
|
---|
318 | str +=(strc > 255) ? 2 : 1;
|
---|
319 | cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
---|
320 | } while(1);
|
---|
321 | }
|
---|
322 | return strcmp(str, cmp); /* ASCII CP */
|
---|
323 | }
|
---|
324 |
|
---|
325 | /*********************************************************************
|
---|
326 | * _mbsicoll(MSVCRT.@)
|
---|
327 | * FIXME: handle locales.
|
---|
328 | */
|
---|
329 | int _mbsicoll(const unsigned char* str, const unsigned char* cmp)
|
---|
330 | {
|
---|
331 | if(MSVCRT___mb_cur_max > 1)
|
---|
332 | {
|
---|
333 | unsigned int strc, cmpc;
|
---|
334 | do {
|
---|
335 | if(!*str)
|
---|
336 | return *cmp ? -1 : 0;
|
---|
337 | if(!*cmp)
|
---|
338 | return 1;
|
---|
339 | strc = _mbctolower(_mbsnextc(str));
|
---|
340 | cmpc = _mbctolower(_mbsnextc(cmp));
|
---|
341 | if(strc != cmpc)
|
---|
342 | return strc < cmpc ? -1 : 1;
|
---|
343 | str +=(strc > 255) ? 2 : 1;
|
---|
344 | cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
---|
345 | } while(1);
|
---|
346 | }
|
---|
347 | return strcasecmp(str, cmp); /* ASCII CP */
|
---|
348 | }
|
---|
349 |
|
---|
350 | /*********************************************************************
|
---|
351 | * _mbsicmp(MSVCRT.@)
|
---|
352 | */
|
---|
353 | int _mbsicmp(const unsigned char* str, const unsigned char* cmp)
|
---|
354 | {
|
---|
355 | dprintf(("MSVCRT: _mbsicmp"));
|
---|
356 | if(MSVCRT___mb_cur_max > 1)
|
---|
357 | {
|
---|
358 | unsigned int strc, cmpc;
|
---|
359 | do {
|
---|
360 | if(!*str)
|
---|
361 | return *cmp ? -1 : 0;
|
---|
362 | if(!*cmp)
|
---|
363 | return 1;
|
---|
364 | strc = _mbctolower(_mbsnextc(str));
|
---|
365 | cmpc = _mbctolower(_mbsnextc(cmp));
|
---|
366 | if(strc != cmpc)
|
---|
367 | return strc < cmpc ? -1 : 1;
|
---|
368 | str +=(strc > 255) ? 2 : 1;
|
---|
369 | cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
---|
370 | } while(1);
|
---|
371 | }
|
---|
372 | return _stricmp(str, cmp); /* ASCII CP */
|
---|
373 | }
|
---|
374 |
|
---|
375 | /*********************************************************************
|
---|
376 | * _mbsncmp(MSVCRT.@)
|
---|
377 | */
|
---|
378 | int _mbsncmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
---|
379 | {
|
---|
380 | dprintf(("MSVCRT: _mbsncmp"));
|
---|
381 | if(!len)
|
---|
382 | return 0;
|
---|
383 |
|
---|
384 | if(MSVCRT___mb_cur_max > 1)
|
---|
385 | {
|
---|
386 | unsigned int strc, cmpc;
|
---|
387 | while(len--)
|
---|
388 | {
|
---|
389 | int inc;
|
---|
390 | if(!*str)
|
---|
391 | return *cmp ? -1 : 0;
|
---|
392 | if(!*cmp)
|
---|
393 | return 1;
|
---|
394 | strc = _mbsnextc(str);
|
---|
395 | cmpc = _mbsnextc(cmp);
|
---|
396 | if(strc != cmpc)
|
---|
397 | return strc < cmpc ? -1 : 1;
|
---|
398 | inc=(strc > 255) ? 2 : 1; /* Equal, use same increment */
|
---|
399 | str += inc;
|
---|
400 | cmp += inc;
|
---|
401 | }
|
---|
402 | return 0; /* Matched len chars */
|
---|
403 | }
|
---|
404 | return strncmp(str, cmp, len); /* ASCII CP */
|
---|
405 | }
|
---|
406 |
|
---|
407 | /*********************************************************************
|
---|
408 | * _mbsnbcmp(MSVCRT.@)
|
---|
409 | */
|
---|
410 | int _mbsnbcmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
---|
411 | {
|
---|
412 | dprintf(("MSVCRT: _mbsnbcmp"));
|
---|
413 | if (!len)
|
---|
414 | return 0;
|
---|
415 | if(MSVCRT___mb_cur_max > 1)
|
---|
416 | {
|
---|
417 | unsigned int strc, cmpc;
|
---|
418 | while (len)
|
---|
419 | {
|
---|
420 | int clen;
|
---|
421 | if(!*str)
|
---|
422 | return *cmp ? -1 : 0;
|
---|
423 | if(!*cmp)
|
---|
424 | return 1;
|
---|
425 | if (MSVCRT_isleadbyte(*str))
|
---|
426 | {
|
---|
427 | strc=(len>=2)?_mbsnextc(str):0;
|
---|
428 | clen=2;
|
---|
429 | }
|
---|
430 | else
|
---|
431 | {
|
---|
432 | strc=*str;
|
---|
433 | clen=1;
|
---|
434 | }
|
---|
435 | if (MSVCRT_isleadbyte(*cmp))
|
---|
436 | cmpc=(len>=2)?_mbsnextc(cmp):0;
|
---|
437 | else
|
---|
438 | cmpc=*str;
|
---|
439 | if(strc != cmpc)
|
---|
440 | return strc < cmpc ? -1 : 1;
|
---|
441 | len -= clen;
|
---|
442 | str += clen;
|
---|
443 | cmp += clen;
|
---|
444 | }
|
---|
445 | return 0; /* Matched len chars */
|
---|
446 | FIXME("%s %s %d\n",str,cmp,len);
|
---|
447 | }
|
---|
448 | return strncmp(str,cmp,len);
|
---|
449 | }
|
---|
450 |
|
---|
451 | /*********************************************************************
|
---|
452 | * _mbsnicmp(MSVCRT.@)
|
---|
453 | *
|
---|
454 | * Compare two multibyte strings case insensitively to 'len' characters.
|
---|
455 | */
|
---|
456 | int _mbsnicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
---|
457 | {
|
---|
458 | dprintf(("MSVCRT: _mbsnicmp"));
|
---|
459 | /* FIXME: No tolower() for mb strings yet */
|
---|
460 | if(MSVCRT___mb_cur_max > 1)
|
---|
461 | {
|
---|
462 | unsigned int strc, cmpc;
|
---|
463 | while(len--)
|
---|
464 | {
|
---|
465 | if(!*str)
|
---|
466 | return *cmp ? -1 : 0;
|
---|
467 | if(!*cmp)
|
---|
468 | return 1;
|
---|
469 | strc = _mbctolower(_mbsnextc(str));
|
---|
470 | cmpc = _mbctolower(_mbsnextc(cmp));
|
---|
471 | if(strc != cmpc)
|
---|
472 | return strc < cmpc ? -1 : 1;
|
---|
473 | str +=(strc > 255) ? 2 : 1;
|
---|
474 | cmp +=(strc > 255) ? 2 : 1; /* Equal, use same increment */
|
---|
475 | }
|
---|
476 | return 0; /* Matched len chars */
|
---|
477 | }
|
---|
478 | return strncasecmp(str, cmp, len); /* ASCII CP */
|
---|
479 | }
|
---|
480 |
|
---|
481 | /*********************************************************************
|
---|
482 | * _mbsnbicmp(MSVCRT.@)
|
---|
483 | */
|
---|
484 | int _mbsnbicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
---|
485 | {
|
---|
486 | dprintf(("MSVCRT: _mbsnbicmp"));
|
---|
487 | if (!len)
|
---|
488 | return 0;
|
---|
489 | if(MSVCRT___mb_cur_max > 1)
|
---|
490 | {
|
---|
491 | unsigned int strc, cmpc;
|
---|
492 | while (len)
|
---|
493 | {
|
---|
494 | int clen;
|
---|
495 | if(!*str)
|
---|
496 | return *cmp ? -1 : 0;
|
---|
497 | if(!*cmp)
|
---|
498 | return 1;
|
---|
499 | if (MSVCRT_isleadbyte(*str))
|
---|
500 | {
|
---|
501 | strc=(len>=2)?_mbsnextc(str):0;
|
---|
502 | clen=2;
|
---|
503 | }
|
---|
504 | else
|
---|
505 | {
|
---|
506 | strc=*str;
|
---|
507 | clen=1;
|
---|
508 | }
|
---|
509 | if (MSVCRT_isleadbyte(*cmp))
|
---|
510 | cmpc=(len>=2)?_mbsnextc(cmp):0;
|
---|
511 | else
|
---|
512 | cmpc=*str;
|
---|
513 | strc = _mbctolower(strc);
|
---|
514 | cmpc = _mbctolower(cmpc);
|
---|
515 | if(strc != cmpc)
|
---|
516 | return strc < cmpc ? -1 : 1;
|
---|
517 | len -= clen;
|
---|
518 | str += clen;
|
---|
519 | cmp += clen;
|
---|
520 | }
|
---|
521 | return 0; /* Matched len bytes */
|
---|
522 | FIXME("%s %s %d\n",str,cmp,len);
|
---|
523 | }
|
---|
524 | return strncmp(str,cmp,len);
|
---|
525 | }
|
---|
526 |
|
---|
527 | /*********************************************************************
|
---|
528 | * _mbschr(MSVCRT.@)
|
---|
529 | *
|
---|
530 | * Find a multibyte character in a multibyte string.
|
---|
531 | */
|
---|
532 | unsigned char* _mbschr(const unsigned char* s, unsigned int x)
|
---|
533 | {
|
---|
534 | dprintf(("MSVCRT: _mbschr"));
|
---|
535 | if(MSVCRT___mb_cur_max > 1)
|
---|
536 | {
|
---|
537 | unsigned int c;
|
---|
538 | while (1)
|
---|
539 | {
|
---|
540 | c = _mbsnextc(s);
|
---|
541 | if (c == x)
|
---|
542 | return (unsigned char*)s;
|
---|
543 | if (!c)
|
---|
544 | return NULL;
|
---|
545 | s += c > 255 ? 2 : 1;
|
---|
546 | }
|
---|
547 | }
|
---|
548 | return strchr(s, x); /* ASCII CP */
|
---|
549 | }
|
---|
550 |
|
---|
551 | /*********************************************************************
|
---|
552 | * _mbsrchr(MSVCRT.@)
|
---|
553 | */
|
---|
554 | unsigned char* _mbsrchr(const unsigned char* s, unsigned int x)
|
---|
555 | {
|
---|
556 | dprintf(("MSVCRT: _mbsrchr"));
|
---|
557 | if(MSVCRT___mb_cur_max > 1)
|
---|
558 | {
|
---|
559 | unsigned int c;
|
---|
560 | unsigned char* match=NULL;
|
---|
561 | if(!s)
|
---|
562 | return NULL;
|
---|
563 | while (1) {
|
---|
564 | c = _mbsnextc(s);
|
---|
565 | if (c == x)
|
---|
566 | match=(unsigned char*)s;
|
---|
567 | if (!c)
|
---|
568 | return match;
|
---|
569 | s +=(c > 255) ? 2 : 1;
|
---|
570 | }
|
---|
571 | }
|
---|
572 | return strrchr(s,x);
|
---|
573 | }
|
---|
574 |
|
---|
575 | /*********************************************************************
|
---|
576 | * _mbstok(MSVCRT.@)
|
---|
577 | *
|
---|
578 | * Find and extract tokens from strings
|
---|
579 | */
|
---|
580 | unsigned char* _mbstok(unsigned char *str, const unsigned char *delim)
|
---|
581 | {
|
---|
582 | MSVCRT_thread_data *data = msvcrt_get_thread_data();
|
---|
583 | char *ret;
|
---|
584 |
|
---|
585 | if(MSVCRT___mb_cur_max > 1)
|
---|
586 | {
|
---|
587 | unsigned int c;
|
---|
588 |
|
---|
589 | if (!str)
|
---|
590 | if (!(str = data->mbstok_next)) return NULL;
|
---|
591 |
|
---|
592 | while ((c = _mbsnextc(str)) && _mbschr(delim, c)) {
|
---|
593 | str += c > 255 ? 2 : 1;
|
---|
594 | }
|
---|
595 | if (!*str) return NULL;
|
---|
596 | ret = str++;
|
---|
597 | while ((c = _mbsnextc(str)) && !_mbschr(delim, c)) {
|
---|
598 | str += c > 255 ? 2 : 1;
|
---|
599 | }
|
---|
600 | if (*str) {
|
---|
601 | *str++ = 0;
|
---|
602 | if (c > 255) *str++ = 0;
|
---|
603 | }
|
---|
604 | data->mbstok_next = str;
|
---|
605 | return ret;
|
---|
606 | }
|
---|
607 | return strtok(str, delim); /* ASCII CP */
|
---|
608 | }
|
---|
609 |
|
---|
610 | /*********************************************************************
|
---|
611 | * mbtowc(MSVCRT.@)
|
---|
612 | */
|
---|
613 | int MSVCRT_mbtowc(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n)
|
---|
614 | {
|
---|
615 | dprintf(("MSVCRT: _mbtowc"));
|
---|
616 | if(n <= 0 || !str)
|
---|
617 | return 0;
|
---|
618 | if(!MultiByteToWideChar(CP_ACP, 0, str, n, dst, 1))
|
---|
619 | return 0;
|
---|
620 | /* return the number of bytes from src that have been used */
|
---|
621 | if(!*str)
|
---|
622 | return 0;
|
---|
623 | if(n >= 2 && MSVCRT_isleadbyte(*str) && str[1])
|
---|
624 | return 2;
|
---|
625 | return 1;
|
---|
626 | }
|
---|
627 |
|
---|
628 | /*********************************************************************
|
---|
629 | * _mbbtombc(MSVCRT.@)
|
---|
630 | */
|
---|
631 | unsigned int _mbbtombc(unsigned int c)
|
---|
632 | {
|
---|
633 | dprintf(("MSVCRT: _mbbtombc"));
|
---|
634 | if(MSVCRT___mb_cur_max > 1 &&
|
---|
635 | ((c >= 0x20 && c <=0x7e) ||(c >= 0xa1 && c <= 0xdf)))
|
---|
636 | {
|
---|
637 | /* FIXME: I can't get this function to return anything
|
---|
638 | * different to what I pass it...
|
---|
639 | */
|
---|
640 | }
|
---|
641 | return c; /* ASCII CP or no MB char */
|
---|
642 | }
|
---|
643 |
|
---|
644 | /*********************************************************************
|
---|
645 | * _ismbbkana(MSVCRT.@)
|
---|
646 | */
|
---|
647 | int _ismbbkana(unsigned int c)
|
---|
648 | {
|
---|
649 | dprintf(("MSVCRT: _ismbbkana"));
|
---|
650 | /* FIXME: use lc_ctype when supported, not lc_all */
|
---|
651 | if(MSVCRT_current_lc_all_cp == 932)
|
---|
652 | {
|
---|
653 | /* Japanese/Katakana, CP 932 */
|
---|
654 | return (c >= 0xa1 && c <= 0xdf);
|
---|
655 | }
|
---|
656 | return 0;
|
---|
657 | }
|
---|
658 |
|
---|
659 | /*********************************************************************
|
---|
660 | * _ismbcdigit(MSVCRT.@)
|
---|
661 | */
|
---|
662 | int _ismbcdigit(unsigned int ch)
|
---|
663 | {
|
---|
664 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
665 | dprintf(("MSVCRT: _ismbcdigit"));
|
---|
666 | return (get_char_typeW( wch ) & C1_DIGIT);
|
---|
667 | }
|
---|
668 |
|
---|
669 | /*********************************************************************
|
---|
670 | * _ismbcgraph(MSVCRT.@)
|
---|
671 | */
|
---|
672 | int _ismbcgraph(unsigned int ch)
|
---|
673 | {
|
---|
674 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
675 | return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA));
|
---|
676 | }
|
---|
677 |
|
---|
678 | /*********************************************************************
|
---|
679 | * _ismbcalpha (MSVCRT.@)
|
---|
680 | */
|
---|
681 | int _ismbcalpha(unsigned int ch)
|
---|
682 | {
|
---|
683 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
684 | return (get_char_typeW( wch ) & C1_ALPHA);
|
---|
685 | }
|
---|
686 |
|
---|
687 | /*********************************************************************
|
---|
688 | * _ismbclower (MSVCRT.@)
|
---|
689 | */
|
---|
690 | int _ismbclower(unsigned int ch)
|
---|
691 | {
|
---|
692 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
693 | return (get_char_typeW( wch ) & C1_UPPER);
|
---|
694 | }
|
---|
695 |
|
---|
696 | /*********************************************************************
|
---|
697 | * _ismbcupper (MSVCRT.@)
|
---|
698 | */
|
---|
699 | int _ismbcupper(unsigned int ch)
|
---|
700 | {
|
---|
701 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
702 | return (get_char_typeW( wch ) & C1_LOWER);
|
---|
703 | }
|
---|
704 |
|
---|
705 | /*********************************************************************
|
---|
706 | * _ismbcsymbol(MSVCRT.@)
|
---|
707 | */
|
---|
708 | int _ismbcsymbol(unsigned int ch)
|
---|
709 | {
|
---|
710 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
711 | WORD ctype;
|
---|
712 | if (!GetStringTypeW(CT_CTYPE3, &wch, 1, &ctype))
|
---|
713 | {
|
---|
714 | WARN("GetStringTypeW failed on %x\n", ch);
|
---|
715 | return 0;
|
---|
716 | }
|
---|
717 | return ((ctype & C3_SYMBOL) != 0);
|
---|
718 | }
|
---|
719 |
|
---|
720 | /*********************************************************************
|
---|
721 | * _ismbcalnum (MSVCRT.@)
|
---|
722 | */
|
---|
723 | int _ismbcalnum(unsigned int ch)
|
---|
724 | {
|
---|
725 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
726 | return (get_char_typeW( wch ) & (C1_ALPHA | C1_DIGIT));
|
---|
727 | }
|
---|
728 |
|
---|
729 | /*********************************************************************
|
---|
730 | * _ismbcspace (MSVCRT.@)
|
---|
731 | */
|
---|
732 | int _ismbcspace(unsigned int ch)
|
---|
733 | {
|
---|
734 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
735 | return (get_char_typeW( wch ) & C1_SPACE);
|
---|
736 | }
|
---|
737 |
|
---|
738 | /*********************************************************************
|
---|
739 | * _ismbcprint (MSVCRT.@)
|
---|
740 | */
|
---|
741 | int _ismbcprint(unsigned int ch)
|
---|
742 | {
|
---|
743 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
744 | return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA | C1_SPACE));
|
---|
745 | }
|
---|
746 |
|
---|
747 | /*********************************************************************
|
---|
748 | * _ismbcpunct(MSVCRT.@)
|
---|
749 | */
|
---|
750 | int _ismbcpunct(unsigned int ch)
|
---|
751 | {
|
---|
752 | MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
---|
753 | return (get_char_typeW( wch ) & C1_PUNCT);
|
---|
754 | }
|
---|
755 |
|
---|
756 | /*********************************************************************
|
---|
757 | * _ismbchira(MSVCRT.@)
|
---|
758 | */
|
---|
759 | int _ismbchira(unsigned int c)
|
---|
760 | {
|
---|
761 | /* FIXME: use lc_ctype when supported, not lc_all */
|
---|
762 | if(MSVCRT_current_lc_all_cp == 932)
|
---|
763 | {
|
---|
764 | /* Japanese/Hiragana, CP 932 */
|
---|
765 | return (c >= 0x829f && c <= 0x82f1);
|
---|
766 | }
|
---|
767 | return 0;
|
---|
768 | }
|
---|
769 |
|
---|
770 | /*********************************************************************
|
---|
771 | * _ismbckata(MSVCRT.@)
|
---|
772 | */
|
---|
773 | int _ismbckata(unsigned int c)
|
---|
774 | {
|
---|
775 | /* FIXME: use lc_ctype when supported, not lc_all */
|
---|
776 | if(MSVCRT_current_lc_all_cp == 932)
|
---|
777 | {
|
---|
778 | if(c < 256)
|
---|
779 | return _ismbbkana(c);
|
---|
780 | /* Japanese/Katakana, CP 932 */
|
---|
781 | return (c >= 0x8340 && c <= 0x8396 && c != 0x837f);
|
---|
782 | }
|
---|
783 | return 0;
|
---|
784 | }
|
---|
785 |
|
---|
786 | /*********************************************************************
|
---|
787 | * _ismbblead(MSVCRT.@)
|
---|
788 | */
|
---|
789 | int _ismbblead(unsigned int c)
|
---|
790 | {
|
---|
791 | /* FIXME: should reference MSVCRT_mbctype */
|
---|
792 | return MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(c);
|
---|
793 | }
|
---|
794 |
|
---|
795 |
|
---|
796 | /*********************************************************************
|
---|
797 | * _ismbbtrail(MSVCRT.@)
|
---|
798 | */
|
---|
799 | int _ismbbtrail(unsigned int c)
|
---|
800 | {
|
---|
801 | /* FIXME: should reference MSVCRT_mbctype */
|
---|
802 | return !_ismbblead(c);
|
---|
803 | }
|
---|
804 |
|
---|
805 | /*********************************************************************
|
---|
806 | * _ismbslead(MSVCRT.@)
|
---|
807 | */
|
---|
808 | int _ismbslead(const unsigned char* start, const unsigned char* str)
|
---|
809 | {
|
---|
810 | /* Lead bytes can also be trail bytes if caller messed up
|
---|
811 | * iterating through the string...
|
---|
812 | */
|
---|
813 | if(MSVCRT___mb_cur_max > 1)
|
---|
814 | {
|
---|
815 | while(start < str)
|
---|
816 | start += MSVCRT_isleadbyte(*str) ? 2 : 1;
|
---|
817 |
|
---|
818 | if(start == str)
|
---|
819 | return MSVCRT_isleadbyte(*str);
|
---|
820 | }
|
---|
821 | return 0; /* Must have been a trail, we skipped it */
|
---|
822 | }
|
---|
823 |
|
---|
824 | /*********************************************************************
|
---|
825 | * _ismbstrail(MSVCRT.@)
|
---|
826 | */
|
---|
827 | int _ismbstrail(const unsigned char* start, const unsigned char* str)
|
---|
828 | {
|
---|
829 | /* Must not be a lead, and must be preceeded by one */
|
---|
830 | return !_ismbslead(start, str) && MSVCRT_isleadbyte(str[-1]);
|
---|
831 | }
|
---|
832 |
|
---|
833 | /*********************************************************************
|
---|
834 | * _mbsset(MSVCRT.@)
|
---|
835 | */
|
---|
836 | unsigned char* _mbsset(unsigned char* str, unsigned int c)
|
---|
837 | {
|
---|
838 | unsigned char* ret = str;
|
---|
839 |
|
---|
840 | if(MSVCRT___mb_cur_max == 1 || c < 256)
|
---|
841 | return MSVCRT__strset(str, c); /* ASCII CP or SB char */
|
---|
842 |
|
---|
843 | c &= 0xffff; /* Strip high bits */
|
---|
844 |
|
---|
845 | while(str[0] && str[1])
|
---|
846 | {
|
---|
847 | *str++ = c >> 8;
|
---|
848 | *str++ = c & 0xff;
|
---|
849 | }
|
---|
850 | if(str[0])
|
---|
851 | str[0] = '\0'; /* FIXME: OK to shorten? */
|
---|
852 |
|
---|
853 | return ret;
|
---|
854 | }
|
---|
855 |
|
---|
856 | /*********************************************************************
|
---|
857 | * _mbsnbset(MSVCRT.@)
|
---|
858 | */
|
---|
859 | unsigned char* _mbsnbset(unsigned char *str, unsigned int c, MSVCRT_size_t len)
|
---|
860 | {
|
---|
861 | unsigned char *ret = str;
|
---|
862 |
|
---|
863 | if(!len)
|
---|
864 | return ret;
|
---|
865 |
|
---|
866 | if(MSVCRT___mb_cur_max == 1 || c < 256)
|
---|
867 | return _strnset(str, c, len); /* ASCII CP or SB char */
|
---|
868 |
|
---|
869 | c &= 0xffff; /* Strip high bits */
|
---|
870 |
|
---|
871 | while(str[0] && str[1] && (len > 1))
|
---|
872 | {
|
---|
873 | *str++ = c >> 8;
|
---|
874 | len--;
|
---|
875 | *str++ = c & 0xff;
|
---|
876 | len--;
|
---|
877 | }
|
---|
878 | if(len && str[0]) {
|
---|
879 | /* as per msdn pad with a blank character */
|
---|
880 | str[0] = ' ';
|
---|
881 | }
|
---|
882 |
|
---|
883 | return ret;
|
---|
884 | }
|
---|
885 |
|
---|
886 | /*********************************************************************
|
---|
887 | * _mbsnset(MSVCRT.@)
|
---|
888 | */
|
---|
889 | unsigned char* _mbsnset(unsigned char* str, unsigned int c, MSVCRT_size_t len)
|
---|
890 | {
|
---|
891 | unsigned char *ret = str;
|
---|
892 |
|
---|
893 | if(!len)
|
---|
894 | return ret;
|
---|
895 |
|
---|
896 | if(MSVCRT___mb_cur_max == 1 || c < 256)
|
---|
897 | return MSVCRT__strnset(str, c, len); /* ASCII CP or SB char */
|
---|
898 |
|
---|
899 | c &= 0xffff; /* Strip high bits */
|
---|
900 |
|
---|
901 | while(str[0] && str[1] && len--)
|
---|
902 | {
|
---|
903 | *str++ = c >> 8;
|
---|
904 | *str++ = c & 0xff;
|
---|
905 | }
|
---|
906 | if(len && str[0])
|
---|
907 | str[0] = '\0'; /* FIXME: OK to shorten? */
|
---|
908 |
|
---|
909 | return ret;
|
---|
910 | }
|
---|
911 |
|
---|
912 | /*********************************************************************
|
---|
913 | * _mbsnccnt(MSVCRT.@)
|
---|
914 | * 'c' is for 'character'.
|
---|
915 | */
|
---|
916 | MSVCRT_size_t _mbsnccnt(const unsigned char* str, MSVCRT_size_t len)
|
---|
917 | {
|
---|
918 | MSVCRT_size_t ret;
|
---|
919 | if(MSVCRT___mb_cur_max > 1)
|
---|
920 | {
|
---|
921 | ret=0;
|
---|
922 | while(*str && len-- > 0)
|
---|
923 | {
|
---|
924 | if(MSVCRT_isleadbyte(*str))
|
---|
925 | {
|
---|
926 | if (!len)
|
---|
927 | break;
|
---|
928 | len--;
|
---|
929 | str++;
|
---|
930 | }
|
---|
931 | str++;
|
---|
932 | ret++;
|
---|
933 | }
|
---|
934 | return ret;
|
---|
935 | }
|
---|
936 | ret=strlen(str);
|
---|
937 | return min(ret, len); /* ASCII CP */
|
---|
938 | }
|
---|
939 |
|
---|
940 | /*********************************************************************
|
---|
941 | * _mbsnbcnt(MSVCRT.@)
|
---|
942 | * 'b' is for byte count.
|
---|
943 | */
|
---|
944 | MSVCRT_size_t _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len)
|
---|
945 | {
|
---|
946 | MSVCRT_size_t ret;
|
---|
947 | if(MSVCRT___mb_cur_max > 1)
|
---|
948 | {
|
---|
949 | const unsigned char* xstr = str;
|
---|
950 | while(*xstr && len-- > 0)
|
---|
951 | {
|
---|
952 | if (MSVCRT_isleadbyte(*xstr++))
|
---|
953 | xstr++;
|
---|
954 | }
|
---|
955 | return xstr-str;
|
---|
956 | }
|
---|
957 | ret=strlen(str);
|
---|
958 | return min(ret, len); /* ASCII CP */
|
---|
959 | }
|
---|
960 |
|
---|
961 |
|
---|
962 | /*********************************************************************
|
---|
963 | * _mbsnbcat(MSVCRT.@)
|
---|
964 | */
|
---|
965 | unsigned char* _mbsnbcat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
|
---|
966 | {
|
---|
967 | if(MSVCRT___mb_cur_max > 1)
|
---|
968 | {
|
---|
969 | char *res = dst;
|
---|
970 | while (*dst) {
|
---|
971 | if (MSVCRT_isleadbyte(*dst++)) {
|
---|
972 | if (*dst) {
|
---|
973 | dst++;
|
---|
974 | } else {
|
---|
975 | /* as per msdn overwrite the lead byte in front of '\0' */
|
---|
976 | dst--;
|
---|
977 | break;
|
---|
978 | }
|
---|
979 | }
|
---|
980 | }
|
---|
981 | while (*src && len--) *dst++ = *src++;
|
---|
982 | *dst = '\0';
|
---|
983 | return res;
|
---|
984 | }
|
---|
985 | return strncat(dst, src, len); /* ASCII CP */
|
---|
986 | }
|
---|
987 |
|
---|
988 | /*********************************************************************
|
---|
989 | * _mbsncat(MSVCRT.@)
|
---|
990 | */
|
---|
991 | unsigned char* _mbsncat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
|
---|
992 | {
|
---|
993 | if(MSVCRT___mb_cur_max > 1)
|
---|
994 | {
|
---|
995 | char *res = dst;
|
---|
996 | while (*dst)
|
---|
997 | {
|
---|
998 | if (MSVCRT_isleadbyte(*dst++))
|
---|
999 | dst++;
|
---|
1000 | }
|
---|
1001 | while (*src && len--)
|
---|
1002 | {
|
---|
1003 | *dst++ = *src;
|
---|
1004 | if(MSVCRT_isleadbyte(*src++))
|
---|
1005 | *dst++ = *src++;
|
---|
1006 | }
|
---|
1007 | *dst = '\0';
|
---|
1008 | return res;
|
---|
1009 | }
|
---|
1010 | return strncat(dst, src, len); /* ASCII CP */
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 |
|
---|
1014 | /*********************************************************************
|
---|
1015 | * _mbslwr(MSVCRT.@)
|
---|
1016 | */
|
---|
1017 | unsigned char* _mbslwr(unsigned char* s)
|
---|
1018 | {
|
---|
1019 | if (!s)
|
---|
1020 | return NULL;
|
---|
1021 | if (MSVCRT___mb_cur_max > 1)
|
---|
1022 | {
|
---|
1023 | unsigned int c;
|
---|
1024 | unsigned char* p=s;
|
---|
1025 | while (*s)
|
---|
1026 | {
|
---|
1027 | c = _mbctolower(_mbsnextc(s));
|
---|
1028 | /* Note that I assume that the size of the character is unchanged */
|
---|
1029 | if (c > 255)
|
---|
1030 | {
|
---|
1031 | *s++=(c>>8);
|
---|
1032 | c=c & 0xff;
|
---|
1033 | }
|
---|
1034 | *s++=c;
|
---|
1035 | }
|
---|
1036 | return p;
|
---|
1037 | }
|
---|
1038 | return _strlwr(s);
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 |
|
---|
1042 | /*********************************************************************
|
---|
1043 | * _mbsupr(MSVCRT.@)
|
---|
1044 | */
|
---|
1045 | unsigned char* _mbsupr(unsigned char* s)
|
---|
1046 | {
|
---|
1047 | if (!s)
|
---|
1048 | return NULL;
|
---|
1049 | if (MSVCRT___mb_cur_max > 1)
|
---|
1050 | {
|
---|
1051 | unsigned int c;
|
---|
1052 | unsigned char* p=s;
|
---|
1053 | while (*s)
|
---|
1054 | {
|
---|
1055 | c = _mbctoupper(_mbsnextc(s));
|
---|
1056 | /* Note that I assume that the size of the character is unchanged */
|
---|
1057 | if (c > 255)
|
---|
1058 | {
|
---|
1059 | *s++=(c>>8);
|
---|
1060 | c=c & 0xff;
|
---|
1061 | }
|
---|
1062 | *s++=c;
|
---|
1063 | }
|
---|
1064 | return p;
|
---|
1065 | }
|
---|
1066 | return _strupr(s);
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 |
|
---|
1070 | /*********************************************************************
|
---|
1071 | * _mbsspn (MSVCRT.@)
|
---|
1072 | */
|
---|
1073 | MSVCRT_size_t _mbsspn(const unsigned char* string, const unsigned char* set)
|
---|
1074 | {
|
---|
1075 | const unsigned char *p, *q;
|
---|
1076 |
|
---|
1077 | for (p = string; *p; p++)
|
---|
1078 | {
|
---|
1079 | if (MSVCRT_isleadbyte(*p))
|
---|
1080 | {
|
---|
1081 | for (q = set; *q; q++)
|
---|
1082 | {
|
---|
1083 | if (!q[1])
|
---|
1084 | break;
|
---|
1085 | if ((*p == *q) && (p[1] == q[1]))
|
---|
1086 | break;
|
---|
1087 | q++;
|
---|
1088 | }
|
---|
1089 | if (*++p == '\0')
|
---|
1090 | break;
|
---|
1091 | }
|
---|
1092 | else
|
---|
1093 | for (q = set; *q; q++)
|
---|
1094 | if (*p == *q)
|
---|
1095 | break;
|
---|
1096 | }
|
---|
1097 | return p - string;
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | /*********************************************************************
|
---|
1101 | * _mbscspn(MSVCRT.@)
|
---|
1102 | */
|
---|
1103 | MSVCRT_size_t _mbscspn(const unsigned char* str, const unsigned char* cmp)
|
---|
1104 | {
|
---|
1105 | if (MSVCRT___mb_cur_max > 1)
|
---|
1106 | FIXME("don't handle double character case\n");
|
---|
1107 | return strcspn(str, cmp);
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | /*********************************************************************
|
---|
1111 | * _mbsrev (MSVCRT.@)
|
---|
1112 | */
|
---|
1113 | unsigned char* _mbsrev(unsigned char* str)
|
---|
1114 | {
|
---|
1115 | int i, len = _mbslen(str);
|
---|
1116 | unsigned char *p, *temp=MSVCRT_malloc(len*2);
|
---|
1117 |
|
---|
1118 | if(!temp)
|
---|
1119 | return str;
|
---|
1120 |
|
---|
1121 | /* unpack multibyte string to temp buffer */
|
---|
1122 | p=str;
|
---|
1123 | for(i=0; i<len; i++)
|
---|
1124 | {
|
---|
1125 | if (MSVCRT_isleadbyte(*p))
|
---|
1126 | {
|
---|
1127 | temp[i*2]=*p++;
|
---|
1128 | temp[i*2+1]=*p++;
|
---|
1129 | }
|
---|
1130 | else
|
---|
1131 | {
|
---|
1132 | temp[i*2]=*p++;
|
---|
1133 | temp[i*2+1]=0;
|
---|
1134 | }
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | /* repack it in the reverse order */
|
---|
1138 | p=str;
|
---|
1139 | for(i=len-1; i>=0; i--)
|
---|
1140 | {
|
---|
1141 | if(MSVCRT_isleadbyte(temp[i*2]))
|
---|
1142 | {
|
---|
1143 | *p++=temp[i*2];
|
---|
1144 | *p++=temp[i*2+1];
|
---|
1145 | }
|
---|
1146 | else
|
---|
1147 | {
|
---|
1148 | *p++=temp[i*2];
|
---|
1149 | }
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | MSVCRT_free(temp);
|
---|
1153 |
|
---|
1154 | return str;
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | /*********************************************************************
|
---|
1158 | * _mbspbrk (MSVCRT.@)
|
---|
1159 | */
|
---|
1160 | unsigned char* _mbspbrk(const unsigned char* str, const unsigned char* accept)
|
---|
1161 | {
|
---|
1162 | const unsigned char* p;
|
---|
1163 |
|
---|
1164 | while(*str)
|
---|
1165 | {
|
---|
1166 | for(p = accept; *p; p += (MSVCRT_isleadbyte(*p)?2:1) )
|
---|
1167 | {
|
---|
1168 | if (*p == *str)
|
---|
1169 | if( !MSVCRT_isleadbyte(*p) || ( *(p+1) == *(str+1) ) )
|
---|
1170 | return (unsigned char*)str;
|
---|
1171 | }
|
---|
1172 | str += (MSVCRT_isleadbyte(*str)?2:1);
|
---|
1173 | }
|
---|
1174 | return NULL;
|
---|
1175 | }
|
---|