xref: /illumos-gate/usr/src/uts/common/sys/kiconv_sc.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_KICONV_SC_H
27 #define	_SYS_KICONV_SC_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #ifdef	_KERNEL
34 
35 /* Valid first byte of GB18030 character or not. */
36 #define	KICONV_SC_IS_GBK_1st_BYTE(c)		((c) >= 0x81 && (c) <= 0xfe)
37 
38 /* Valid 2nd byte of 2 bytes GB18030 character or not. */
39 #define	KICONV_SC_IS_GBK_2nd_BYTE(c)					\
40 		(((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0x80 && (c) <= 0xFE))
41 
42 /* Valid 2nd byte of 4 bytes GB18030 character or not. */
43 #define	KICONV_SC_IS_GB18030_2nd_BYTE(c)	((c) >= 0x30 && (c) <= 0x39)
44 
45 /* Valid 3rd byte of 4 bytes GB18030 character or not. */
46 #define	KICONV_SC_IS_GB18030_3rd_BYTE(c)	((c) >= 0x81 && (c) <= 0xfe)
47 
48 /* Valid 4th byte of 4 bytes GB18030 character or not. */
49 #define	KICONV_SC_IS_GB18030_4th_BYTE(c)			\
50 	    KICONV_SC_IS_GB18030_2nd_BYTE((c))
51 
52 /* Get the number of bytes of one GB character(uint32_t). */
53 #define	KICONV_SC_GET_GB_LEN(v, l)				\
54 	    if (((v) & 0xFFFF0000) != 0)			\
55 		    (l) = 4;					\
56 	    else if (((v) & 0xFF00) != 0)			\
57 		    (l) = 2;					\
58 	    else						\
59 		    (l) = 1
60 
61 /* Valid GB2312 byte or not. */
62 #define	KICONV_SC_IS_GB2312_BYTE(b)		((b) >= 0xA1 && (b) <= 0xFE)
63 
64 /* UTF-8 value of Unicode Plane 1 start code point (U+10000). */
65 #define	KICONV_SC_PLANE1_UCS4_START		(0x10000)
66 #define	KICONV_SC_PLANE1_UTF8_START		(0xF0908080)
67 
68 /* Start code point of GB18030 which maps to U+10000. */
69 #define	KICONV_SC_PLANE1_GB18030_START		(0x90308130)
70 
71 #endif	/* _KERNEL */
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif /* _SYS_KICONV_SC_H */
78