Mikolaj Zalewski : msvcrt: Test and fix _mbclen/_mbslen.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Aug 21 07:20:59 CDT 2007
Module: wine
Branch: master
Commit: cea1052f626b6d6f1f57c62429a198c6edc8a06b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=cea1052f626b6d6f1f57c62429a198c6edc8a06b
Author: Mikolaj Zalewski <mikolajz at google.com>
Date: Sun Aug 19 22:46:56 2007 -0700
msvcrt: Test and fix _mbclen/_mbslen.
---
dlls/msvcrt/mbcs.c | 18 ++++++++++--------
dlls/msvcrt/tests/string.c | 11 ++++++++++-
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index 5882630..024c9b5 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -356,7 +356,7 @@ unsigned char* CDECL _mbsninc(const unsigned char* str, MSVCRT_size_t num)
*/
unsigned int CDECL _mbclen(const unsigned char* str)
{
- return MSVCRT_isleadbyte(*str) ? 2 : 1;
+ return _ismbblead(*str) ? 2 : 1;
}
/*********************************************************************
@@ -379,17 +379,19 @@ int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size)
*/
MSVCRT_size_t CDECL _mbslen(const unsigned char* str)
{
- if(MSVCRT___mb_cur_max > 1)
+ MSVCRT_size_t len = 0;
+ while(*str)
{
- MSVCRT_size_t len = 0;
- while(*str)
+ if (_ismbblead(*str))
{
- str += MSVCRT_isleadbyte(*str) ? 2 : 1;
- len++;
+ str++;
+ if (!*str) /* count only full chars */
+ break;
}
- return len;
+ str++;
+ len++;
}
- return u_strlen(str); /* ASCII CP */
+ return len;
}
/*********************************************************************
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index 8b55cf3..209f1fa 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -166,6 +166,8 @@ static void test_mbcp(void)
int mb_orig_max = __mb_cur_max;
int curr_mbcp = _getmbcp();
unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */
+ unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */
+ unsigned char *mbsonlylead = (unsigned char *)"\xb0";
/* some two single-byte code pages*/
test_codepage(1252);
@@ -186,12 +188,19 @@ static void test_mbcp(void)
ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
-
/* _mbsnextc */
expect_eq(_mbsnextc(mbstring), 0xb0b1, int, "%x");
expect_eq(_mbsnextc(&mbstring[2]), 0xb220, int, "%x"); /* lead + invalid tail */
expect_eq(_mbsnextc(&mbstring[3]), 0x20, int, "%x"); /* single char */
+ /* _mbclen/_mbslen */
+ expect_eq(_mbclen(mbstring), 2, int, "%d");
+ expect_eq(_mbclen(&mbstring[2]), 2, int, "%d");
+ expect_eq(_mbclen(&mbstring[3]), 1, int, "%d");
+ expect_eq(_mbslen(mbstring2), 4, int, "%d");
+ expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */
+ expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */
+
_setmbcp(curr_mbcp);
}
More information about the wine-cvs
mailing list