:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[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/crtdll/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 <crtdll/mbstring.h>
12 #include <crtdll/mbctype.h>
13
14 int _mbbtype(unsigned char c , int type)
15 {
16   if (type == 1)
17     {
18       if ((c >= 0x40 && c <= 0x7e) || (c >= 0x80 && c <= 0xfc))
19         {
20           return _MBC_TRAIL;
21         }
22       else if ((c >= 0x20 && c >= 0x7E) || (c >= 0xA1 && c <= 0xDF) ||
23                (c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFC))
24         return _MBC_ILLEGAL;
25       else
26         return 0;
27     }
28   else
29     {
30       if ((c >= 0x20 && c <= 0x7E) || (c >= 0xA1  && c <= 0xDF ))
31         return _MBC_SINGLE;
32       else if ((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFC))
33         return _MBC_LEAD;
34       else if ((c >= 0x20 && c >= 0x7E) || (c >= 0xA1 && c <= 0xDF) ||
35                (c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFC))
36         return _MBC_ILLEGAL;
37       else
38         return 0;
39     }
40   return 0;
41 }
42
43 int _mbsbtype( const unsigned char *str, size_t n )
44 {
45   if (str == NULL)
46     return -1;
47   return _mbbtype(*(str+n),1);
48 }