msvcrt: Test and fix _mbsinc/_mbsninc.
This commit is contained in:
parent
cf8cf1d7f9
commit
9a2d605dd9
|
@ -27,6 +27,7 @@
|
|||
#include "wine/unicode.h"
|
||||
#include "wine/debug.h"
|
||||
#include "msvcrt/mbctype.h"
|
||||
#include "msvcrt/mbstring.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
||||
|
||||
|
@ -335,10 +336,7 @@ unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cu
|
|||
*/
|
||||
unsigned char* CDECL _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 */
|
||||
return (unsigned char *)(str + _mbclen(str));
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
@ -346,15 +344,22 @@ unsigned char* CDECL _mbsinc(const unsigned char* str)
|
|||
*/
|
||||
unsigned char* CDECL _mbsninc(const unsigned char* str, MSVCRT_size_t num)
|
||||
{
|
||||
if(!str || num < 1)
|
||||
if(!str)
|
||||
return NULL;
|
||||
if(MSVCRT___mb_cur_max > 1)
|
||||
|
||||
while (num > 0 && *str)
|
||||
{
|
||||
while(num--)
|
||||
str = _mbsinc(str);
|
||||
return (unsigned char*)str;
|
||||
if (_ismbblead(*str))
|
||||
{
|
||||
if (!*(str+1))
|
||||
break;
|
||||
str++;
|
||||
}
|
||||
return (unsigned char*)str + num; /* ASCII CP */
|
||||
str++;
|
||||
num--;
|
||||
}
|
||||
|
||||
return (unsigned char*)str;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
@ -1348,7 +1353,7 @@ MSVCRT_size_t CDECL _mbsspn(const unsigned char* string, const unsigned char* se
|
|||
/*********************************************************************
|
||||
* _mbsspnp (MSVCRT.@)
|
||||
*/
|
||||
const unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned char* set)
|
||||
unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned char* set)
|
||||
{
|
||||
const unsigned char *p, *q;
|
||||
|
||||
|
@ -1376,7 +1381,7 @@ const unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned
|
|||
}
|
||||
if (*p == '\0')
|
||||
return NULL;
|
||||
return p;
|
||||
return (unsigned char *)p;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
|
|
@ -185,6 +185,7 @@ static void test_mbcp(void)
|
|||
unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
|
||||
unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2";
|
||||
unsigned char buf[16];
|
||||
int step;
|
||||
|
||||
/* some two single-byte code pages*/
|
||||
test_codepage(1252);
|
||||
|
@ -252,6 +253,31 @@ static void test_mbcp(void)
|
|||
_mbsnbcpy(buf, mbsonlylead, 5);
|
||||
expect_bin(buf, "\0\0\0\0\0\xff", 6);
|
||||
|
||||
/* _mbsinc/mbsdec */
|
||||
step = _mbsinc(mbstring) - mbstring;
|
||||
ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
|
||||
step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */
|
||||
ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step);
|
||||
|
||||
step = _mbsninc(mbsonlylead, 1) - mbsonlylead;
|
||||
ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
|
||||
step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */
|
||||
ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step);
|
||||
step = _mbsninc(mbstring2, 0) - mbstring2;
|
||||
ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step);
|
||||
step = _mbsninc(mbstring2, 1) - mbstring2;
|
||||
ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step);
|
||||
step = _mbsninc(mbstring2, 2) - mbstring2;
|
||||
ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step);
|
||||
step = _mbsninc(mbstring2, 3) - mbstring2;
|
||||
ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step);
|
||||
step = _mbsninc(mbstring2, 4) - mbstring2;
|
||||
ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
|
||||
step = _mbsninc(mbstring2, 5) - mbstring2;
|
||||
ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
|
||||
step = _mbsninc(mbstring2, 17) - mbstring2;
|
||||
ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step);
|
||||
|
||||
/* functions that depend on locale codepage, not mbcp.
|
||||
* we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet
|
||||
* (as of Wine 0.9.43)
|
||||
|
|
Loading…
Reference in New Issue