2 * msvcrt.dll mbcs functions
4 * Copyright 1999 Alexandre Julliard
5 * Copyright 2000 Jon Griffths
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Not currently binary compatible with win32. MSVCRT_mbctype must be
23 * populated correctly and the ismb* functions should reference it.
27 #include "wine/unicode.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
32 unsigned char MSVCRT_mbctype[257];
33 int MSVCRT___mb_cur_max = 1;
35 static MSVCRT_wchar_t msvcrt_mbc_to_wc(unsigned int ch)
45 mbch[0] = (ch >> 8) & 0xff;
49 if (!MultiByteToWideChar(msvcrt_current_lc_all_cp, 0, mbch, n_chars, &chW, 1))
51 WARN("MultiByteToWideChar failed on %x\n", ch);
57 static inline size_t u_strlen( const unsigned char *str )
59 return strlen( (const char*) str );
62 static inline unsigned char* u_strncat( unsigned char* dst, const unsigned char* src, size_t len )
64 return (unsigned char*)strncat( (char*)dst, (const char*)src, len);
67 static inline int u_strcmp( const unsigned char *s1, const unsigned char *s2 )
69 return strcmp( (const char*)s1, (const char*)s2 );
72 static inline int u_strcasecmp( const unsigned char *s1, const unsigned char *s2 )
74 return strcasecmp( (const char*)s1, (const char*)s2 );
77 static inline int u_strncmp( const unsigned char *s1, const unsigned char *s2, size_t len )
79 return strncmp( (const char*)s1, (const char*)s2, len );
82 static inline int u_strncasecmp( const unsigned char *s1, const unsigned char *s2, size_t len )
84 return strncasecmp( (const char*)s1, (const char*)s2, len );
87 static inline unsigned char *u_strchr( const unsigned char *s, unsigned char x )
89 return (unsigned char*) strchr( (const char*)s, x );
92 static inline unsigned char *u_strrchr( const unsigned char *s, unsigned char x )
94 return (unsigned char*) strrchr( (const char*)s, x );
97 static inline unsigned char *u_strtok( unsigned char *s, const unsigned char *delim )
99 return (unsigned char*) strtok( (char*)s, (const char*)delim );
102 static inline unsigned char *u__strset( unsigned char *s, unsigned char c )
104 return (unsigned char*) _strset( (char*)s, c);
107 static inline unsigned char *u__strnset( unsigned char *s, unsigned char c, size_t len )
109 return (unsigned char*) _strnset( (char*)s, c, len );
112 static inline size_t u_strcspn( const unsigned char *s, const unsigned char *rej )
114 return strcspn( (const char *)s, (const char*)rej );
117 /*********************************************************************
118 * __p__mbctype (MSVCRT.@)
120 unsigned char* CDECL __p__mbctype(void)
122 return MSVCRT_mbctype;
125 /*********************************************************************
126 * __p___mb_cur_max(MSVCRT.@)
128 int* CDECL __p___mb_cur_max(void)
130 return &MSVCRT___mb_cur_max;
133 /*********************************************************************
134 * _mbsnextc(MSVCRT.@)
136 unsigned int CDECL _mbsnextc(const unsigned char* str)
138 if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*str))
139 return *str << 8 | str[1];
140 return *str; /* ASCII CP or SB char */
143 /*********************************************************************
144 * _mbctolower(MSVCRT.@)
146 unsigned int CDECL _mbctolower(unsigned int c)
148 if (MSVCRT_isleadbyte(c))
150 FIXME("Handle MBC chars\n");
153 return tolower(c); /* ASCII CP or SB char */
156 /*********************************************************************
157 * _mbctoupper(MSVCRT.@)
159 unsigned int CDECL _mbctoupper(unsigned int c)
161 if (MSVCRT_isleadbyte(c))
163 FIXME("Handle MBC chars\n");
166 return toupper(c); /* ASCII CP or SB char */
169 /*********************************************************************
172 unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cur)
174 if(MSVCRT___mb_cur_max > 1)
175 return (unsigned char *)(_ismbstrail(start,cur-1) ? cur - 2 : cur -1);
177 return (unsigned char *)cur - 1; /* ASCII CP or SB char */
180 /*********************************************************************
183 unsigned char* CDECL _mbsinc(const unsigned char* str)
185 if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*str))
186 return (unsigned char*)str + 2; /* MB char */
188 return (unsigned char*)str + 1; /* ASCII CP or SB char */
191 /*********************************************************************
194 unsigned char* CDECL _mbsninc(const unsigned char* str, MSVCRT_size_t num)
198 if(MSVCRT___mb_cur_max > 1)
202 return (unsigned char*)str;
204 return (unsigned char*)str + num; /* ASCII CP */
207 /*********************************************************************
210 unsigned int CDECL _mbclen(const unsigned char* str)
212 return MSVCRT_isleadbyte(*str) ? 2 : 1;
215 /*********************************************************************
218 int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size)
220 if (str && *str && size)
222 if(MSVCRT___mb_cur_max == 1)
223 return 1; /* ASCII CP */
225 return !MSVCRT_isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
230 /*********************************************************************
233 MSVCRT_size_t CDECL _mbslen(const unsigned char* str)
235 if(MSVCRT___mb_cur_max > 1)
237 MSVCRT_size_t len = 0;
240 str += MSVCRT_isleadbyte(*str) ? 2 : 1;
245 return u_strlen(str); /* ASCII CP */
248 /*********************************************************************
249 * _mbstrlen(MSVCRT.@)
251 MSVCRT_size_t CDECL _mbstrlen(const char* str)
253 if(MSVCRT___mb_cur_max > 1)
255 MSVCRT_size_t len = 0;
258 /* FIXME: According to the documentation we are supposed to test for
259 * multi-byte character validity. Whatever that means
261 str += MSVCRT_isleadbyte(*str) ? 2 : 1;
266 return strlen(str); /* ASCII CP */
269 /*********************************************************************
272 void CDECL _mbccpy(unsigned char* dest, const unsigned char* src)
275 if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*src))
276 *++dest = *++src; /* MB char */
279 /*********************************************************************
282 unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
284 unsigned char* ret = dst;
287 if(MSVCRT___mb_cur_max > 1)
293 if (MSVCRT_isleadbyte(*src++))
302 if (!(*dst++ = *src++)) break;
305 while (n--) *dst++ = 0;
309 /*********************************************************************
310 * _mbsnbcpy(MSVCRT.@)
312 unsigned char* CDECL _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
314 unsigned char* ret = dst;
317 if(MSVCRT___mb_cur_max > 1)
319 while (*src && (n > 1))
323 if (MSVCRT_isleadbyte(*src++))
329 if (*src && n && !MSVCRT_isleadbyte(*src))
331 /* If the last character is a multi-byte character then
332 * we cannot copy it since we have only one byte left
343 if (!(*dst++ = *src++)) break;
346 while (n--) *dst++ = 0;
350 /*********************************************************************
353 int CDECL _mbscmp(const unsigned char* str, const unsigned char* cmp)
355 if(MSVCRT___mb_cur_max > 1)
357 unsigned int strc, cmpc;
360 return *cmp ? -1 : 0;
363 strc = _mbsnextc(str);
364 cmpc = _mbsnextc(cmp);
366 return strc < cmpc ? -1 : 1;
367 str +=(strc > 255) ? 2 : 1;
368 cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
371 return u_strcmp(str, cmp); /* ASCII CP */
374 /*********************************************************************
375 * _mbsicoll(MSVCRT.@)
376 * FIXME: handle locales.
378 int CDECL _mbsicoll(const unsigned char* str, const unsigned char* cmp)
380 if(MSVCRT___mb_cur_max > 1)
382 unsigned int strc, cmpc;
385 return *cmp ? -1 : 0;
388 strc = _mbctolower(_mbsnextc(str));
389 cmpc = _mbctolower(_mbsnextc(cmp));
391 return strc < cmpc ? -1 : 1;
392 str +=(strc > 255) ? 2 : 1;
393 cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
396 return u_strcasecmp(str, cmp); /* ASCII CP */
399 /*********************************************************************
401 * Performs a case-sensitive comparison according to the current code page
403 * _NLSCMPERROR if error
404 * FIXME: handle locales.
406 int CDECL _mbscoll(const unsigned char* str, const unsigned char* cmp)
408 if(MSVCRT___mb_cur_max > 1)
410 unsigned int strc, cmpc;
413 return *cmp ? -1 : 0;
416 strc = _mbsnextc(str);
417 cmpc = _mbsnextc(cmp);
419 return strc < cmpc ? -1 : 1;
420 str +=(strc > 255) ? 2 : 1;
421 cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
424 return u_strcmp(str, cmp); /* ASCII CP */
428 /*********************************************************************
431 int CDECL _mbsicmp(const unsigned char* str, const unsigned char* cmp)
433 if(MSVCRT___mb_cur_max > 1)
435 unsigned int strc, cmpc;
438 return *cmp ? -1 : 0;
441 strc = _mbctolower(_mbsnextc(str));
442 cmpc = _mbctolower(_mbsnextc(cmp));
444 return strc < cmpc ? -1 : 1;
445 str +=(strc > 255) ? 2 : 1;
446 cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
449 return u_strcasecmp(str, cmp); /* ASCII CP */
452 /*********************************************************************
455 int CDECL _mbsncmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
460 if(MSVCRT___mb_cur_max > 1)
462 unsigned int strc, cmpc;
467 return *cmp ? -1 : 0;
470 strc = _mbsnextc(str);
471 cmpc = _mbsnextc(cmp);
473 return strc < cmpc ? -1 : 1;
474 inc=(strc > 255) ? 2 : 1; /* Equal, use same increment */
478 return 0; /* Matched len chars */
480 return u_strncmp(str, cmp, len); /* ASCII CP */
483 /*********************************************************************
484 * _mbsnbcmp(MSVCRT.@)
486 int CDECL _mbsnbcmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
490 if(MSVCRT___mb_cur_max > 1)
492 unsigned int strc, cmpc;
497 return *cmp ? -1 : 0;
500 if (MSVCRT_isleadbyte(*str))
502 strc=(len>=2)?_mbsnextc(str):0;
510 if (MSVCRT_isleadbyte(*cmp))
511 cmpc=(len>=2)?_mbsnextc(cmp):0;
515 return strc < cmpc ? -1 : 1;
520 return 0; /* Matched len chars */
522 return u_strncmp(str,cmp,len);
525 /*********************************************************************
526 * _mbsnicmp(MSVCRT.@)
528 * Compare two multibyte strings case insensitively to 'len' characters.
530 int CDECL _mbsnicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
532 /* FIXME: No tolower() for mb strings yet */
533 if(MSVCRT___mb_cur_max > 1)
535 unsigned int strc, cmpc;
539 return *cmp ? -1 : 0;
542 strc = _mbctolower(_mbsnextc(str));
543 cmpc = _mbctolower(_mbsnextc(cmp));
545 return strc < cmpc ? -1 : 1;
546 str +=(strc > 255) ? 2 : 1;
547 cmp +=(strc > 255) ? 2 : 1; /* Equal, use same increment */
549 return 0; /* Matched len chars */
551 return u_strncasecmp(str, cmp, len); /* ASCII CP */
554 /*********************************************************************
555 * _mbsnbicmp(MSVCRT.@)
557 int CDECL _mbsnbicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
561 if(MSVCRT___mb_cur_max > 1)
563 unsigned int strc, cmpc;
568 return *cmp ? -1 : 0;
571 if (MSVCRT_isleadbyte(*str))
573 strc=(len>=2)?_mbsnextc(str):0;
581 if (MSVCRT_isleadbyte(*cmp))
582 cmpc=(len>=2)?_mbsnextc(cmp):0;
585 strc = _mbctolower(strc);
586 cmpc = _mbctolower(cmpc);
588 return strc < cmpc ? -1 : 1;
593 return 0; /* Matched len bytes */
595 return u_strncmp(str,cmp,len);
598 /*********************************************************************
601 unsigned char * CDECL _mbscat( unsigned char *dst, const unsigned char *src )
603 strcat( (char *)dst, (const char *)src );
607 /*********************************************************************
610 unsigned char* CDECL _mbscpy( unsigned char *dst, const unsigned char *src )
612 strcpy( (char *)dst, (const char *)src );
616 /*********************************************************************
619 unsigned char * CDECL _mbsstr(const unsigned char *haystack, const unsigned char *needle)
621 return (unsigned char *)strstr( (const char *)haystack, (const char *)needle );
624 /*********************************************************************
627 * Find a multibyte character in a multibyte string.
629 unsigned char* CDECL _mbschr(const unsigned char* s, unsigned int x)
631 if(MSVCRT___mb_cur_max > 1)
638 return (unsigned char*)s;
641 s += c > 255 ? 2 : 1;
644 return u_strchr(s, x); /* ASCII CP */
647 /*********************************************************************
650 unsigned char* CDECL _mbsrchr(const unsigned char* s, unsigned int x)
652 if(MSVCRT___mb_cur_max > 1)
655 unsigned char* match=NULL;
661 match=(unsigned char*)s;
664 s +=(c > 255) ? 2 : 1;
667 return u_strrchr(s, x);
670 /*********************************************************************
673 * Find and extract tokens from strings
675 unsigned char* CDECL _mbstok(unsigned char *str, const unsigned char *delim)
677 thread_data_t *data = msvcrt_get_thread_data();
680 if(MSVCRT___mb_cur_max > 1)
685 if (!(str = data->mbstok_next)) return NULL;
687 while ((c = _mbsnextc(str)) && _mbschr(delim, c)) {
688 str += c > 255 ? 2 : 1;
690 if (!*str) return NULL;
692 while ((c = _mbsnextc(str)) && !_mbschr(delim, c)) {
693 str += c > 255 ? 2 : 1;
697 if (c > 255) *str++ = 0;
699 data->mbstok_next = str;
702 return u_strtok(str, delim); /* ASCII CP */
705 /*********************************************************************
708 int CDECL MSVCRT_mbtowc(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n)
710 /* temp var needed because MultiByteToWideChar wants non NULL destination */
711 MSVCRT_wchar_t tmpdst = '\0';
715 if(!MultiByteToWideChar(CP_ACP, 0, str, n, &tmpdst, 1))
719 /* return the number of bytes from src that have been used */
722 if(n >= 2 && MSVCRT_isleadbyte(*str) && str[1])
727 /*********************************************************************
728 * _mbbtombc(MSVCRT.@)
730 unsigned int CDECL _mbbtombc(unsigned int c)
732 if(MSVCRT___mb_cur_max > 1 &&
733 ((c >= 0x20 && c <=0x7e) ||(c >= 0xa1 && c <= 0xdf)))
735 /* FIXME: I can't get this function to return anything
736 * different from what I pass it...
739 return c; /* ASCII CP or no MB char */
742 /*********************************************************************
743 * _ismbbkana(MSVCRT.@)
745 int CDECL _ismbbkana(unsigned int c)
747 /* FIXME: use lc_ctype when supported, not lc_all */
748 if(msvcrt_current_lc_all_cp == 932)
750 /* Japanese/Katakana, CP 932 */
751 return (c >= 0xa1 && c <= 0xdf);
756 /*********************************************************************
757 * _ismbcdigit(MSVCRT.@)
759 int CDECL _ismbcdigit(unsigned int ch)
761 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
762 return (get_char_typeW( wch ) & C1_DIGIT);
765 /*********************************************************************
766 * _ismbcgraph(MSVCRT.@)
768 int CDECL _ismbcgraph(unsigned int ch)
770 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
771 return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA));
774 /*********************************************************************
775 * _ismbcalpha (MSVCRT.@)
777 int CDECL _ismbcalpha(unsigned int ch)
779 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
780 return (get_char_typeW( wch ) & C1_ALPHA);
783 /*********************************************************************
784 * _ismbclower (MSVCRT.@)
786 int CDECL _ismbclower(unsigned int ch)
788 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
789 return (get_char_typeW( wch ) & C1_UPPER);
792 /*********************************************************************
793 * _ismbcupper (MSVCRT.@)
795 int CDECL _ismbcupper(unsigned int ch)
797 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
798 return (get_char_typeW( wch ) & C1_LOWER);
801 /*********************************************************************
802 * _ismbcsymbol(MSVCRT.@)
804 int CDECL _ismbcsymbol(unsigned int ch)
806 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
808 if (!GetStringTypeW(CT_CTYPE3, &wch, 1, &ctype))
810 WARN("GetStringTypeW failed on %x\n", ch);
813 return ((ctype & C3_SYMBOL) != 0);
816 /*********************************************************************
817 * _ismbcalnum (MSVCRT.@)
819 int CDECL _ismbcalnum(unsigned int ch)
821 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
822 return (get_char_typeW( wch ) & (C1_ALPHA | C1_DIGIT));
825 /*********************************************************************
826 * _ismbcspace (MSVCRT.@)
828 int CDECL _ismbcspace(unsigned int ch)
830 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
831 return (get_char_typeW( wch ) & C1_SPACE);
834 /*********************************************************************
835 * _ismbcprint (MSVCRT.@)
837 int CDECL _ismbcprint(unsigned int ch)
839 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
840 return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA | C1_SPACE));
843 /*********************************************************************
844 * _ismbcpunct(MSVCRT.@)
846 int CDECL _ismbcpunct(unsigned int ch)
848 MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
849 return (get_char_typeW( wch ) & C1_PUNCT);
852 /*********************************************************************
853 * _ismbchira(MSVCRT.@)
855 int CDECL _ismbchira(unsigned int c)
857 /* FIXME: use lc_ctype when supported, not lc_all */
858 if(msvcrt_current_lc_all_cp == 932)
860 /* Japanese/Hiragana, CP 932 */
861 return (c >= 0x829f && c <= 0x82f1);
866 /*********************************************************************
867 * _ismbckata(MSVCRT.@)
869 int CDECL _ismbckata(unsigned int c)
871 /* FIXME: use lc_ctype when supported, not lc_all */
872 if(msvcrt_current_lc_all_cp == 932)
875 return _ismbbkana(c);
876 /* Japanese/Katakana, CP 932 */
877 return (c >= 0x8340 && c <= 0x8396 && c != 0x837f);
882 /*********************************************************************
883 * _ismbblead(MSVCRT.@)
885 int CDECL _ismbblead(unsigned int c)
887 /* FIXME: should reference MSVCRT_mbctype */
888 return MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(c);
892 /*********************************************************************
893 * _ismbbtrail(MSVCRT.@)
895 int CDECL _ismbbtrail(unsigned int c)
897 /* FIXME: should reference MSVCRT_mbctype */
898 return !_ismbblead(c);
901 /*********************************************************************
902 * _ismbslead(MSVCRT.@)
904 int CDECL _ismbslead(const unsigned char* start, const unsigned char* str)
906 /* Lead bytes can also be trail bytes if caller messed up
907 * iterating through the string...
909 if(MSVCRT___mb_cur_max > 1)
912 start += MSVCRT_isleadbyte(*str) ? 2 : 1;
915 return MSVCRT_isleadbyte(*str);
917 return 0; /* Must have been a trail, we skipped it */
920 /*********************************************************************
921 * _ismbstrail(MSVCRT.@)
923 int CDECL _ismbstrail(const unsigned char* start, const unsigned char* str)
925 /* Must not be a lead, and must be preceded by one */
926 return !_ismbslead(start, str) && MSVCRT_isleadbyte(str[-1]);
929 /*********************************************************************
932 unsigned char* CDECL _mbsset(unsigned char* str, unsigned int c)
934 unsigned char* ret = str;
936 if(MSVCRT___mb_cur_max == 1 || c < 256)
937 return u__strset(str, c); /* ASCII CP or SB char */
939 c &= 0xffff; /* Strip high bits */
941 while(str[0] && str[1])
947 str[0] = '\0'; /* FIXME: OK to shorten? */
952 /*********************************************************************
953 * _mbsnbset(MSVCRT.@)
955 unsigned char* CDECL _mbsnbset(unsigned char *str, unsigned int c, MSVCRT_size_t len)
957 unsigned char *ret = str;
962 if(MSVCRT___mb_cur_max == 1 || c < 256)
963 return u__strnset(str, c, len); /* ASCII CP or SB char */
965 c &= 0xffff; /* Strip high bits */
967 while(str[0] && str[1] && (len > 1))
975 /* as per msdn pad with a blank character */
982 /*********************************************************************
985 unsigned char* CDECL _mbsnset(unsigned char* str, unsigned int c, MSVCRT_size_t len)
987 unsigned char *ret = str;
992 if(MSVCRT___mb_cur_max == 1 || c < 256)
993 return u__strnset(str, c, len); /* ASCII CP or SB char */
995 c &= 0xffff; /* Strip high bits */
997 while(str[0] && str[1] && len--)
1003 str[0] = '\0'; /* FIXME: OK to shorten? */
1008 /*********************************************************************
1009 * _mbsnccnt(MSVCRT.@)
1010 * 'c' is for 'character'.
1012 MSVCRT_size_t CDECL _mbsnccnt(const unsigned char* str, MSVCRT_size_t len)
1015 if(MSVCRT___mb_cur_max > 1)
1018 while(*str && len-- > 0)
1020 if(MSVCRT_isleadbyte(*str))
1033 return min(ret, len); /* ASCII CP */
1036 /*********************************************************************
1037 * _mbsnbcnt(MSVCRT.@)
1038 * 'b' is for byte count.
1040 MSVCRT_size_t CDECL _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len)
1043 if(MSVCRT___mb_cur_max > 1)
1045 const unsigned char* xstr = str;
1046 while(*xstr && len-- > 0)
1048 if (MSVCRT_isleadbyte(*xstr++))
1054 return min(ret, len); /* ASCII CP */
1057 /*********************************************************************
1058 * _mbsnbcat(MSVCRT.@)
1060 unsigned char* CDECL _mbsnbcat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
1062 if(MSVCRT___mb_cur_max > 1)
1064 unsigned char *res = dst;
1066 if (MSVCRT_isleadbyte(*dst++)) {
1070 /* as per msdn overwrite the lead byte in front of '\0' */
1076 while (*src && len--) *dst++ = *src++;
1080 return u_strncat(dst, src, len); /* ASCII CP */
1084 /*********************************************************************
1085 * _mbsncat(MSVCRT.@)
1087 unsigned char* CDECL _mbsncat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
1089 if(MSVCRT___mb_cur_max > 1)
1091 unsigned char *res = dst;
1094 if (MSVCRT_isleadbyte(*dst++))
1097 while (*src && len--)
1100 if(MSVCRT_isleadbyte(*src++))
1106 return u_strncat(dst, src, len); /* ASCII CP */
1110 /*********************************************************************
1113 unsigned char* CDECL _mbslwr(unsigned char* s)
1115 unsigned char *ret = s;
1118 if (MSVCRT___mb_cur_max > 1)
1123 c = _mbctolower(_mbsnextc(s));
1124 /* Note that I assume that the size of the character is unchanged */
1133 else for ( ; *s; s++) *s = tolower(*s);
1138 /*********************************************************************
1141 unsigned char* CDECL _mbsupr(unsigned char* s)
1143 unsigned char *ret = s;
1146 if (MSVCRT___mb_cur_max > 1)
1151 c = _mbctoupper(_mbsnextc(s));
1152 /* Note that I assume that the size of the character is unchanged */
1161 else for ( ; *s; s++) *s = toupper(*s);
1166 /*********************************************************************
1167 * _mbsspn (MSVCRT.@)
1169 MSVCRT_size_t CDECL _mbsspn(const unsigned char* string, const unsigned char* set)
1171 const unsigned char *p, *q;
1173 for (p = string; *p; p++)
1175 if (MSVCRT_isleadbyte(*p))
1177 for (q = set; *q; q++)
1181 if ((*p == *q) && (p[1] == q[1]))
1185 if (!q[0] || !q[1]) break;
1189 for (q = set; *q; q++)
1198 /*********************************************************************
1199 * _mbscspn(MSVCRT.@)
1201 MSVCRT_size_t CDECL _mbscspn(const unsigned char* str, const unsigned char* cmp)
1203 if (MSVCRT___mb_cur_max > 1)
1204 FIXME("don't handle double character case\n");
1205 return u_strcspn(str, cmp);
1208 /*********************************************************************
1209 * _mbsrev (MSVCRT.@)
1211 unsigned char* CDECL _mbsrev(unsigned char* str)
1213 int i, len = _mbslen(str);
1214 unsigned char *p, *temp=MSVCRT_malloc(len*2);
1219 /* unpack multibyte string to temp buffer */
1221 for(i=0; i<len; i++)
1223 if (MSVCRT_isleadbyte(*p))
1235 /* repack it in the reverse order */
1237 for(i=len-1; i>=0; i--)
1239 if(MSVCRT_isleadbyte(temp[i*2]))
1255 /*********************************************************************
1256 * _mbspbrk (MSVCRT.@)
1258 unsigned char* CDECL _mbspbrk(const unsigned char* str, const unsigned char* accept)
1260 const unsigned char* p;
1264 for(p = accept; *p; p += (MSVCRT_isleadbyte(*p)?2:1) )
1267 if( !MSVCRT_isleadbyte(*p) || ( *(p+1) == *(str+1) ) )
1268 return (unsigned char*)str;
1270 str += (MSVCRT_isleadbyte(*str)?2:1);