e186674242da8d2b708e0b5b563257353a628008
[reactos.git] / reactos / lib / sdk / crt / mbstring / mbclen.c
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 <mbstring.h>
13 #include <stdlib.h>
14
15 int isleadbyte(int byte);
16
17 /*
18 * @implemented
19 */
20 size_t _mbclen(const unsigned char *s)
21 {
22 return _ismbblead(*s) ? 2 : 1;
23 }
24
25 size_t _mbclen2(const unsigned int s)
26 {
27 return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1;
28 }
29
30 /*
31 * assume MB_CUR_MAX == 2
32 *
33 * @implemented
34 */
35 int mblen( const char *str, size_t size )
36 {
37 if (str && *str && size)
38 {
39 return !isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
40 }
41 return 0;
42 }