Fix _mbsspn() with conformance tests.

This commit is contained in:
Rein Klazes 2005-11-21 12:03:18 +00:00 committed by Alexandre Julliard
parent 1833cfba75
commit 6f92870a80
2 changed files with 40 additions and 20 deletions

View file

@ -1154,29 +1154,31 @@ unsigned char* _mbsupr(unsigned char* s)
*/
MSVCRT_size_t _mbsspn(const unsigned char* string, const unsigned char* set)
{
const unsigned char *p, *q;
const unsigned char *p, *q;
for (p = string; *p; p++)
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;
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;
}
}
return p - string;
return p - string;
}
/*********************************************************************

View file

@ -21,6 +21,7 @@
#include "wine/test.h"
#include "winbase.h"
#include <string.h>
#include <mbstring.h>
#include <stdlib.h>
#include <mbctype.h>
@ -83,6 +84,21 @@ void test_ismbblead()
_setmbcp(1252);
}
static void test_mbsspn( void)
{
unsigned char str1[]="cabernet";
unsigned char str2[]="shiraz";
unsigned char set[]="abc";
unsigned char empty[]="";
int ret;
ret=_mbsspn( str1, set);
ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
ret=_mbsspn( str2, set);
ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
ret=_mbsspn( str1, empty);
ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
}
START_TEST(string)
{
void *mem;
@ -107,4 +123,6 @@ START_TEST(string)
/* Test ismbblead*/
test_ismbblead();
/* test _mbsspn */
test_mbsspn();
}