Commit 6f92870a authored by Rein Klazes's avatar Rein Klazes Committed by Alexandre Julliard

Fix _mbsspn() with conformance tests.

parent 1833cfba
...@@ -1154,29 +1154,31 @@ unsigned char* _mbsupr(unsigned char* s) ...@@ -1154,29 +1154,31 @@ unsigned char* _mbsupr(unsigned char* s)
*/ */
MSVCRT_size_t _mbsspn(const unsigned char* string, const unsigned char* set) 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)) if (MSVCRT_isleadbyte(*p))
{ {
for (q = set; *q; q++) for (q = set; *q; q++)
{ {
if (!q[1]) if (!q[1])
break; break;
if ((*p == *q) && (p[1] == q[1])) if ((*p == *q) && (p[1] == q[1]))
break; break;
q++; q++;
} }
if (*++p == '\0') if (!q[0] || !q[1]) break;
break; }
} else
else {
for (q = set; *q; q++) for (q = set; *q; q++)
if (*p == *q) if (*p == *q)
break; break;
if (!*q) break;
}
} }
return p - string; return p - string;
} }
/********************************************************************* /*********************************************************************
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "wine/test.h" #include "wine/test.h"
#include "winbase.h" #include "winbase.h"
#include <string.h> #include <string.h>
#include <mbstring.h>
#include <stdlib.h> #include <stdlib.h>
#include <mbctype.h> #include <mbctype.h>
...@@ -83,6 +84,21 @@ void test_ismbblead() ...@@ -83,6 +84,21 @@ void test_ismbblead()
_setmbcp(1252); _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) START_TEST(string)
{ {
void *mem; void *mem;
...@@ -107,4 +123,6 @@ START_TEST(string) ...@@ -107,4 +123,6 @@ START_TEST(string)
/* Test ismbblead*/ /* Test ismbblead*/
test_ismbblead(); test_ismbblead();
/* test _mbsspn */
test_mbsspn();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment