1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS system libraries 4 * FILE: lib/sdk/crt/mbstring/mbclen.c 5 * PURPOSE: Determines the length of a multi byte character 6 * PROGRAMERS: 7 * Copyright 1999 Alexandre Julliard 8 * Copyright 2000 Jon Griffths 9 * 10 */ 11 12 #include <precomp.h> 13 #include <mbstring.h> 14 15 /* 16 * @implemented 17 */ _mbclen(const unsigned char * s)18size_t _mbclen(const unsigned char *s) 19 { 20 return _ismbblead(*s) ? 2 : 1; 21 } 22 _mbclen2(const unsigned int s)23size_t _mbclen2(const unsigned int s) 24 { 25 return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1; 26 } 27 28 /* 29 * assume MB_CUR_MAX == 2 30 * 31 * @implemented 32 */ mblen(const char * str,size_t size)33int mblen( const char *str, size_t size ) 34 { 35 if (str && *str && size) 36 { 37 return !isleadbyte((unsigned char)*str) ? 1 : (size>1 ? 2 : -1); 38 } 39 return 0; 40 } 41 mbrlen(const char * str,size_t len,mbstate_t * state)42size_t __cdecl mbrlen(const char *str, size_t len, mbstate_t *state) 43 { 44 mbstate_t s = (state ? *state : 0); 45 size_t ret; 46 47 if(!len || !str || !*str) 48 return 0; 49 50 if(get_locinfo()->mb_cur_max == 1) { 51 return 1; 52 }else if(!s && isleadbyte((unsigned char)*str)) { 53 if(len == 1) { 54 s = (unsigned char)*str; 55 ret = -2; 56 }else { 57 ret = 2; 58 } 59 }else if(!s) { 60 ret = 1; 61 }else { 62 s = 0; 63 ret = 2; 64 } 65 66 if(state) 67 *state = s; 68 return ret; 69 } 70 71