ReactOS 0.4.15-dev-8390-g075894b
mbbtype.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/sdk/crt/mbstring/mbbtype.c
5 * PURPOSE: Determines the type of a multibyte character
6 * PROGRAMERS:
7 * Copyright 1999 Ariadne
8 * Copyright 1999 Alexandre Julliard
9 * Copyright 2000 Jon Griffths
10 *
11 */
12
13#include <precomp.h>
14
15#include <mbstring.h>
16#include <mbctype.h>
17
18/*
19 * @implemented
20 */
21int _mbbtype(unsigned char c , int type)
22{
23 if ( type == 1 ) {
24 if ((c >= 0x40 && c <= 0x7e ) || (c >= 0x80 && c <= 0xfc ) )
25 {
26 return _MBC_TRAIL;
27 }
28 else if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) ||
29 ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
30 return _MBC_ILLEGAL;
31 else
32 return 0;
33 } else {
34 if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) {
35 return _MBC_SINGLE;
36 }
37 else if ( (c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC) )
38 return _MBC_LEAD;
39 else if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) ||
40 ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
41 return _MBC_ILLEGAL;
42 else
43 return 0;
44 }
45 return 0;
46}
47
48/*
49 * @implemented
50 */
51int _mbsbtype( const unsigned char *str, size_t n )
52{
53 int lead = 0;
54 const unsigned char *end = str + n;
55
56 /* Lead bytes can also be trail bytes so we need to analyse the string.
57 * Also we must return _MBC_ILLEGAL for chars past the end of the string
58 */
59 while (str < end) /* Note: we skip the last byte - will check after the loop */
60 {
61 if (!*str)
62 return _MBC_ILLEGAL;
63 lead = !lead && _ismbblead(*str);
64 str++;
65 }
66
67 if (lead)
68 if (_ismbbtrail(*str))
69 return _MBC_TRAIL;
70 else
71 return _MBC_ILLEGAL;
72 else
73 if (_ismbblead(*str))
74 return _MBC_LEAD;
75 else
76 return _MBC_SINGLE;
77}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLdouble n
Definition: glext.h:7729
const GLubyte * c
Definition: glext.h:8905
int _mbsbtype(const unsigned char *str, size_t n)
Definition: mbbtype.c:51
int _mbbtype(unsigned char c, int type)
Definition: mbbtype.c:21
_Check_return_ _CRTIMP int __cdecl _ismbbtrail(_In_ unsigned int _C)
#define _MBC_TRAIL
Definition: msvcrt.h:825
#define _MBC_SINGLE
Definition: msvcrt.h:823
#define _MBC_LEAD
Definition: msvcrt.h:824
#define _MBC_ILLEGAL
Definition: msvcrt.h:826
int __cdecl _ismbblead(unsigned int)
Definition: ismblead.c:20
const WCHAR * str