2008-12-18 21:17:22 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/sdk/crt/mbstring/mbclen.c
|
|
|
|
* PURPOSE: Determines the length of a multi byte character
|
|
|
|
* PROGRAMERS:
|
|
|
|
* Copyright 1999 Alexandre Julliard
|
|
|
|
* Copyright 2000 Jon Griffths
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-12-13 16:32:17 +00:00
|
|
|
#include <precomp.h>
|
2007-03-14 20:24:57 +00:00
|
|
|
#include <mbstring.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
size_t _mbclen(const unsigned char *s)
|
|
|
|
{
|
2008-12-18 21:17:22 +00:00
|
|
|
return _ismbblead(*s) ? 2 : 1;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t _mbclen2(const unsigned int s)
|
|
|
|
{
|
2008-12-18 21:17:22 +00:00
|
|
|
return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assume MB_CUR_MAX == 2
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-12-18 21:17:22 +00:00
|
|
|
int mblen( const char *str, size_t size )
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2008-12-18 21:17:22 +00:00
|
|
|
if (str && *str && size)
|
|
|
|
{
|
2012-12-16 16:38:36 +00:00
|
|
|
return !isleadbyte((unsigned char)*str) ? 1 : (size>1 ? 2 : -1);
|
2008-12-18 21:17:22 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
2012-12-13 16:32:17 +00:00
|
|
|
|
|
|
|
size_t __cdecl mbrlen(const char *str, size_t len, mbstate_t *state)
|
|
|
|
{
|
|
|
|
mbstate_t s = (state ? *state : 0);
|
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
if(!len || !str || !*str)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(get_locinfo()->mb_cur_max == 1) {
|
|
|
|
return 1;
|
|
|
|
}else if(!s && isleadbyte((unsigned char)*str)) {
|
|
|
|
if(len == 1) {
|
|
|
|
s = (unsigned char)*str;
|
|
|
|
ret = -2;
|
|
|
|
}else {
|
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
}else if(!s) {
|
|
|
|
ret = 1;
|
|
|
|
}else {
|
|
|
|
s = 0;
|
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(state)
|
|
|
|
*state = s;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|