update for HEAD-2003091401
[reactos.git] / lib / msvcrt / mbstring / mbbtype.c
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/msvcrt/mbstring/mbbtype.c
5  * PURPOSE:     Determines the type of a multibyte character
6  * PROGRAMER:   Boudewijn Dekker
7  * UPDATE HISTORY:
8  *              12/04/99: Created
9  */
10
11 #include <msvcrt/mbstring.h>
12 #include <msvcrt/mbctype.h>
13
14 /*
15  * @implemented
16  */
17 int _mbbtype(unsigned char c , int type)
18 {
19         if ( type == 1 ) {
20                 if ((c >= 0x40 && c <= 0x7e ) || (c >= 0x80 && c <= 0xfc ) )
21                 {
22                         return _MBC_TRAIL;
23                 }
24                 else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) || 
25                          ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
26                          return _MBC_ILLEGAL;
27                 else
28                         return 0;
29         } else  {
30                 if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1  && c <= 0xDF )) {
31                         return _MBC_SINGLE;
32                 }
33                 else if ( (c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC) )
34                         return _MBC_LEAD;
35                 else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) || 
36                          ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
37                          return _MBC_ILLEGAL;
38                 else
39                         return 0;
40         }
41         return 0;       
42 }
43
44 /*
45  * @implemented
46  */
47 int _mbsbtype( const unsigned char *str, size_t n )
48 {
49         if ( str == NULL )
50                 return -1;
51         return _mbbtype(*(str+n),1);
52 }