]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3convertutf.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3convertutf.h
1 /*\r
2  * Copyright 2001-2004 Unicode, Inc.\r
3  * \r
4  * Disclaimer\r
5  * \r
6  * This source code is provided as is by Unicode, Inc. No claims are\r
7  * made as to fitness for any particular purpose. No warranties of any\r
8  * kind are expressed or implied. The recipient agrees to determine\r
9  * applicability of information provided. If this file has been\r
10  * purchased on magnetic or optical media from Unicode, Inc., the\r
11  * sole remedy for any claim will be exchange of defective media\r
12  * within 90 days of receipt.\r
13  * \r
14  * Limitations on Rights to Redistribute This Code\r
15  * \r
16  * Unicode, Inc. hereby grants the right to freely use the information\r
17  * supplied in this file in the creation of products supporting the\r
18  * Unicode Standard, and to make copies of this file in any form\r
19  * for internal or external distribution as long as this notice\r
20  * remains attached.\r
21  */\r
22 \r
23 /* ---------------------------------------------------------------------\r
24 \r
25     Conversions between UTF32, UTF-16, and UTF-8.  Header file.\r
26 \r
27     Several functions are included here, forming a complete set of\r
28     conversions between the three formats.  UTF-7 is not included\r
29     here, but is handled in a separate source file.\r
30 \r
31     Each of these routines takes pointers to input buffers and output\r
32     buffers.  The input buffers are const.\r
33 \r
34     Each routine converts the text between *sourceStart and sourceEnd,\r
35     putting the result into the buffer between *targetStart and\r
36     targetEnd. Note: the end pointers are *after* the last item: e.g. \r
37     *(sourceEnd - 1) is the last item.\r
38 \r
39     The return result indicates whether the conversion was successful,\r
40     and if not, whether the problem was in the source or target buffers.\r
41     (Only the first encountered problem is indicated.)\r
42 \r
43     After the conversion, *sourceStart and *targetStart are both\r
44     updated to point to the end of last text successfully converted in\r
45     the respective buffers.\r
46 \r
47     Input parameters:\r
48         sourceStart - pointer to a pointer to the source buffer.\r
49                 The contents of this are modified on return so that\r
50                 it points at the next thing to be converted.\r
51         targetStart - similarly, pointer to pointer to the target buffer.\r
52         sourceEnd, targetEnd - respectively pointers to the ends of the\r
53                 two buffers, for overflow checking only.\r
54 \r
55     These conversion functions take a ConversionFlags argument. When this\r
56     flag is set to strict, both irregular sequences and isolated surrogates\r
57     will cause an error.  When the flag is set to lenient, both irregular\r
58     sequences and isolated surrogates are converted.\r
59 \r
60     Whether the flag is strict or lenient, all illegal sequences will cause\r
61     an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,\r
62     or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code\r
63     must check for illegal sequences.\r
64 \r
65     When the flag is set to lenient, characters over 0x10FFFF are converted\r
66     to the replacement character; otherwise (when the flag is set to strict)\r
67     they constitute an error.\r
68 \r
69     Output parameters:\r
70         The value "sourceIllegal" is returned from some routines if the input\r
71         sequence is malformed.  When "sourceIllegal" is returned, the source\r
72         value will point to the illegal value that caused the problem. E.g.,\r
73         in UTF-8 when a sequence is malformed, it points to the start of the\r
74         malformed sequence.  \r
75 \r
76     Author: Mark E. Davis, 1994.\r
77     Rev History: Rick McGowan, fixes & updates May 2001.\r
78                  Fixes & updates, Sept 2001.\r
79 \r
80 ------------------------------------------------------------------------ */\r
81 \r
82 /* ---------------------------------------------------------------------\r
83     The following 4 definitions are compiler-specific.\r
84     The C standard does not guarantee that wchar_t has at least\r
85     16 bits, so wchar_t is no less portable than unsigned short!\r
86     All should be unsigned values to avoid sign extension during\r
87     bit mask & shift operations.\r
88 ------------------------------------------------------------------------ */\r
89 \r
90 \r
91 // Changes for ANTLR3 - Jim Idle, January 2008.\r
92 // builtin types defined for Unicode types changed to\r
93 // aliases for the types that are system determined by\r
94 // ANTLR at compile time.\r
95 //\r
96 // typedef unsigned long        UTF32;  /* at least 32 bits */\r
97 // typedef unsigned short       UTF16;  /* at least 16 bits */\r
98 // typedef unsigned char        UTF8;   /* typically 8 bits */\r
99 // typedef unsigned char        Boolean; /* 0 or 1 */\r
100 \r
101 #ifndef _ANTLR3_CONVERTUTF_H\r
102 #define _ANTLR3_CONVERTUTF_H\r
103 \r
104 #include        <antlr3defs.h>\r
105 \r
106 typedef ANTLR3_UINT32   UTF32;  /* at least 32 bits */\r
107 typedef ANTLR3_UINT16   UTF16;  /* at least 16 bits */\r
108 typedef ANTLR3_UINT8    UTF8;   /* typically 8 bits */\r
109 \r
110 /* Some fundamental constants */\r
111 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD\r
112 #define UNI_MAX_BMP (UTF32)0x0000FFFF\r
113 #define UNI_MAX_UTF16 (UTF32)0x0010FFFF\r
114 #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF\r
115 #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF\r
116 \r
117 typedef enum {\r
118         conversionOK,           /* conversion successful */\r
119         sourceExhausted,        /* partial character in source, but hit end */\r
120         targetExhausted,        /* insuff. room in target for conversion */\r
121         sourceIllegal           /* source sequence is illegal/malformed */\r
122 } ConversionResult;\r
123 \r
124 typedef enum {\r
125         strictConversion = 0,\r
126         lenientConversion\r
127 } ConversionFlags;\r
128 \r
129 /* This is for C++ and does no harm in C */\r
130 #ifdef __cplusplus\r
131 extern "C" {\r
132 #endif\r
133 \r
134 ConversionResult ConvertUTF8toUTF16 (\r
135                 const UTF8** sourceStart, const UTF8* sourceEnd, \r
136                 UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);\r
137 \r
138 ConversionResult ConvertUTF16toUTF8 (\r
139                 const UTF16** sourceStart, const UTF16* sourceEnd, \r
140                 UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);\r
141                 \r
142 ConversionResult ConvertUTF8toUTF32 (\r
143                 const UTF8** sourceStart, const UTF8* sourceEnd, \r
144                 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);\r
145 \r
146 ConversionResult ConvertUTF32toUTF8 (\r
147                 const UTF32** sourceStart, const UTF32* sourceEnd, \r
148                 UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);\r
149                 \r
150 ConversionResult ConvertUTF16toUTF32 (\r
151                 const UTF16** sourceStart, const UTF16* sourceEnd, \r
152                 UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);\r
153 \r
154 ConversionResult ConvertUTF32toUTF16 (\r
155                 const UTF32** sourceStart, const UTF32* sourceEnd, \r
156                 UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);\r
157 \r
158 ANTLR3_BOOLEAN isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);\r
159 \r
160 #ifdef __cplusplus\r
161 }\r
162 #endif\r
163 \r
164 #endif\r
165 \r
166 /* --------------------------------------------------------------------- */\r