Debian Codegraph @

include/prism/encoding.h

raw symbols SCIP
1 /**
2 * @file encoding.h
3 *
4 * The encoding interface and implementations used by the parser.
5 */
6 #ifndef PRISM_ENCODING_H
7 #define PRISM_ENCODING_Hcxx . . $ `include/prism/encoding.h:7:9`!
8
9 #include "prism/defines.h"cxx . . $ `<file>/include/prism/defines.h`/
10 #include "prism/util/pm_strncasecmp.h"cxx . . $ `<file>/include/prism/util/pm_strncasecmp.h`/
11
12 #include <assert.h>
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include <stdint.h>
16
17 /**
18 * This struct defines the functions necessary to implement the encoding
19 * interface so we can determine how many bytes the subsequent character takes.
20 * Each callback should return the number of bytes, or 0 if the next bytes are
21 * invalid for the encoding and type.
22 */
23 typedef structcxx . . $ $anonymous_type_f1726b61bf0350fa_0# {
24 /**
25 * Return the number of bytes that the next character takes if it is valid
26 * in the encoding. Does not read more than n bytes. It is assumed that n is
27 * at least 1.
28 */
29 size_t (*char_widthcxx . . $ $anonymous_type_f1726b61bf0350fa_0#char_width.)(const uint8_tcxx . . $ uint8_t# *b, ptrdiff_t n);
30
31 /**
32 * Return the number of bytes that the next character takes if it is valid
33 * in the encoding and is alphabetical. Does not read more than n bytes. It
34 * is assumed that n is at least 1.
35 */
36 size_t (*alpha_charcxx . . $ $anonymous_type_f1726b61bf0350fa_0#alpha_char.)(const uint8_tcxx . . $ uint8_t# *b, ptrdiff_t n);
37
38 /**
39 * Return the number of bytes that the next character takes if it is valid
40 * in the encoding and is alphanumeric. Does not read more than n bytes. It
41 * is assumed that n is at least 1.
42 */
43 size_t (*alnum_charcxx . . $ $anonymous_type_f1726b61bf0350fa_0#alnum_char.)(const uint8_tcxx . . $ uint8_t# *b, ptrdiff_t n);
44
45 /**
46 * Return true if the next character is valid in the encoding and is an
47 * uppercase character. Does not read more than n bytes. It is assumed that
48 * n is at least 1.
49 */
50 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! (*isupper_charcxx . . $ $anonymous_type_f1726b61bf0350fa_0#isupper_char.)(const uint8_tcxx . . $ uint8_t# *b, ptrdiff_t n);
51
52 /**
53 * The name of the encoding. This should correspond to a value that can be
54 * passed to Encoding.find in Ruby.
55 */
56 const char *namecxx . . $ $anonymous_type_f1726b61bf0350fa_0#name.;
57
58 /**
59 * Return true if the encoding is a multibyte encoding.
60 */
61 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! multibytecxx . . $ $anonymous_type_f1726b61bf0350fa_0#multibyte.;
62 } pm_encoding_tcxx . . $ pm_encoding_t#;
63
64 /**
65 * All of the lookup tables use the first bit of each embedded byte to indicate
66 * whether the codepoint is alphabetical.
67 */
68 #define PRISM_ENCODING_ALPHABETIC_BITcxx . . $ `include/prism/encoding.h:68:9`! 1 << 0
69
70 /**
71 * All of the lookup tables use the second bit of each embedded byte to indicate
72 * whether the codepoint is alphanumeric.
73 */
74 #define PRISM_ENCODING_ALPHANUMERIC_BITcxx . . $ `include/prism/encoding.h:74:9`! 1 << 1
75
76 /**
77 * All of the lookup tables use the third bit of each embedded byte to indicate
78 * whether the codepoint is uppercase.
79 */
80 #define PRISM_ENCODING_UPPERCASE_BITcxx . . $ `include/prism/encoding.h:80:9`! 1 << 2
81
82 /**
83 * Return the size of the next character in the UTF-8 encoding.
84 *
85 * @param b The bytes to read.
86 * @param n The number of bytes that can be read.
87 * @returns The number of bytes that the next character takes if it is valid in
88 * the encoding, or 0 if it is not.
89 */
90 size_t pm_encoding_utf_8_char_widthcxx . . $ pm_encoding_utf_8_char_width(dc9dc2cf7fc514b1).(const uint8_tcxx . . $ uint8_t# *b, ptrdiff_t n);
91
92 /**
93 * Return the size of the next character in the UTF-8 encoding if it is an
94 * alphabetical character.
95 *
96 * @param b The bytes to read.
97 * @param n The number of bytes that can be read.
98 * @returns The number of bytes that the next character takes if it is valid in
99 * the encoding, or 0 if it is not.
100 */
101 size_t pm_encoding_utf_8_alpha_charcxx . . $ pm_encoding_utf_8_alpha_char(dc9dc2cf7fc514b1).(const uint8_tcxx . . $ uint8_t# *b, ptrdiff_t n);
102
103 /**
104 * Return the size of the next character in the UTF-8 encoding if it is an
105 * alphanumeric character.
106 *
107 * @param b The bytes to read.
108 * @param n The number of bytes that can be read.
109 * @returns The number of bytes that the next character takes if it is valid in
110 * the encoding, or 0 if it is not.
111 */
112 size_t pm_encoding_utf_8_alnum_charcxx . . $ pm_encoding_utf_8_alnum_char(dc9dc2cf7fc514b1).(const uint8_tcxx . . $ uint8_t# *b, ptrdiff_t n);
113
114 /**
115 * Return true if the next character in the UTF-8 encoding if it is an uppercase
116 * character.
117 *
118 * @param b The bytes to read.
119 * @param n The number of bytes that can be read.
120 * @returns True if the next character is valid in the encoding and is an
121 * uppercase character, or false if it is not.
122 */
123 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! pm_encoding_utf_8_isupper_charcxx . . $ pm_encoding_utf_8_isupper_char(184b3a42c386a21c).(const uint8_tcxx . . $ uint8_t# *b, ptrdiff_t n);
124
125 /**
126 * This lookup table is referenced in both the UTF-8 encoding file and the
127 * parser directly in order to speed up the default encoding processing. It is
128 * used to indicate whether a character is alphabetical, alphanumeric, or
129 * uppercase in unicode mappings.
130 */
131 extern const uint8_tcxx . . $ uint8_t# pm_encoding_unicode_tablecxx . . $ pm_encoding_unicode_table.[256];
132
133 /**
134 * These are all of the encodings that prism supports.
135 */
136 typedef enumcxx . . $ $anonymous_type_f1726b61bf0350fa_1# {
137 PM_ENCODING_UTF_8cxx . . $ PM_ENCODING_UTF_8. = 0,
138 PM_ENCODING_US_ASCIIcxx . . $ PM_ENCODING_US_ASCII.,
139 PM_ENCODING_ASCII_8BITcxx . . $ PM_ENCODING_ASCII_8BIT.,
140 PM_ENCODING_EUC_JPcxx . . $ PM_ENCODING_EUC_JP.,
141 PM_ENCODING_WINDOWS_31Jcxx . . $ PM_ENCODING_WINDOWS_31J.,
142
143 // We optionally support excluding the full set of encodings to only support the
144 // minimum necessary to process Ruby code without encoding comments.
145 #ifndef PRISM_ENCODING_EXCLUDE_FULL
146 PM_ENCODING_BIG5cxx . . $ PM_ENCODING_BIG5.,
147 PM_ENCODING_BIG5_HKSCScxx . . $ PM_ENCODING_BIG5_HKSCS.,
148 PM_ENCODING_BIG5_UAOcxx . . $ PM_ENCODING_BIG5_UAO.,
149 PM_ENCODING_CESU_8cxx . . $ PM_ENCODING_CESU_8.,
150 PM_ENCODING_CP51932cxx . . $ PM_ENCODING_CP51932.,
151 PM_ENCODING_CP850cxx . . $ PM_ENCODING_CP850.,
152 PM_ENCODING_CP852cxx . . $ PM_ENCODING_CP852.,
153 PM_ENCODING_CP855cxx . . $ PM_ENCODING_CP855.,
154 PM_ENCODING_CP949cxx . . $ PM_ENCODING_CP949.,
155 PM_ENCODING_CP950cxx . . $ PM_ENCODING_CP950.,
156 PM_ENCODING_CP951cxx . . $ PM_ENCODING_CP951.,
157 PM_ENCODING_EMACS_MULEcxx . . $ PM_ENCODING_EMACS_MULE.,
158 PM_ENCODING_EUC_JP_MScxx . . $ PM_ENCODING_EUC_JP_MS.,
159 PM_ENCODING_EUC_JIS_2004cxx . . $ PM_ENCODING_EUC_JIS_2004.,
160 PM_ENCODING_EUC_KRcxx . . $ PM_ENCODING_EUC_KR.,
161 PM_ENCODING_EUC_TWcxx . . $ PM_ENCODING_EUC_TW.,
162 PM_ENCODING_GB12345cxx . . $ PM_ENCODING_GB12345.,
163 PM_ENCODING_GB18030cxx . . $ PM_ENCODING_GB18030.,
164 PM_ENCODING_GB1988cxx . . $ PM_ENCODING_GB1988.,
165 PM_ENCODING_GB2312cxx . . $ PM_ENCODING_GB2312.,
166 PM_ENCODING_GBKcxx . . $ PM_ENCODING_GBK.,
167 PM_ENCODING_IBM437cxx . . $ PM_ENCODING_IBM437.,
168 PM_ENCODING_IBM720cxx . . $ PM_ENCODING_IBM720.,
169 PM_ENCODING_IBM737cxx . . $ PM_ENCODING_IBM737.,
170 PM_ENCODING_IBM775cxx . . $ PM_ENCODING_IBM775.,
171 PM_ENCODING_IBM852cxx . . $ PM_ENCODING_IBM852.,
172 PM_ENCODING_IBM855cxx . . $ PM_ENCODING_IBM855.,
173 PM_ENCODING_IBM857cxx . . $ PM_ENCODING_IBM857.,
174 PM_ENCODING_IBM860cxx . . $ PM_ENCODING_IBM860.,
175 PM_ENCODING_IBM861cxx . . $ PM_ENCODING_IBM861.,
176 PM_ENCODING_IBM862cxx . . $ PM_ENCODING_IBM862.,
177 PM_ENCODING_IBM863cxx . . $ PM_ENCODING_IBM863.,
178 PM_ENCODING_IBM864cxx . . $ PM_ENCODING_IBM864.,
179 PM_ENCODING_IBM865cxx . . $ PM_ENCODING_IBM865.,
180 PM_ENCODING_IBM866cxx . . $ PM_ENCODING_IBM866.,
181 PM_ENCODING_IBM869cxx . . $ PM_ENCODING_IBM869.,
182 PM_ENCODING_ISO_8859_1cxx . . $ PM_ENCODING_ISO_8859_1.,
183 PM_ENCODING_ISO_8859_2cxx . . $ PM_ENCODING_ISO_8859_2.,
184 PM_ENCODING_ISO_8859_3cxx . . $ PM_ENCODING_ISO_8859_3.,
185 PM_ENCODING_ISO_8859_4cxx . . $ PM_ENCODING_ISO_8859_4.,
186 PM_ENCODING_ISO_8859_5cxx . . $ PM_ENCODING_ISO_8859_5.,
187 PM_ENCODING_ISO_8859_6cxx . . $ PM_ENCODING_ISO_8859_6.,
188 PM_ENCODING_ISO_8859_7cxx . . $ PM_ENCODING_ISO_8859_7.,
189 PM_ENCODING_ISO_8859_8cxx . . $ PM_ENCODING_ISO_8859_8.,
190 PM_ENCODING_ISO_8859_9cxx . . $ PM_ENCODING_ISO_8859_9.,
191 PM_ENCODING_ISO_8859_10cxx . . $ PM_ENCODING_ISO_8859_10.,
192 PM_ENCODING_ISO_8859_11cxx . . $ PM_ENCODING_ISO_8859_11.,
193 PM_ENCODING_ISO_8859_13cxx . . $ PM_ENCODING_ISO_8859_13.,
194 PM_ENCODING_ISO_8859_14cxx . . $ PM_ENCODING_ISO_8859_14.,
195 PM_ENCODING_ISO_8859_15cxx . . $ PM_ENCODING_ISO_8859_15.,
196 PM_ENCODING_ISO_8859_16cxx . . $ PM_ENCODING_ISO_8859_16.,
197 PM_ENCODING_KOI8_Rcxx . . $ PM_ENCODING_KOI8_R.,
198 PM_ENCODING_KOI8_Ucxx . . $ PM_ENCODING_KOI8_U.,
199 PM_ENCODING_MAC_CENT_EUROcxx . . $ PM_ENCODING_MAC_CENT_EURO.,
200 PM_ENCODING_MAC_CROATIANcxx . . $ PM_ENCODING_MAC_CROATIAN.,
201 PM_ENCODING_MAC_CYRILLICcxx . . $ PM_ENCODING_MAC_CYRILLIC.,
202 PM_ENCODING_MAC_GREEKcxx . . $ PM_ENCODING_MAC_GREEK.,
203 PM_ENCODING_MAC_ICELANDcxx . . $ PM_ENCODING_MAC_ICELAND.,
204 PM_ENCODING_MAC_JAPANESEcxx . . $ PM_ENCODING_MAC_JAPANESE.,
205 PM_ENCODING_MAC_ROMANcxx . . $ PM_ENCODING_MAC_ROMAN.,
206 PM_ENCODING_MAC_ROMANIAcxx . . $ PM_ENCODING_MAC_ROMANIA.,
207 PM_ENCODING_MAC_THAIcxx . . $ PM_ENCODING_MAC_THAI.,
208 PM_ENCODING_MAC_TURKISHcxx . . $ PM_ENCODING_MAC_TURKISH.,
209 PM_ENCODING_MAC_UKRAINEcxx . . $ PM_ENCODING_MAC_UKRAINE.,
210 PM_ENCODING_SHIFT_JIScxx . . $ PM_ENCODING_SHIFT_JIS.,
211 PM_ENCODING_SJIS_DOCOMOcxx . . $ PM_ENCODING_SJIS_DOCOMO.,
212 PM_ENCODING_SJIS_KDDIcxx . . $ PM_ENCODING_SJIS_KDDI.,
213 PM_ENCODING_SJIS_SOFTBANKcxx . . $ PM_ENCODING_SJIS_SOFTBANK.,
214 PM_ENCODING_STATELESS_ISO_2022_JPcxx . . $ PM_ENCODING_STATELESS_ISO_2022_JP.,
215 PM_ENCODING_STATELESS_ISO_2022_JP_KDDIcxx . . $ PM_ENCODING_STATELESS_ISO_2022_JP_KDDI.,
216 PM_ENCODING_TIS_620cxx . . $ PM_ENCODING_TIS_620.,
217 PM_ENCODING_UTF8_MACcxx . . $ PM_ENCODING_UTF8_MAC.,
218 PM_ENCODING_UTF8_DOCOMOcxx . . $ PM_ENCODING_UTF8_DOCOMO.,
219 PM_ENCODING_UTF8_KDDIcxx . . $ PM_ENCODING_UTF8_KDDI.,
220 PM_ENCODING_UTF8_SOFTBANKcxx . . $ PM_ENCODING_UTF8_SOFTBANK.,
221 PM_ENCODING_WINDOWS_1250cxx . . $ PM_ENCODING_WINDOWS_1250.,
222 PM_ENCODING_WINDOWS_1251cxx . . $ PM_ENCODING_WINDOWS_1251.,
223 PM_ENCODING_WINDOWS_1252cxx . . $ PM_ENCODING_WINDOWS_1252.,
224 PM_ENCODING_WINDOWS_1253cxx . . $ PM_ENCODING_WINDOWS_1253.,
225 PM_ENCODING_WINDOWS_1254cxx . . $ PM_ENCODING_WINDOWS_1254.,
226 PM_ENCODING_WINDOWS_1255cxx . . $ PM_ENCODING_WINDOWS_1255.,
227 PM_ENCODING_WINDOWS_1256cxx . . $ PM_ENCODING_WINDOWS_1256.,
228 PM_ENCODING_WINDOWS_1257cxx . . $ PM_ENCODING_WINDOWS_1257.,
229 PM_ENCODING_WINDOWS_1258cxx . . $ PM_ENCODING_WINDOWS_1258.,
230 PM_ENCODING_WINDOWS_874cxx . . $ PM_ENCODING_WINDOWS_874.,
231 #endif
232
233 PM_ENCODING_MAXIMUMcxx . . $ PM_ENCODING_MAXIMUM.
234 } pm_encoding_type_tcxx . . $ pm_encoding_type_t#;
235
236 /**
237 * This is the table of all of the encodings that prism supports.
238 */
239 extern const pm_encoding_tcxx . . $ pm_encoding_t# pm_encodingscxx . . $ pm_encodings.[PM_ENCODING_MAXIMUMcxx . . $ PM_ENCODING_MAXIMUM.];
240
241 /**
242 * This is the default UTF-8 encoding. We need a reference to it to quickly
243 * create parsers.
244 */
245 #define PM_ENCODING_UTF_8_ENTRYcxx . . $ `include/prism/encoding.h:245:9`! (&pm_encodings[PM_ENCODING_UTF_8])
246
247 /**
248 * This is the US-ASCII encoding. We need a reference to it to be able to
249 * compare against it when a string is being created because it could possibly
250 * need to fall back to ASCII-8BIT.
251 */
252 #define PM_ENCODING_US_ASCII_ENTRYcxx . . $ `include/prism/encoding.h:252:9`! (&pm_encodings[PM_ENCODING_US_ASCII])
253
254 /**
255 * This is the ASCII-8BIT encoding. We need a reference to it so that pm_strpbrk
256 * can compare against it because invalid multibyte characters are not a thing
257 * in this encoding. It is also needed for handling Regexp encoding flags.
258 */
259 #define PM_ENCODING_ASCII_8BIT_ENTRYcxx . . $ `include/prism/encoding.h:259:9`! (&pm_encodings[PM_ENCODING_ASCII_8BIT])
260
261 /**
262 * This is the EUC-JP encoding. We need a reference to it to quickly process
263 * regular expression modifiers.
264 */
265 #define PM_ENCODING_EUC_JP_ENTRYcxx . . $ `include/prism/encoding.h:265:9`! (&pm_encodings[PM_ENCODING_EUC_JP])
266
267 /**
268 * This is the Windows-31J encoding. We need a reference to it to quickly
269 * process regular expression modifiers.
270 */
271 #define PM_ENCODING_WINDOWS_31J_ENTRYcxx . . $ `include/prism/encoding.h:271:9`! (&pm_encodings[PM_ENCODING_WINDOWS_31J])
272
273 /**
274 * Parse the given name of an encoding and return a pointer to the corresponding
275 * encoding struct if one can be found, otherwise return NULL.
276 *
277 * @param start A pointer to the first byte of the name.
278 * @param end A pointer to the last byte of the name.
279 * @returns A pointer to the encoding struct if one is found, otherwise NULL.
280 */
281 const pm_encoding_tcxx . . $ pm_encoding_t# * pm_encoding_findcxx . . $ pm_encoding_find(b3921455d57a439).(const uint8_tcxx . . $ uint8_t# *start, const uint8_tcxx . . $ uint8_t# *end);
282
283 #endif