update for HEAD-2003021201
[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 int _mbbtype(unsigned char c , int type)
15 {
16         if ( type == 1 ) {
17                 if ((c >= 0x40 && c <= 0x7e ) || (c >= 0x80 && c <= 0xfc ) )
18                 {
19                         return _MBC_TRAIL;
20                 }
21                 else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) || 
22                          ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
23                          return _MBC_ILLEGAL;
24                 else
25                         return 0;
26         } else  {
27                 if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1  && c <= 0xDF )) {
28                         return _MBC_SINGLE;
29                 }
30                 else if ( (c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC) )
31                         return _MBC_LEAD;
32                 else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) || 
33                          ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
34                          return _MBC_ILLEGAL;
35                 else
36                         return 0;
37         }
38         return 0;       
39 }
40
41 int _mbsbtype( const unsigned char *str, size_t n )
42 {
43         if ( str == NULL )
44                 return -1;
45         return _mbbtype(*(str+n),1);
46 }