msvcrt: Add _mbsbtype_l implementation.

This commit is contained in:
Bartosz Kosiorek 2023-11-02 18:35:20 +01:00 committed by Alexandre Julliard
parent 4e2d8b1328
commit c59a856cc0
9 changed files with 54 additions and 32 deletions

View file

@ -1096,7 +1096,7 @@
@ extern _mbctype MSVCRT_mbctype
@ stub _mblen_l
@ cdecl _mbsbtype(str long)
@ stub _mbsbtype_l
@ cdecl _mbsbtype_l(str long ptr)
@ cdecl _mbscat_s(ptr long str)
@ cdecl _mbscat_s_l(ptr long str ptr)
@ cdecl _mbschr(str long)

View file

@ -1453,7 +1453,7 @@
@ extern _mbctype MSVCRT_mbctype
@ stub _mblen_l
@ cdecl _mbsbtype(str long)
@ stub _mbsbtype_l
@ cdecl _mbsbtype_l(str long ptr)
@ cdecl _mbscat_s(ptr long str)
@ cdecl _mbscat_s_l(ptr long str ptr)
@ cdecl _mbschr(str long)

View file

@ -1464,7 +1464,7 @@
@ extern _mbctype MSVCRT_mbctype
@ stub _mblen_l
@ cdecl _mbsbtype(str long)
@ stub _mbsbtype_l
@ cdecl _mbsbtype_l(str long ptr)
@ cdecl _mbscat_s(ptr long str)
@ cdecl _mbscat_s_l(ptr long str ptr)
@ cdecl _mbschr(str long)

View file

@ -768,7 +768,7 @@
@ extern _mbctype MSVCRT_mbctype
@ stub _mblen_l
@ cdecl _mbsbtype(str long)
@ stub _mbsbtype_l
@ cdecl _mbsbtype_l(str long ptr)
@ cdecl _mbscat_s(ptr long str)
@ cdecl _mbscat_s_l(ptr long str ptr)
@ cdecl _mbschr(str long)

View file

@ -746,7 +746,7 @@
@ extern _mbctype MSVCRT_mbctype
@ stub _mblen_l
@ cdecl _mbsbtype(str long)
@ stub _mbsbtype_l
@ cdecl _mbsbtype_l(str long ptr)
@ cdecl _mbscat_s(ptr long str)
@ cdecl _mbscat_s_l(ptr long str ptr)
@ cdecl _mbschr(str long)

View file

@ -2027,35 +2027,56 @@ int CDECL _mbbtype(unsigned char c, int type)
return _mbbtype_l(c, type, NULL);
}
/*********************************************************************
* _mbsbtype_l (MSVCRT.@)
*/
int CDECL _mbsbtype_l(const unsigned char *str, size_t count, _locale_t locale)
{
int lead = 0;
pthreadmbcinfo mbcinfo;
const unsigned char *end = str + count;
if (!MSVCRT_CHECK_PMT(str))
return _MBC_ILLEGAL;
if (locale)
mbcinfo = locale->mbcinfo;
else
mbcinfo = get_mbcinfo();
/* Lead bytes can also be trail bytes so we need to analyse the string.
* Also we must return _MBC_ILLEGAL for chars past the end of the string
*/
while (str < end) /* Note: we skip the last byte - will check after the loop */
{
if (!*str)
return _MBC_ILLEGAL;
lead = mbcinfo->ismbcodepage && !lead && _ismbblead_l(*str, locale);
str++;
}
if (lead)
{
if (_ismbbtrail_l(*str, locale))
return _MBC_TRAIL;
else
return _MBC_ILLEGAL;
}
else
{
if (_ismbblead_l(*str, locale))
return _MBC_LEAD;
else
return _MBC_SINGLE;
}
}
/*********************************************************************
* _mbsbtype (MSVCRT.@)
*/
int CDECL _mbsbtype(const unsigned char *str, size_t count)
{
int lead = 0;
const unsigned char *end = str + count;
/* Lead bytes can also be trail bytes so we need to analyse the string.
* Also we must return _MBC_ILLEGAL for chars past the end of the string
*/
while (str < end) /* Note: we skip the last byte - will check after the loop */
{
if (!*str)
return _MBC_ILLEGAL;
lead = get_mbcinfo()->ismbcodepage && !lead && _ismbblead(*str);
str++;
}
if (lead)
if (_ismbbtrail(*str))
return _MBC_TRAIL;
else
return _MBC_ILLEGAL;
else
if (_ismbblead(*str))
return _MBC_LEAD;
else
return _MBC_SINGLE;
return _mbsbtype_l(str, count, NULL);
}
/*********************************************************************

View file

@ -713,7 +713,7 @@
@ extern _mbctype MSVCRT_mbctype
# stub _mblen_l(str long ptr)
@ cdecl _mbsbtype(str long)
# stub _mbsbtype_l(str long ptr)
@ cdecl _mbsbtype_l(str long ptr)
@ cdecl _mbscat(str str)
@ cdecl _mbscat_s(ptr long str)
@ cdecl _mbscat_s_l(ptr long str ptr)

View file

@ -335,6 +335,7 @@ static void test_mbcp(void)
expect_eq(_ismbstrail(mbsonlylead, &mbsonlylead[5]), FALSE, int, "%d");
/* _mbsbtype */
expect_eq(_mbsbtype(NULL, 0), _MBC_ILLEGAL, int, "%d");
expect_eq(_mbsbtype(mbstring, 0), _MBC_LEAD, int, "%d");
expect_eq(_mbsbtype(mbstring, 1), _MBC_TRAIL, int, "%d");
expect_eq(_mbsbtype(mbstring, 2), _MBC_LEAD, int, "%d");

View file

@ -611,7 +611,7 @@
@ cdecl _mbctoupper_l(long ptr)
@ stub _mblen_l
@ cdecl _mbsbtype(str long)
@ stub _mbsbtype_l
@ cdecl _mbsbtype_l(str long ptr)
@ cdecl _mbscat_s(ptr long str)
@ cdecl _mbscat_s_l(ptr long str ptr)
@ cdecl _mbschr(str long)
@ -1181,7 +1181,7 @@
@ cdecl _o__mbctoupper_l(long ptr) _mbctoupper_l
@ stub _o__mblen_l
@ cdecl _o__mbsbtype(str long) _mbsbtype
@ stub _o__mbsbtype_l
@ cdecl _o__mbsbtype_l(str long ptr) _mbsbtype_l
@ cdecl _o__mbscat_s(ptr long str) _mbscat_s
@ cdecl _o__mbscat_s_l(ptr long str ptr) _mbscat_s_l
@ cdecl _o__mbschr(str long) _mbschr