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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
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"
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
#include "msvcrt/mbctype.h"
|
|
|
|
#include "msvcrt/mbstring.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "msvcrt/stdlib.h"
|
2001-04-11 01:25:25 +02:00
|
|
|
#include "msvcrt/string.h"
|
2001-07-24 01:50:18 +02:00
|
|
|
#include "msvcrt/wctype.h"
|
2001-04-11 01:25:25 +02:00
|
|
|
|
2002-11-19 01:52:38 +01:00
|
|
|
#include "wine/unicode.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
unsigned char MSVCRT_mbctype[257];
|
|
|
|
int MSVCRT___mb_cur_max = 1;
|
|
|
|
|
2002-11-19 01:52:38 +01:00
|
|
|
static WCHAR msvcrt_mbc_to_wc(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR chW;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (!MultiByteToWideChar(MSVCRT_current_lc_all_cp, 0, mbch, n_chars, &chW, 1))
|
|
|
|
{
|
|
|
|
WARN("MultiByteToWideChar failed on %x\n", ch);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return chW;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __p__mbctype (MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* __p__mbctype(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return MSVCRT_mbctype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p___mb_cur_max(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int* __p___mb_cur_max(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return &MSVCRT___mb_cur_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnextc(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned int _mbsnextc(const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*str))
|
|
|
|
return *str << 8 | str[1];
|
|
|
|
return *str; /* ASCII CP or SB char */
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:11:35 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbctolower(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned int _mbctolower(unsigned int c)
|
|
|
|
{
|
|
|
|
if (MSVCRT_isleadbyte(c))
|
|
|
|
{
|
|
|
|
FIXME("Handle MBC chars\n");
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return tolower(c); /* ASCII CP or SB char */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbctoupper(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned int _mbctoupper(unsigned int c)
|
|
|
|
{
|
|
|
|
if (MSVCRT_isleadbyte(c))
|
|
|
|
{
|
|
|
|
FIXME("Handle MBC chars\n");
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return toupper(c); /* ASCII CP or SB char */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsdec(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned char* _mbsdec(const unsigned char* start, const unsigned char* cur)
|
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
return (char *)(_ismbstrail(start,cur-1) ? cur - 2 : cur -1);
|
|
|
|
|
|
|
|
return (char *)cur - 1; /* ASCII CP or SB char */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsinc(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned char* _mbsinc(const unsigned char* str)
|
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*str))
|
|
|
|
return (unsigned char*)str + 2; /* MB char */
|
|
|
|
|
|
|
|
return (unsigned char*)str + 1; /* ASCII CP or SB char */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsninc(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned char* _mbsninc(const unsigned char* str, MSVCRT_size_t num)
|
|
|
|
{
|
|
|
|
if(!str || num < 1)
|
|
|
|
return NULL;
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
while(num--)
|
|
|
|
str = _mbsinc(str);
|
|
|
|
return (unsigned char*)str;
|
|
|
|
}
|
|
|
|
return (unsigned char*)str + num; /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbclen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned int _mbclen(const unsigned char* str)
|
|
|
|
{
|
|
|
|
return MSVCRT_isleadbyte(*str) ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* mblen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbslen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t _mbslen(const unsigned char* str)
|
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t len = 0;
|
|
|
|
while(*str)
|
|
|
|
{
|
|
|
|
str += MSVCRT_isleadbyte(*str) ? 2 : 1;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
return strlen(str); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbstrlen(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_size_t _mbstrlen(const char* str)
|
|
|
|
{
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
MSVCRT_size_t len = 0;
|
|
|
|
while(*str)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/* FIXME: According to the documentation we are supposed to test for
|
2001-12-05 23:11:35 +01:00
|
|
|
* multi-byte character validity. Whatever that means
|
|
|
|
*/
|
|
|
|
str += MSVCRT_isleadbyte(*str) ? 2 : 1;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
return strlen(str); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbccpy(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void _mbccpy(unsigned char* dest, const unsigned char* src)
|
|
|
|
{
|
|
|
|
*dest++ = *src;
|
|
|
|
if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*src))
|
|
|
|
*dest = *++src; /* MB char */
|
|
|
|
else
|
|
|
|
ERR("failure.. is this ok?\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsncpy(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned char* _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
if(!n)
|
|
|
|
return dst;
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned char* ret = dst;
|
|
|
|
while (*src && n--)
|
|
|
|
{
|
|
|
|
*dst++ = *src;
|
|
|
|
if (MSVCRT_isleadbyte(*src++))
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
while(n--)
|
|
|
|
*dst++ = '\0';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return strncpy(dst, src, n); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbcpy(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned char* _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n)
|
|
|
|
{
|
|
|
|
if(!n)
|
|
|
|
return dst;
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned char* ret = dst;
|
|
|
|
while (*src && (n-- > 1))
|
|
|
|
{
|
|
|
|
*dst++ = *src;
|
|
|
|
if (MSVCRT_isleadbyte(*src++))
|
|
|
|
{
|
|
|
|
*dst++ = *src++;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*src && n && !MSVCRT_isleadbyte(*src))
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/* If the last character is a multi-byte character then
|
2001-12-05 23:11:35 +01:00
|
|
|
* we cannot copy it since we have only one byte left
|
|
|
|
*/
|
|
|
|
*dst++ = *src;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
while (n--)
|
|
|
|
*dst++ = '\0';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return strncpy(dst, src, n); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbscmp(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int _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);
|
|
|
|
}
|
|
|
|
return strcmp(str, cmp); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsicmp(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int _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);
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
return strcasecmp(str, cmp); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbsncmp(MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int _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 */
|
|
|
|
}
|
|
|
|
return strncmp(str, cmp, len); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbsnbcmp(MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int _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 */
|
|
|
|
FIXME("%s %s %d\n",str,cmp,len);
|
|
|
|
}
|
|
|
|
return 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
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int _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
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
return strncasecmp(str, cmp, len); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2002-04-02 04:42:58 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnbicmp(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int _mbsnbicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
FIXME("%s %s %d\n",str,cmp,len);
|
|
|
|
}
|
|
|
|
return strncmp(str,cmp,len);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* _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
|
|
|
}
|
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
return strchr(s, x); /* ASCII CP */
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsrchr(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* _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;
|
|
|
|
}
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
return strrchr(s,x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* mbtowc(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int MSVCRT_mbtowc(WCHAR *dst, const char* str, MSVCRT_size_t n)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if(n <= 0 || !str)
|
|
|
|
return 0;
|
|
|
|
if(!MultiByteToWideChar(CP_ACP, 0, str, n, dst, 1))
|
|
|
|
return 0;
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbbtombc(MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
unsigned int _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
|
|
|
|
* different to what I pass it...
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
return c; /* ASCII CP or no MB char */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbbkana(MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _ismbbkana(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: use lc_ctype when supported, not lc_all */
|
|
|
|
if(MSVCRT_current_lc_all_cp == 932)
|
|
|
|
{
|
|
|
|
/* 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.@)
|
|
|
|
*/
|
|
|
|
int _ismbcdigit(unsigned int ch)
|
|
|
|
{
|
2002-11-19 01:52:38 +01:00
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
return (get_char_typeW( wch ) & C1_DIGIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcgraph(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int _ismbcgraph(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcalpha (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int _ismbcalpha(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
return (get_char_typeW( wch ) & C1_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbclower (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int _ismbclower(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
return (get_char_typeW( wch ) & C1_UPPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcupper (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int _ismbcupper(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
return (get_char_typeW( wch ) & C1_LOWER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcsymbol(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int _ismbcsymbol(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
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.@)
|
|
|
|
*/
|
|
|
|
int _ismbcalnum(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
return (get_char_typeW( wch ) & (C1_ALPHA | C1_DIGIT));
|
2001-12-05 23:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcspace (MSVCRT.@)
|
|
|
|
*/
|
2002-11-19 01:52:38 +01:00
|
|
|
int _ismbcspace(unsigned int ch)
|
2001-12-05 23:11:35 +01:00
|
|
|
{
|
2002-11-19 01:52:38 +01:00
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
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.@)
|
|
|
|
*/
|
|
|
|
int _ismbcprint(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA | C1_SPACE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbcpunct(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int _ismbcpunct(unsigned int ch)
|
|
|
|
{
|
|
|
|
WCHAR wch = msvcrt_mbc_to_wc( ch );
|
|
|
|
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.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _ismbchira(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: use lc_ctype when supported, not lc_all */
|
|
|
|
if(MSVCRT_current_lc_all_cp == 932)
|
|
|
|
{
|
|
|
|
/* 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.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _ismbckata(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: use lc_ctype when supported, not lc_all */
|
|
|
|
if(MSVCRT_current_lc_all_cp == 932)
|
|
|
|
{
|
|
|
|
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.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _ismbblead(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: should reference MSVCRT_mbctype */
|
|
|
|
return MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbbtrail(MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _ismbbtrail(unsigned int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* FIXME: should reference MSVCRT_mbctype */
|
2001-04-10 23:16:07 +02:00
|
|
|
return !_ismbblead(c);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbslead(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int _ismbslead(const unsigned char* start, const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Lead bytes can also be trail bytes if caller messed up
|
|
|
|
* iterating through the string...
|
|
|
|
*/
|
|
|
|
if(MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
while(start < str)
|
|
|
|
start += MSVCRT_isleadbyte(*str) ? 2 : 1;
|
|
|
|
|
|
|
|
if(start == str)
|
|
|
|
return MSVCRT_isleadbyte(*str);
|
|
|
|
}
|
|
|
|
return 0; /* Must have been a trail, we skipped it */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ismbstrail(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
int _ismbstrail(const unsigned char* start, const unsigned char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Must not be a lead, and must be preceeded by one */
|
2001-04-10 23:16:07 +02:00
|
|
|
return !_ismbslead(start, str) && MSVCRT_isleadbyte(str[-1]);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsset(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* _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)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsnset(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* _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)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _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
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
MSVCRT_size_t _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;
|
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
ret=strlen(str);
|
|
|
|
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.
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
MSVCRT_size_t _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;
|
|
|
|
}
|
2001-12-05 23:11:35 +01:00
|
|
|
ret=strlen(str);
|
|
|
|
return min(ret, len); /* ASCII CP */
|
2001-09-07 20:34:45 +02:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsncat(MSVCRT.@)
|
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
unsigned char* _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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return strncat(dst, src, len); /* ASCII CP */
|
|
|
|
}
|
|
|
|
|
2001-07-11 22:13:14 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbslwr(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* _mbslwr(unsigned char* s)
|
2001-07-11 22:13:14 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
|
|
|
if (MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
unsigned char* p=s;
|
|
|
|
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
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return _strlwr(s);
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-17 21:02:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _mbsupr(MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* _mbsupr(unsigned char* s)
|
2001-09-17 21:02:21 +02:00
|
|
|
{
|
2001-12-05 23:11:35 +01:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
|
|
|
if (MSVCRT___mb_cur_max > 1)
|
|
|
|
{
|
|
|
|
unsigned int c;
|
|
|
|
unsigned char* p=s;
|
|
|
|
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
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return _strupr(s);
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsspn (MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
MSVCRT_size_t _mbsspn(const unsigned char* string, const unsigned char* set)
|
2001-07-11 22:13:14 +02: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 (*++p == '\0')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (q = set; *q; q++)
|
|
|
|
if (*p == *q)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return p - string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-12-05 23:11:35 +01:00
|
|
|
* _mbscspn(MSVCRT.@)
|
2001-07-11 22:13:14 +02:00
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
MSVCRT_size_t _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");
|
|
|
|
return strcspn(str, cmp);
|
2001-07-11 22:13:14 +02:00
|
|
|
}
|
2001-08-09 23:37:19 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mbsrev (MSVCRT.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* _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.@)
|
|
|
|
*/
|
2001-12-05 23:11:35 +01:00
|
|
|
unsigned char* _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;
|
|
|
|
}
|