2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll mbcs functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Alexandre Julliard
|
|
|
|
* Copyright 2000 Jon Griffths
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2001-01-11 00:59:25 +01:00
|
|
|
* FIXME
|
2001-01-22 03:22:26 +01:00
|
|
|
* Not currently binary compatible with win32. MSVCRT_mbctype must be
|
2001-01-11 00:59:25 +01:00
|
|
|
* populated correctly and the ismb* functions should reference it.
|
|
|
|
*/
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
2002-11-19 01:52:38 +01:00
|
|
|
#include "wine/unicode.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
2007-02-06 00:34:31 +01:00
|
|
|
#include "msvcrt/mbctype.h"
|
2007-11-15 16:32:33 +01:00
|
|
|
#include "msvcrt/errno.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
unsigned char MSVCRT_mbctype[257];
|
2007-08-22 19:47:01 +02:00
|
|
|
static int g_mbcp_is_multibyte = 0;
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
int MSVCRT___mb_cur_max = 1;
|
2007-08-20 05:19:37 +02:00
|
|
|
extern int MSVCRT___lc_collate_cp;
|
|
|
|
|
|
|
|
/* It seems that the data about valid trail bytes is not available from kernel32
|
|
|
|
* so we have to store is here. The format is the same as for lead bytes in CPINFO */
|
|
|
|
struct cp_extra_info_t
|
|
|
|
{
|
|
|
|
int cp;
|
|
|
|
BYTE TrailBytes[MAX_LEADBYTES];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct cp_extra_info_t g_cpextrainfo[] =
|
|
|
|
{
|
|
|
|
{932, {0x40, 0x7e, 0x80, 0xfc, 0, 0}},
|
|
|
|
{936, {0x40, 0xfe, 0, 0}},
|
|
|
|
{949, {0x41, 0xfe, 0, 0}},
|
|
|
|
{950, {0x40, 0x7e, 0xa1, 0xfe, 0, 0}},
|
2007-08-23 03:41:32 +02:00
|
|
|
{20932, {1, 255, 0, 0}}, /* seems to give different results on different systems */
|
2007-08-20 05:19:37 +02:00
|
|
|
{0, {1, 255, 0, 0}} /* match all with FIXME */
|
|
|
|
};
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2002-12-19 05:21:30 +01:00
|
|
|
static MSVCRT_wchar_t msvcrt_mbc_to_wc(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t chW;
|
2002-11-19 01:52:38 +01:00
|
|
|
char mbch[2];
|
|
|
|
int n_chars;
|
|
|
|
|
|
|
|
if (ch <= 0xff) {
|
|
|
|
mbch[0] = ch;
|
|
|
|
n_chars = 1;
|
|
|
|
} else {
|
|
|
|
mbch[0] = (ch >> 8) & 0xff;
|
|
|
|
mbch[1] = ch & 0xff;
|
|
|
|
n_chars = 2;
|
|
|
|
}
|
2007-01-16 12:08:59 +01:00
|
|
|
if (!MultiByteToWideChar(MSVCRT___lc_codepage, 0, mbch, n_chars, &chW, 1))
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
|
|
|
WARN("MultiByteToWideChar failed on %x\n", ch);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return chW;
|
|
|
|
}
|
|
|
|
|
2005-08-23 20:49:18 +02:00
|
|
|
static inline size_t u_strlen( const unsigned char *str )
|
|
|
|
{
|
|
|
|
return strlen( (const char*) str );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char* u_strncat( unsigned char* dst, const unsigned char* src, size_t len )
|
|
|
|
{
|
|
|
|
return (unsigned char*)strncat( (char*)dst, (const char*)src, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int u_strcmp( const unsigned char *s1, const unsigned char *s2 )
|
|
|
|
{
|
|
|
|
return strcmp( (const char*)s1, (const char*)s2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int u_strcasecmp( const unsigned char *s1, const unsigned char *s2 )
|
|
|
|
{
|
|
|
|
return strcasecmp( (const char*)s1, (const char*)s2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int u_strncmp( const unsigned char *s1, const unsigned char *s2, size_t len )
|
|
|
|
{
|
|
|
|
return strncmp( (const char*)s1, (const char*)s2, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int u_strncasecmp( const unsigned char *s1, const unsigned char *s2, size_t len )
|
|
|
|
{
|
|
|
|
return strncasecmp( (const char*)s1, (const char*)s2, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *u_strchr( const unsigned char *s, unsigned char x )
|
|
|
|
{
|
|
|
|
return (unsigned char*) strchr( (const char*)s, x );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *u_strrchr( const unsigned char *s, unsigned char x )
|
|
|
|
{
|
|
|
|
return (unsigned char*) strrchr( (const char*)s, x );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *u_strtok( unsigned char *s, const unsigned char *delim )
|
|
|
|
{
|
|
|
|
return (unsigned char*) strtok( (char*)s, (const char*)delim );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *u__strset( unsigned char *s, unsigned char c )
|
|
|
|
{
|
|
|
|
return (unsigned char*) _strset( (char*)s, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *u__strnset( unsigned char *s, unsigned char c, size_t len )
|
|
|
|
{
|
|
|
|
return (unsigned char*) _strnset( (char*)s, c, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t u_strcspn( const unsigned char *s, const unsigned char *rej )
|
|
|
|
{
|
|
|
|
return strcspn( (const char *)s, (const char*)rej );
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __p__mbctype (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL __p__mbctype(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return MSVCRT_mbctype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p___mb_cur_max(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int* CDECL __p___mb_cur_max(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return &MSVCRT___mb_cur_max;
|
|
|
|
}
|
|
|
|
|
2007-08-20 05:19:37 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _setmbcp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _setmbcp(int cp)
|
|
|
|
{
|
|
|
|
int newcp;
|
|
|
|
CPINFO cpi;
|
|
|
|
BYTE *bytes;
|
|
|
|
WORD chartypes[256];
|
|
|
|
WORD *curr_type;
|
|
|
|
char bufA[256];
|
|
|
|
WCHAR bufW[256];
|
|
|
|
int charcount;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (cp)
|
|
|
|
{
|
|
|
|
case _MB_CP_ANSI:
|
|
|
|
newcp = GetACP();
|
|
|
|
break;
|
|
|
|
case _MB_CP_OEM:
|
|
|
|
newcp = GetOEMCP();
|
|
|
|
break;
|
|
|
|
case _MB_CP_LOCALE:
|
|
|
|
newcp = MSVCRT___lc_codepage;
|
|
|
|
break;
|
|
|
|
case _MB_CP_SBCS:
|
|
|
|
newcp = 20127; /* ASCII */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newcp = cp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetCPInfo(newcp, &cpi))
|
|
|
|
{
|
|
|
|
WARN("Codepage %d not found\n", newcp);
|
|
|
|
msvcrt_set_errno(MSVCRT_EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup the _mbctype */
|
|
|
|
memset(MSVCRT_mbctype, 0, sizeof(MSVCRT_mbctype));
|
|
|
|
|
|
|
|
bytes = cpi.LeadByte;
|
|
|
|
while (bytes[0] || bytes[1])
|
|
|
|
{
|
|
|
|
for (i = bytes[0]; i <= bytes[1]; i++)
|
|
|
|
MSVCRT_mbctype[i + 1] |= _M1;
|
|
|
|
bytes += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi.MaxCharSize > 1)
|
|
|
|
{
|
|
|
|
/* trail bytes not available through kernel32 but stored in a structure in msvcrt */
|
|
|
|
struct cp_extra_info_t *cpextra = g_cpextrainfo;
|
2007-08-22 19:47:01 +02:00
|
|
|
|
|
|
|
g_mbcp_is_multibyte = 1;
|
2007-08-20 05:19:37 +02:00
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (cpextra->cp == 0 || cpextra->cp == newcp)
|
|
|
|
{
|
|
|
|
if (cpextra->cp == 0)
|
|
|
|
FIXME("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp);
|
|
|
|
|
|
|
|
bytes = cpextra->TrailBytes;
|
|
|
|
while (bytes[0] || bytes[1])
|
|
|
|
{
|
|
|
|
for (i = bytes[0]; i <= bytes[1]; i++)
|
|
|
|
MSVCRT_mbctype[i + 1] |= _M2;
|
|
|
|
bytes += 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cpextra++;
|
|
|
|
}
|
|
|
|
}
|
2007-08-22 19:47:01 +02:00
|
|
|
else
|
|
|
|
g_mbcp_is_multibyte = 0;
|
2007-08-20 05:19:37 +02:00
|
|
|
|
|
|
|
/* we can't use GetStringTypeA directly because we don't have a locale - only a code page
|
|
|
|
*/
|
|
|
|
charcount = 0;
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
if (!(MSVCRT_mbctype[i + 1] & _M1))
|
|
|
|
bufA[charcount++] = i;
|
|
|
|
|
|
|
|
ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount);
|
|
|
|
if (ret != charcount)
|
|
|
|
ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());
|
|
|
|
|
|
|
|
GetStringTypeW(CT_CTYPE1, bufW, charcount, chartypes);
|
|
|
|
|
|
|
|
curr_type = chartypes;
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
if (!(MSVCRT_mbctype[i + 1] & _M1))
|
|
|
|
{
|
|
|
|
if ((*curr_type) & C1_UPPER)
|
|
|
|
MSVCRT_mbctype[i + 1] |= _SBUP;
|
|
|
|
if ((*curr_type) & C1_LOWER)
|
|
|
|
MSVCRT_mbctype[i + 1] |= _SBLOW;
|
|
|
|
curr_type++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newcp == 932) /* CP932 only - set _MP and _MS */
|
|
|
|
{
|
|
|
|
/* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1
|
|
|
|
* and CT_CTYPE3. But as of Wine 0.9.43 we return wrong values what makes
|
|
|
|
* it hard. As this is set only for codepage 932 we hardcode it what gives
|
|
|
|
* also faster execution.
|
|
|
|
*/
|
|
|
|
for (i = 161; i <= 165; i++)
|
|
|
|
MSVCRT_mbctype[i + 1] |= _MP;
|
|
|
|
for (i = 166; i <= 223; i++)
|
|
|
|
MSVCRT_mbctype[i + 1] |= _MS;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSVCRT___lc_collate_cp = MSVCRT___lc_codepage = newcp;
|
|
|
|
TRACE("(%d) -> %d\n", cp, MSVCRT___lc_codepage);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getmbcp (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _getmbcp(void)
|
|
|
|
{
|
|
|
|
return MSVCRT___lc_codepage;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnextc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _mbsnextc(const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-20 07:34:12 +02:00
|
|
|
if(_ismbblead(*str))
|
2001-01-11 00:59:25 +01:00
|
|
|
return *str << 8 | str[1];
|
2007-08-20 07:34:12 +02:00
|
|
|
return *str;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbctolower(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _mbctolower(unsigned int c)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
if (MSVCRT_isleadbyte(c))
|
|
|
|
{
|
|
|
|
FIXME("Handle MBC chars\n");
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return tolower(c); /* ASCII CP or SB char */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbctoupper(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _mbctoupper(unsigned int c)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
if (MSVCRT_isleadbyte(c))
|
|
|
|
{
|
|
|
|
FIXME("Handle MBC chars\n");
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return toupper(c); /* ASCII CP or SB char */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsdec(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cur)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
2005-04-18 11:54:03 +02:00
|
|
|
return (unsigned char *)(_ismbstrail(start,cur-1) ? cur - 2 : cur -1);
|
2001-12-05 23:11:35 +01:00
|
|
|
|
2005-04-18 11:54:03 +02:00
|
|
|
return (unsigned char *)cur - 1; /* ASCII CP or SB char */
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:11:17 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbclen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned int CDECL _mbclen(const unsigned char* str)
|
|
|
|
{
|
|
|
|
return _ismbblead(*str) ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsinc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsinc(const unsigned char* str)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-23 04:14:30 +02:00
|
|
|
return (unsigned char *)(str + _mbclen(str));
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsninc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsninc(const unsigned char* str, MSVCRT_size_t num)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-23 04:14:30 +02:00
|
|
|
if(!str)
|
2001-12-05 23:11:35 +01:00
|
|
|
return NULL;
|
2007-08-23 04:14:30 +02:00
|
|
|
|
|
|
|
while (num > 0 && *str)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-23 04:14:30 +02:00
|
|
|
if (_ismbblead(*str))
|
|
|
|
{
|
|
|
|
if (!*(str+1))
|
|
|
|
break;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
num--;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2007-08-23 04:14:30 +02:00
|
|
|
|
|
|
|
return (unsigned char*)str;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbslen(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL _mbslen(const unsigned char* str)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-20 07:46:56 +02:00
|
|
|
MSVCRT_size_t len = 0;
|
|
|
|
while(*str)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-20 07:46:56 +02:00
|
|
|
if (_ismbblead(*str))
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-20 07:46:56 +02:00
|
|
|
str++;
|
|
|
|
if (!*str) /* count only full chars */
|
|
|
|
break;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2007-08-20 07:46:56 +02:00
|
|
|
str++;
|
|
|
|
len++;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2007-08-20 07:46:56 +02:00
|
|
|
return len;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbccpy(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL _mbccpy(unsigned char* dest, const unsigned char* src)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-11-21 14:34:29 +01:00
|
|
|
*dest = *src;
|
2007-08-22 19:47:01 +02:00
|
|
|
if(_ismbblead(*src))
|
2005-11-21 14:34:29 +01:00
|
|
|
*++dest = *++src; /* MB char */
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsncpy(MSVCRT.@)
|
2007-08-22 19:47:01 +02:00
|
|
|
* REMARKS
|
|
|
|
* The parameter n is the number or characters to copy, not the size of
|
|
|
|
* the buffer. Use _mbsnbcpy for a function analogical to strncpy
|
2001-12-05 23:11:35 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-04-25 17:51:45 +02:00
|
|
|
unsigned char* ret = dst;
|
2001-12-05 23:11:35 +01:00
|
|
|
if(!n)
|
|
|
|
return dst;
|
2007-08-22 19:47:01 +02:00
|
|
|
if (g_mbcp_is_multibyte)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-04-25 17:51:45 +02:00
|
|
|
while (*src && n)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-04-25 17:51:45 +02:00
|
|
|
n--;
|
2007-08-22 19:47:01 +02:00
|
|
|
if (_ismbblead(*src))
|
|
|
|
{
|
|
|
|
if (!*(src+1))
|
|
|
|
{
|
|
|
|
*dst++ = 0;
|
|
|
|
*dst++ = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst++ = *src++;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
}
|
2005-04-25 17:51:45 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
n--;
|
|
|
|
if (!(*dst++ = *src++)) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n--) *dst++ = 0;
|
|
|
|
return ret;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2007-11-15 16:32:33 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcpy_s(MSVCRT.@)
|
|
|
|
* REMARKS
|
|
|
|
* Unlike _mbsnbcpy this function does not pad the rest of the dest
|
|
|
|
* string with 0
|
|
|
|
*/
|
|
|
|
int CDECL _mbsnbcpy_s(unsigned char* dst, MSVCRT_size_t size, const unsigned char* src, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t pos = 0;
|
|
|
|
|
|
|
|
if(!dst || size == 0)
|
|
|
|
return EINVAL;
|
|
|
|
if(!src)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if(!n)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(g_mbcp_is_multibyte)
|
|
|
|
{
|
|
|
|
int is_lead = 0;
|
|
|
|
while (*src && n)
|
|
|
|
{
|
|
|
|
if(pos == size)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
|
|
|
return ERANGE;
|
|
|
|
}
|
|
|
|
is_lead = (!is_lead && _ismbblead(*src));
|
|
|
|
n--;
|
|
|
|
dst[pos++] = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_lead) /* if string ends with a lead, remove it */
|
|
|
|
dst[pos - 1] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
n--;
|
|
|
|
if(pos == size)
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
|
|
|
return ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(*src)) break;
|
|
|
|
dst[pos++] = *src++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pos < size)
|
|
|
|
dst[pos] = '\0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dst[0] = '\0';
|
|
|
|
return ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcpy(MSVCRT.@)
|
2007-08-22 19:47:01 +02:00
|
|
|
* REMARKS
|
|
|
|
* Like strncpy this function doesn't enforce the string to be
|
|
|
|
* NUL-terminated
|
2001-12-05 23:11:35 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2005-04-25 17:51:45 +02:00
|
|
|
unsigned char* ret = dst;
|
2001-12-05 23:11:35 +01:00
|
|
|
if(!n)
|
|
|
|
return dst;
|
2007-08-22 19:47:01 +02:00
|
|
|
if(g_mbcp_is_multibyte)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-22 19:47:01 +02:00
|
|
|
int is_lead = 0;
|
|
|
|
while (*src && n)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2007-08-22 19:47:01 +02:00
|
|
|
is_lead = (!is_lead && _ismbblead(*src));
|
2001-12-05 23:11:35 +01:00
|
|
|
n--;
|
2007-08-22 19:47:01 +02:00
|
|
|
*dst++ = *src++;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2007-08-22 19:47:01 +02:00
|
|
|
|
|
|
|
if (is_lead) /* if string ends with a lead, remove it */
|
|
|
|
*(dst - 1) = 0;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2005-04-25 17:51:45 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
n--;
|
|
|
|
if (!(*dst++ = *src++)) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n--) *dst++ = 0;
|
|
|
|
return ret;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscmp(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbscmp(const unsigned char* str, const unsigned char* cmp)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
do {
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
2001-04-10 23:16:07 +02:00
|
|
|
strc = _mbsnextc(str);
|
|
|
|
cmpc = _mbsnextc(cmp);
|
2001-01-11 00:59:25 +01:00
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
str +=(strc > 255) ? 2 : 1;
|
|
|
|
cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
|
|
|
} while(1);
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strcmp(str, cmp); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2003-01-31 04:20:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsicoll(MSVCRT.@)
|
|
|
|
* FIXME: handle locales.
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsicoll(const unsigned char* str, const unsigned char* cmp)
|
2003-01-31 04:20:25 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
do {
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
|
|
|
strc = _mbctolower(_mbsnextc(str));
|
|
|
|
cmpc = _mbctolower(_mbsnextc(cmp));
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
str +=(strc > 255) ? 2 : 1;
|
|
|
|
cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
|
|
|
} while(1);
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strcasecmp(str, cmp); /* ASCII CP */
|
2003-01-31 04:20:25 +01:00
|
|
|
}
|
|
|
|
|
2005-08-24 20:14:06 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscoll(MSVCRT.@)
|
|
|
|
* Performs a case-sensitive comparison according to the current code page
|
|
|
|
* RETURN
|
|
|
|
* _NLSCMPERROR if error
|
|
|
|
* FIXME: handle locales.
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbscoll(const unsigned char* str, const unsigned char* cmp)
|
2005-08-24 20:14:06 +02:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
do {
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
|
|
|
strc = _mbsnextc(str);
|
|
|
|
cmpc = _mbsnextc(cmp);
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
str +=(strc > 255) ? 2 : 1;
|
|
|
|
cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
|
|
|
} while(1);
|
|
|
|
}
|
|
|
|
return u_strcmp(str, cmp); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
2003-01-31 04:20:25 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsicmp(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsicmp(const unsigned char* str, const unsigned char* cmp)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
do {
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
|
|
|
strc = _mbctolower(_mbsnextc(str));
|
|
|
|
cmpc = _mbctolower(_mbsnextc(cmp));
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
str +=(strc > 255) ? 2 : 1;
|
|
|
|
cmp +=(strc > 255) ? 2 : 1; /* equal, use same increment */
|
|
|
|
} while(1);
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strcasecmp(str, cmp); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbsncmp(MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsncmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(!len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
while(len--)
|
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
int inc;
|
2001-01-11 00:59:25 +01:00
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
2001-04-10 23:16:07 +02:00
|
|
|
strc = _mbsnextc(str);
|
|
|
|
cmpc = _mbsnextc(cmp);
|
2001-01-11 00:59:25 +01:00
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
2001-12-05 23:11:35 +01:00
|
|
|
inc=(strc > 255) ? 2 : 1; /* Equal, use same increment */
|
|
|
|
str += inc;
|
|
|
|
cmp += inc;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return 0; /* Matched len chars */
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncmp(str, cmp, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbsnbcmp(MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsnbcmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!len)
|
|
|
|
return 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
int clen;
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
|
|
|
if (MSVCRT_isleadbyte(*str))
|
|
|
|
{
|
|
|
|
strc=(len>=2)?_mbsnextc(str):0;
|
|
|
|
clen=2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strc=*str;
|
|
|
|
clen=1;
|
|
|
|
}
|
|
|
|
if (MSVCRT_isleadbyte(*cmp))
|
|
|
|
cmpc=(len>=2)?_mbsnextc(cmp):0;
|
|
|
|
else
|
|
|
|
cmpc=*str;
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
len -= clen;
|
|
|
|
str += clen;
|
|
|
|
cmp += clen;
|
|
|
|
}
|
|
|
|
return 0; /* Matched len chars */
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncmp(str,cmp,len);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbsnicmp(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Compare two multibyte strings case insensitively to 'len' characters.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsnicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
/* FIXME: No tolower() for mb strings yet */
|
2001-01-11 00:59:25 +01:00
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned int strc, cmpc;
|
|
|
|
while(len--)
|
|
|
|
{
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
|
|
|
strc = _mbctolower(_mbsnextc(str));
|
|
|
|
cmpc = _mbctolower(_mbsnextc(cmp));
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
str +=(strc > 255) ? 2 : 1;
|
|
|
|
cmp +=(strc > 255) ? 2 : 1; /* Equal, use same increment */
|
|
|
|
}
|
|
|
|
return 0; /* Matched len chars */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncasecmp(str, cmp, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2002-04-02 04:42:58 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbicmp(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _mbsnbicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
2002-04-02 04:42:58 +02:00
|
|
|
{
|
|
|
|
if (!len)
|
|
|
|
return 0;
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int strc, cmpc;
|
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
int clen;
|
|
|
|
if(!*str)
|
|
|
|
return *cmp ? -1 : 0;
|
|
|
|
if(!*cmp)
|
|
|
|
return 1;
|
|
|
|
if (MSVCRT_isleadbyte(*str))
|
|
|
|
{
|
|
|
|
strc=(len>=2)?_mbsnextc(str):0;
|
|
|
|
clen=2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strc=*str;
|
|
|
|
clen=1;
|
|
|
|
}
|
|
|
|
if (MSVCRT_isleadbyte(*cmp))
|
|
|
|
cmpc=(len>=2)?_mbsnextc(cmp):0;
|
|
|
|
else
|
|
|
|
cmpc=*str;
|
|
|
|
strc = _mbctolower(strc);
|
|
|
|
cmpc = _mbctolower(cmpc);
|
|
|
|
if(strc != cmpc)
|
|
|
|
return strc < cmpc ? -1 : 1;
|
|
|
|
len -= clen;
|
|
|
|
str += clen;
|
|
|
|
cmp += clen;
|
|
|
|
}
|
|
|
|
return 0; /* Matched len bytes */
|
|
|
|
}
|
2007-08-04 17:48:02 +02:00
|
|
|
return u_strncasecmp(str,cmp,len);
|
2002-04-02 04:42:58 +02:00
|
|
|
}
|
|
|
|
|
2006-01-14 17:40:29 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscat (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char * CDECL _mbscat( unsigned char *dst, const unsigned char *src )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
strcat( (char *)dst, (const char *)src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbscpy (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbscpy( unsigned char *dst, const unsigned char *src )
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
strcpy( (char *)dst, (const char *)src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsstr (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char * CDECL _mbsstr(const unsigned char *haystack, const unsigned char *needle)
|
2006-01-14 17:40:29 +01:00
|
|
|
{
|
|
|
|
return (unsigned char *)strstr( (const char *)haystack, (const char *)needle );
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbschr(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Find a multibyte character in a multibyte string.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbschr(const unsigned char* s, unsigned int x)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned int c;
|
|
|
|
while (1)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
c = _mbsnextc(s);
|
|
|
|
if (c == x)
|
|
|
|
return (unsigned char*)s;
|
|
|
|
if (!c)
|
|
|
|
return NULL;
|
|
|
|
s += c > 255 ? 2 : 1;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strchr(s, x); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsrchr(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsrchr(const unsigned char* s, unsigned int x)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
unsigned char* match=NULL;
|
|
|
|
if(!s)
|
|
|
|
return NULL;
|
|
|
|
while (1) {
|
|
|
|
c = _mbsnextc(s);
|
|
|
|
if (c == x)
|
|
|
|
match=(unsigned char*)s;
|
|
|
|
if (!c)
|
|
|
|
return match;
|
|
|
|
s +=(c > 255) ? 2 : 1;
|
|
|
|
}
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strrchr(s, x);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2003-02-01 01:45:22 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbstok(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Find and extract tokens from strings
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbstok(unsigned char *str, const unsigned char *delim)
|
2003-02-01 01:45:22 +01:00
|
|
|
{
|
2004-06-25 03:19:15 +02:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2005-08-23 20:49:18 +02:00
|
|
|
unsigned char *ret;
|
2003-02-01 01:45:22 +01:00
|
|
|
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
|
|
|
|
if (!str)
|
2003-02-01 01:59:22 +01:00
|
|
|
if (!(str = data->mbstok_next)) return NULL;
|
2003-02-01 01:45:22 +01:00
|
|
|
|
|
|
|
while ((c = _mbsnextc(str)) && _mbschr(delim, c)) {
|
|
|
|
str += c > 255 ? 2 : 1;
|
|
|
|
}
|
|
|
|
if (!*str) return NULL;
|
|
|
|
ret = str++;
|
|
|
|
while ((c = _mbsnextc(str)) && !_mbschr(delim, c)) {
|
|
|
|
str += c > 255 ? 2 : 1;
|
|
|
|
}
|
|
|
|
if (*str) {
|
|
|
|
*str++ = 0;
|
|
|
|
if (c > 255) *str++ = 0;
|
|
|
|
}
|
2003-02-01 01:59:22 +01:00
|
|
|
data->mbstok_next = str;
|
2003-02-01 01:45:22 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strtok(str, delim); /* ASCII CP */
|
2003-02-01 01:45:22 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* mbtowc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL MSVCRT_mbtowc(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2003-04-17 04:15:03 +02:00
|
|
|
/* temp var needed because MultiByteToWideChar wants non NULL destination */
|
|
|
|
MSVCRT_wchar_t tmpdst = '\0';
|
|
|
|
|
|
|
|
if(n <= 0 || !str)
|
|
|
|
return 0;
|
|
|
|
if(!MultiByteToWideChar(CP_ACP, 0, str, n, &tmpdst, 1))
|
|
|
|
return -1;
|
|
|
|
if(dst)
|
|
|
|
*dst = tmpdst;
|
|
|
|
/* return the number of bytes from src that have been used */
|
|
|
|
if(!*str)
|
|
|
|
return 0;
|
|
|
|
if(n >= 2 && MSVCRT_isleadbyte(*str) && str[1])
|
|
|
|
return 2;
|
|
|
|
return 1;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbbtombc(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL _mbbtombc(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1 &&
|
|
|
|
((c >= 0x20 && c <=0x7e) ||(c >= 0xa1 && c <= 0xdf)))
|
|
|
|
{
|
|
|
|
/* FIXME: I can't get this function to return anything
|
2004-07-24 01:02:09 +02:00
|
|
|
* different from what I pass it...
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
return c; /* ASCII CP or no MB char */
|
|
|
|
}
|
|
|
|
|
2007-02-06 00:34:31 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbbtype(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbbtype(unsigned char c, int type)
|
|
|
|
{
|
|
|
|
if (type == 1)
|
|
|
|
{
|
|
|
|
if ((c >= 0x20 && c <= 0x7e) || (c >= 0xa1 && c <= 0xdf))
|
|
|
|
return _MBC_SINGLE;
|
|
|
|
else if ((c >= 0x40 && c <= 0x7e) || (c >= 0x80 && c <= 0xfc))
|
|
|
|
return _MBC_TRAIL;
|
|
|
|
else
|
|
|
|
return _MBC_ILLEGAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((c >= 0x20 && c <= 0x7e) || (c >= 0xa1 && c <= 0xdf))
|
|
|
|
return _MBC_SINGLE;
|
|
|
|
else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc))
|
|
|
|
return _MBC_LEAD;
|
|
|
|
else
|
|
|
|
return _MBC_ILLEGAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbbkana(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbbkana(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: use lc_ctype when supported, not lc_all */
|
2007-01-16 12:08:59 +01:00
|
|
|
if(MSVCRT___lc_codepage == 932)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Japanese/Katakana, CP 932 */
|
2001-01-12 20:56:22 +01:00
|
|
|
return (c >= 0xa1 && c <= 0xdf);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcdigit(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcdigit(unsigned int ch)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_DIGIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcgraph(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcgraph(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcalpha (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcalpha(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbclower (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbclower(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_UPPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcupper (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcupper(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_LOWER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcsymbol(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcsymbol(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
WORD ctype;
|
|
|
|
if (!GetStringTypeW(CT_CTYPE3, &wch, 1, &ctype))
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2002-11-19 01:52:38 +01:00
|
|
|
WARN("GetStringTypeW failed on %x\n", ch);
|
|
|
|
return 0;
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2002-11-19 01:52:38 +01:00
|
|
|
return ((ctype & C3_SYMBOL) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcalnum (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcalnum(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & (C1_ALPHA | C1_DIGIT));
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcspace (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcspace(unsigned int ch)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_SPACE);
|
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
|
2002-11-19 01:52:38 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcprint (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcprint(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA | C1_SPACE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcpunct(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbcpunct(unsigned int ch)
|
2002-11-19 01:52:38 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t wch = msvcrt_mbc_to_wc( ch );
|
2002-11-19 01:52:38 +01:00
|
|
|
return (get_char_typeW( wch ) & C1_PUNCT);
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _ismbchira(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbchira(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: use lc_ctype when supported, not lc_all */
|
2007-01-16 12:08:59 +01:00
|
|
|
if(MSVCRT___lc_codepage == 932)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Japanese/Hiragana, CP 932 */
|
2001-01-12 20:56:22 +01:00
|
|
|
return (c >= 0x829f && c <= 0x82f1);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbckata(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbckata(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: use lc_ctype when supported, not lc_all */
|
2007-01-16 12:08:59 +01:00
|
|
|
if(MSVCRT___lc_codepage == 932)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(c < 256)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _ismbbkana(c);
|
2001-01-11 00:59:25 +01:00
|
|
|
/* Japanese/Katakana, CP 932 */
|
2001-01-12 20:56:22 +01:00
|
|
|
return (c >= 0x8340 && c <= 0x8396 && c != 0x837f);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbblead(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbblead(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-20 07:30:45 +02:00
|
|
|
return (MSVCRT_mbctype[(c&0xff) + 1] & _M1) != 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbbtrail(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbbtrail(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-20 07:30:45 +02:00
|
|
|
return (MSVCRT_mbctype[(c&0xff) + 1] & _M2) != 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbslead(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbslead(const unsigned char* start, const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-24 02:26:14 +02:00
|
|
|
int lead = 0;
|
|
|
|
|
|
|
|
if(!g_mbcp_is_multibyte)
|
|
|
|
return 0;
|
|
|
|
|
2007-08-29 21:43:57 +02:00
|
|
|
/* Lead bytes can also be trail bytes so we need to analyse the string
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2007-08-24 02:26:14 +02:00
|
|
|
while (start <= str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-24 02:26:14 +02:00
|
|
|
if (!*start)
|
|
|
|
return 0;
|
|
|
|
lead = !lead && _ismbblead(*start);
|
|
|
|
start++;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2007-08-24 02:26:14 +02:00
|
|
|
|
|
|
|
return lead ? -1 : 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbstrail(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _ismbstrail(const unsigned char* start, const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2007-08-24 02:26:14 +02:00
|
|
|
/* Note: this function doesn't check _ismbbtrail */
|
|
|
|
if ((str > start) && _ismbslead(start, str-1))
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2007-08-24 03:11:43 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsbtype (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _mbsbtype(const unsigned char *str, MSVCRT_size_t count)
|
|
|
|
{
|
|
|
|
int lead = 0;
|
|
|
|
const unsigned char *end = str + count;
|
|
|
|
int mbcp = g_mbcp_is_multibyte;
|
|
|
|
|
|
|
|
/* Lead bytes can also be trail bytes so we need to analyse the string.
|
|
|
|
* Also we must return _MBC_ILLEGAL for chars past the end of the string
|
|
|
|
*/
|
|
|
|
while (str < end) /* Note: we skip the last byte - will check after the loop */
|
|
|
|
{
|
|
|
|
if (!*str)
|
|
|
|
return _MBC_ILLEGAL;
|
|
|
|
lead = mbcp && !lead && _ismbblead(*str);
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lead)
|
|
|
|
if (_ismbbtrail(*str))
|
|
|
|
return _MBC_TRAIL;
|
|
|
|
else
|
|
|
|
return _MBC_ILLEGAL;
|
|
|
|
else
|
|
|
|
if (_ismbblead(*str))
|
|
|
|
return _MBC_LEAD;
|
|
|
|
else
|
|
|
|
return _MBC_SINGLE;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsset(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsset(unsigned char* str, unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* ret = str;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
if(MSVCRT___mb_cur_max == 1 || c < 256)
|
2005-08-23 20:49:18 +02:00
|
|
|
return u__strset(str, c); /* ASCII CP or SB char */
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
c &= 0xffff; /* Strip high bits */
|
|
|
|
|
|
|
|
while(str[0] && str[1])
|
|
|
|
{
|
|
|
|
*str++ = c >> 8;
|
|
|
|
*str++ = c & 0xff;
|
|
|
|
}
|
|
|
|
if(str[0])
|
|
|
|
str[0] = '\0'; /* FIXME: OK to shorten? */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-02-01 01:45:22 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbset(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsnbset(unsigned char *str, unsigned int c, MSVCRT_size_t len)
|
2003-02-01 01:45:22 +01:00
|
|
|
{
|
|
|
|
unsigned char *ret = str;
|
|
|
|
|
|
|
|
if(!len)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if(MSVCRT___mb_cur_max == 1 || c < 256)
|
2005-08-23 20:49:18 +02:00
|
|
|
return u__strnset(str, c, len); /* ASCII CP or SB char */
|
2003-02-01 01:45:22 +01:00
|
|
|
|
|
|
|
c &= 0xffff; /* Strip high bits */
|
|
|
|
|
|
|
|
while(str[0] && str[1] && (len > 1))
|
|
|
|
{
|
|
|
|
*str++ = c >> 8;
|
|
|
|
len--;
|
|
|
|
*str++ = c & 0xff;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
if(len && str[0]) {
|
|
|
|
/* as per msdn pad with a blank character */
|
|
|
|
str[0] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnset(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsnset(unsigned char* str, unsigned int c, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char *ret = str;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
if(!len)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if(MSVCRT___mb_cur_max == 1 || c < 256)
|
2005-08-23 20:49:18 +02:00
|
|
|
return u__strnset(str, c, len); /* ASCII CP or SB char */
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
c &= 0xffff; /* Strip high bits */
|
|
|
|
|
|
|
|
while(str[0] && str[1] && len--)
|
|
|
|
{
|
|
|
|
*str++ = c >> 8;
|
|
|
|
*str++ = c & 0xff;
|
|
|
|
}
|
|
|
|
if(len && str[0])
|
|
|
|
str[0] = '\0'; /* FIXME: OK to shorten? */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnccnt(MSVCRT.@)
|
2001-09-07 20:34:45 +02:00
|
|
|
* 'c' is for 'character'.
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL _mbsnccnt(const unsigned char* str, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
MSVCRT_size_t ret;
|
2001-01-11 00:59:25 +01:00
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
ret=0;
|
2001-01-11 00:59:25 +01:00
|
|
|
while(*str && len-- > 0)
|
|
|
|
{
|
|
|
|
if(MSVCRT_isleadbyte(*str))
|
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!len)
|
|
|
|
break;
|
2001-01-11 00:59:25 +01:00
|
|
|
len--;
|
2001-12-05 23:11:35 +01:00
|
|
|
str++;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
str++;
|
2001-12-05 23:11:35 +01:00
|
|
|
ret++;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
ret=u_strlen(str);
|
2001-12-05 23:11:35 +01:00
|
|
|
return min(ret, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2001-09-07 20:34:45 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcnt(MSVCRT.@)
|
|
|
|
* 'b' is for byte count.
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len)
|
2001-09-07 20:34:45 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
MSVCRT_size_t ret;
|
2001-09-07 20:34:45 +02:00
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
const unsigned char* xstr = str;
|
2001-09-07 20:34:45 +02:00
|
|
|
while(*xstr && len-- > 0)
|
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if (MSVCRT_isleadbyte(*xstr++))
|
2001-09-07 20:34:45 +02:00
|
|
|
xstr++;
|
|
|
|
}
|
|
|
|
return xstr-str;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
ret=u_strlen(str);
|
2001-12-05 23:11:35 +01:00
|
|
|
return min(ret, len); /* ASCII CP */
|
2001-09-07 20:34:45 +02:00
|
|
|
}
|
|
|
|
|
2003-02-15 00:26:58 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcat(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsnbcat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
|
2003-02-15 00:26:58 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
2005-08-23 20:49:18 +02:00
|
|
|
unsigned char *res = dst;
|
2003-02-15 00:26:58 +01:00
|
|
|
while (*dst) {
|
|
|
|
if (MSVCRT_isleadbyte(*dst++)) {
|
|
|
|
if (*dst) {
|
|
|
|
dst++;
|
|
|
|
} else {
|
|
|
|
/* as per msdn overwrite the lead byte in front of '\0' */
|
|
|
|
dst--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*src && len--) *dst++ = *src++;
|
|
|
|
*dst = '\0';
|
|
|
|
return res;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncat(dst, src, len); /* ASCII CP */
|
2003-02-15 00:26:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsncat(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsncat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
2005-08-23 20:49:18 +02:00
|
|
|
unsigned char *res = dst;
|
2001-12-05 23:11:35 +01:00
|
|
|
while (*dst)
|
|
|
|
{
|
|
|
|
if (MSVCRT_isleadbyte(*dst++))
|
|
|
|
dst++;
|
|
|
|
}
|
|
|
|
while (*src && len--)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
*dst++ = *src;
|
|
|
|
if(MSVCRT_isleadbyte(*src++))
|
|
|
|
*dst++ = *src++;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
*dst = '\0';
|
2001-01-11 00:59:25 +01:00
|
|
|
return res;
|
|
|
|
}
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strncat(dst, src, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2001-07-11 22:13:14 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbslwr(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbslwr(unsigned char* s)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2006-01-24 12:24:05 +01:00
|
|
|
unsigned char *ret = s;
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
|
|
|
if (MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
while (*s)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
c = _mbctolower(_mbsnextc(s));
|
|
|
|
/* Note that I assume that the size of the character is unchanged */
|
|
|
|
if (c > 255)
|
|
|
|
{
|
|
|
|
*s++=(c>>8);
|
|
|
|
c=c & 0xff;
|
|
|
|
}
|
|
|
|
*s++=c;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2006-01-24 12:24:05 +01:00
|
|
|
else for ( ; *s; s++) *s = tolower(*s);
|
|
|
|
return ret;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-17 21:02:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsupr(MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsupr(unsigned char* s)
|
2001-09-17 21:02:21 +02:00
|
|
|
{
|
2006-01-24 12:24:05 +01:00
|
|
|
unsigned char *ret = s;
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
|
|
|
if (MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
while (*s)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
c = _mbctoupper(_mbsnextc(s));
|
|
|
|
/* Note that I assume that the size of the character is unchanged */
|
|
|
|
if (c > 255)
|
|
|
|
{
|
|
|
|
*s++=(c>>8);
|
|
|
|
c=c & 0xff;
|
|
|
|
}
|
|
|
|
*s++=c;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
2006-01-24 12:24:05 +01:00
|
|
|
else for ( ; *s; s++) *s = toupper(*s);
|
|
|
|
return ret;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsspn (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL _mbsspn(const unsigned char* string, const unsigned char* set)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2005-11-21 13:03:18 +01:00
|
|
|
const unsigned char *p, *q;
|
2001-07-11 22:13:14 +02:00
|
|
|
|
2005-11-21 13:03:18 +01:00
|
|
|
for (p = string; *p; p++)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2005-11-21 13:03:18 +01:00
|
|
|
if (MSVCRT_isleadbyte(*p))
|
|
|
|
{
|
|
|
|
for (q = set; *q; q++)
|
|
|
|
{
|
|
|
|
if (!q[1])
|
|
|
|
break;
|
|
|
|
if ((*p == *q) && (p[1] == q[1]))
|
|
|
|
break;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
if (!q[0] || !q[1]) break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (q = set; *q; q++)
|
|
|
|
if (*p == *q)
|
|
|
|
break;
|
|
|
|
if (!*q) break;
|
|
|
|
}
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2005-11-21 13:03:18 +01:00
|
|
|
return p - string;
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
2006-12-23 00:24:30 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsspnp (MSVCRT.@)
|
|
|
|
*/
|
2007-08-23 04:14:30 +02:00
|
|
|
unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned char* set)
|
2006-12-23 00:24:30 +01:00
|
|
|
{
|
|
|
|
const unsigned char *p, *q;
|
|
|
|
|
|
|
|
for (p = string; *p; p++)
|
|
|
|
{
|
|
|
|
if (MSVCRT_isleadbyte(*p))
|
|
|
|
{
|
|
|
|
for (q = set; *q; q++)
|
|
|
|
{
|
|
|
|
if (!q[1])
|
|
|
|
break;
|
|
|
|
if ((*p == *q) && (p[1] == q[1]))
|
|
|
|
break;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
if (!q[0] || !q[1]) break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (q = set; *q; q++)
|
|
|
|
if (*p == *q)
|
|
|
|
break;
|
|
|
|
if (!*q) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*p == '\0')
|
|
|
|
return NULL;
|
2007-08-23 04:14:30 +02:00
|
|
|
return (unsigned char *)p;
|
2006-12-23 00:24:30 +01:00
|
|
|
}
|
|
|
|
|
2001-07-11 22:13:14 +02:00
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbscspn(MSVCRT.@)
|
2001-07-11 22:13:14 +02:00
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
MSVCRT_size_t CDECL _mbscspn(const unsigned char* str, const unsigned char* cmp)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if (MSVCRT___mb_cur_max > 1)
|
|
|
|
FIXME("don't handle double character case\n");
|
2005-08-23 20:49:18 +02:00
|
|
|
return u_strcspn(str, cmp);
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2001-08-09 23:37:19 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsrev (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbsrev(unsigned char* str)
|
2001-08-09 23:37:19 +02:00
|
|
|
{
|
|
|
|
int i, len = _mbslen(str);
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char *p, *temp=MSVCRT_malloc(len*2);
|
2001-08-09 23:37:19 +02:00
|
|
|
|
|
|
|
if(!temp)
|
|
|
|
return str;
|
|
|
|
|
|
|
|
/* unpack multibyte string to temp buffer */
|
|
|
|
p=str;
|
|
|
|
for(i=0; i<len; i++)
|
|
|
|
{
|
|
|
|
if (MSVCRT_isleadbyte(*p))
|
|
|
|
{
|
|
|
|
temp[i*2]=*p++;
|
|
|
|
temp[i*2+1]=*p++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp[i*2]=*p++;
|
|
|
|
temp[i*2+1]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* repack it in the reverse order */
|
|
|
|
p=str;
|
|
|
|
for(i=len-1; i>=0; i--)
|
|
|
|
{
|
|
|
|
if(MSVCRT_isleadbyte(temp[i*2]))
|
|
|
|
{
|
|
|
|
*p++=temp[i*2];
|
|
|
|
*p++=temp[i*2+1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*p++=temp[i*2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MSVCRT_free(temp);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2001-08-11 00:24:54 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbspbrk (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned char* CDECL _mbspbrk(const unsigned char* str, const unsigned char* accept)
|
2001-08-11 00:24:54 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
const unsigned char* p;
|
2001-08-11 00:24:54 +02:00
|
|
|
|
|
|
|
while(*str)
|
|
|
|
{
|
|
|
|
for(p = accept; *p; p += (MSVCRT_isleadbyte(*p)?2:1) )
|
|
|
|
{
|
|
|
|
if (*p == *str)
|
|
|
|
if( !MSVCRT_isleadbyte(*p) || ( *(p+1) == *(str+1) ) )
|
2001-12-05 23:11:35 +01:00
|
|
|
return (unsigned char*)str;
|
2001-08-11 00:24:54 +02:00
|
|
|
}
|
|
|
|
str += (MSVCRT_isleadbyte(*str)?2:1);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-20 07:59:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions depending on locale codepage
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* mblen(MSVCRT.@)
|
|
|
|
* REMARKS
|
|
|
|
* Unlike most of the multibyte string functions this function uses
|
|
|
|
* the locale codepage, not the codepage set by _setmbcp
|
|
|
|
*/
|
|
|
|
int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size)
|
|
|
|
{
|
|
|
|
if (str && *str && size)
|
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max == 1)
|
|
|
|
return 1; /* ASCII CP */
|
|
|
|
|
|
|
|
return !MSVCRT_isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbstrlen(MSVCRT.@)
|
|
|
|
* REMARKS
|
|
|
|
* Unlike most of the multibyte string functions this function uses
|
|
|
|
* the locale codepage, not the codepage set by _setmbcp
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t CDECL _mbstrlen(const char* str)
|
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t len = 0;
|
|
|
|
while(*str)
|
|
|
|
{
|
|
|
|
/* FIXME: According to the documentation we are supposed to test for
|
|
|
|
* multi-byte character validity. Whatever that means
|
|
|
|
*/
|
|
|
|
str += MSVCRT_isleadbyte(*str) ? 2 : 1;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
return strlen(str); /* ASCII CP */
|
|
|
|
}
|