mirror of
https://github.com/reactos/reactos.git
synced 2025-07-24 01:14:00 +00:00
[CRT]
Implement _mbsnlen, _mbstrnlen svn path=/trunk/; revision=57404
This commit is contained in:
parent
f345eac12b
commit
9f08faa68c
2 changed files with 89 additions and 0 deletions
36
reactos/lib/sdk/crt/string/_mbsnlen.c
Normal file
36
reactos/lib/sdk/crt/string/_mbsnlen.c
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS CRT
|
||||||
|
* PURPOSE: Implementation of _mbsnlen
|
||||||
|
* FILE: lib/sdk/crt/string/_mbsnlen.c
|
||||||
|
* PROGRAMMER: Timo Kreuzer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mbstring.h>
|
||||||
|
|
||||||
|
_Check_return_
|
||||||
|
_CRTIMP
|
||||||
|
size_t
|
||||||
|
__cdecl
|
||||||
|
_mbsnlen(
|
||||||
|
_In_z_ const unsigned char *pmbstr,
|
||||||
|
_In_ size_t cjMaxLen)
|
||||||
|
{
|
||||||
|
size_t cchCount = 0;
|
||||||
|
unsigned char jMbsByte;
|
||||||
|
|
||||||
|
/* Loop while we have bytes to process */
|
||||||
|
while (cjMaxLen-- > 0)
|
||||||
|
{
|
||||||
|
/* Get next mb byte */
|
||||||
|
jMbsByte = *pmbstr++;
|
||||||
|
|
||||||
|
/* If this is 0, we're done */
|
||||||
|
if (jMbsByte == 0) break;
|
||||||
|
|
||||||
|
/* Don't count lead bytes */
|
||||||
|
if (!_ismbblead(jMbsByte)) cchCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cchCount;
|
||||||
|
}
|
53
reactos/lib/sdk/crt/string/_mbstrnlen.c
Normal file
53
reactos/lib/sdk/crt/string/_mbstrnlen.c
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS CRT
|
||||||
|
* PURPOSE: Implementation of _mbstrnlen
|
||||||
|
* FILE: lib/sdk/crt/string/_mbstrnlen.c
|
||||||
|
* PROGRAMMER: Timo Kreuzer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <precomp.h>
|
||||||
|
#include <mbctype.h>
|
||||||
|
#include <specstrings.h>
|
||||||
|
|
||||||
|
_Check_return_
|
||||||
|
_CRTIMP
|
||||||
|
size_t
|
||||||
|
__cdecl
|
||||||
|
_mbstrnlen(
|
||||||
|
_In_z_ const char *pmbstr,
|
||||||
|
_In_ size_t cjMaxLen)
|
||||||
|
{
|
||||||
|
size_t cchCount = 0;
|
||||||
|
unsigned char jMbsByte;
|
||||||
|
|
||||||
|
/* Check parameters */
|
||||||
|
if (!MSVCRT_CHECK_PMT((pmbstr != 0)) && (cjMaxLen <= INT_MAX))
|
||||||
|
{
|
||||||
|
_set_errno(EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Loop while we have bytes to process */
|
||||||
|
while (cjMaxLen-- > 0)
|
||||||
|
{
|
||||||
|
/* Get next mb byte */
|
||||||
|
jMbsByte = *pmbstr++;
|
||||||
|
|
||||||
|
/* If this is 0, we're done */
|
||||||
|
if (jMbsByte == 0) break;
|
||||||
|
|
||||||
|
/* if this is a lead byte, continue with next char */
|
||||||
|
if (_ismbblead(jMbsByte))
|
||||||
|
{
|
||||||
|
// FIXME: check if this is a valid char.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Count this character */
|
||||||
|
cchCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cchCount;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue