Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

encoding.h
Go to the documentation of this file.
1 /**********************************************************************
2
3 encoding.h -
4
5 $Author: matz $
6 created at: Thu May 24 11:49:41 JST 2007
7
8 Copyright (C) 2007 Yukihiro Matsumoto
9
10 **********************************************************************/
11
12 #ifndef RUBY_ENCODING_H
13 #define RUBY_ENCODING_H 1
14
15 #ifdef RUBY_INTERNAL_H
16 #error "Include this file before internal.h"
17 #endif
18
19 #if defined(__cplusplus)
20 extern "C" {
21 #if 0
22 } /* satisfy cc-mode */
23 #endif
24 #endif
25
26 #include <stdarg.h>
27 #include "ruby/ruby.h"
28 #include "ruby/oniguruma.h"
29
30 RUBY_SYMBOL_EXPORT_BEGIN
31
32 enum ruby_encoding_consts {
33 RUBY_ENCODING_INLINE_MAX = 127,
34 RUBY_ENCODING_SHIFT = (RUBY_FL_USHIFT+10),
35 RUBY_ENCODING_MASK = (RUBY_ENCODING_INLINE_MAX<<RUBY_ENCODING_SHIFT
36 /* RUBY_FL_USER10..RUBY_FL_USER16 */),
37 RUBY_ENCODING_MAXNAMELEN = 42
38 };
39
40 #define ENCODING_INLINE_MAX RUBY_ENCODING_INLINE_MAX
41 #define ENCODING_SHIFT RUBY_ENCODING_SHIFT
42 #define ENCODING_MASK RUBY_ENCODING_MASK
43
44 #define RB_ENCODING_SET_INLINED(obj,i) do {\
45 RBASIC(obj)->flags &= ~RUBY_ENCODING_MASK;\
46 RBASIC(obj)->flags |= (VALUE)(i) << RUBY_ENCODING_SHIFT;\
47 } while (0)
48 #define RB_ENCODING_SET(obj,i) rb_enc_set_index((obj), (i))
49
50 #define RB_ENCODING_GET_INLINED(obj) \
51 (int)((RBASIC(obj)->flags & RUBY_ENCODING_MASK)>>RUBY_ENCODING_SHIFT)
52 #define RB_ENCODING_GET(obj) \
53 (RB_ENCODING_GET_INLINED(obj) != RUBY_ENCODING_INLINE_MAX ? \
54 RB_ENCODING_GET_INLINED(obj) : \
55 rb_enc_get_index(obj))
56
57 #define RB_ENCODING_IS_ASCII8BIT(obj) (RB_ENCODING_GET_INLINED(obj) == 0)
58
59 #define ENCODING_SET_INLINED(obj,i) RB_ENCODING_SET_INLINED(obj,i)
60 #define ENCODING_SET(obj,i) RB_ENCODING_SET(obj,i)
61 #define ENCODING_GET_INLINED(obj) RB_ENCODING_GET_INLINED(obj)
62 #define ENCODING_GET(obj) RB_ENCODING_GET(obj)
63 #define ENCODING_IS_ASCII8BIT(obj) RB_ENCODING_IS_ASCII8BIT(obj)
64 #define ENCODING_MAXNAMELEN RUBY_ENCODING_MAXNAMELEN
65
66 enum ruby_coderange_type {
67 RUBY_ENC_CODERANGE_UNKNOWN = 0,
68 RUBY_ENC_CODERANGE_7BIT = ((int)RUBY_FL_USER8),
69 RUBY_ENC_CODERANGE_VALID = ((int)RUBY_FL_USER9),
70 RUBY_ENC_CODERANGE_BROKEN = ((int)(RUBY_FL_USER8|RUBY_FL_USER9)),
71 RUBY_ENC_CODERANGE_MASK = (RUBY_ENC_CODERANGE_7BIT|
72 RUBY_ENC_CODERANGE_VALID|
73 RUBY_ENC_CODERANGE_BROKEN)
74 };
75
76 static inline int
77 rb_enc_coderange_clean_p(int cr)
78 {
79 return (cr ^ (cr >> 1)) & RUBY_ENC_CODERANGE_7BIT;
80 }
81 #define RB_ENC_CODERANGE_CLEAN_P(cr) rb_enc_coderange_clean_p(cr)
82 #define RB_ENC_CODERANGE(obj) ((int)RBASIC(obj)->flags & RUBY_ENC_CODERANGE_MASK)
83 #define RB_ENC_CODERANGE_ASCIIONLY(obj) (RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT)
84 #define RB_ENC_CODERANGE_SET(obj,cr) (\
85 RBASIC(obj)->flags = \
86 (RBASIC(obj)->flags & ~RUBY_ENC_CODERANGE_MASK) | (cr))
87 #define RB_ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_SET((obj),0)
88
89 /* assumed ASCII compatibility */
90 #define RB_ENC_CODERANGE_AND(a, b) \
91 ((a) == RUBY_ENC_CODERANGE_7BIT ? (b) : \
92 (a) != RUBY_ENC_CODERANGE_VALID ? RUBY_ENC_CODERANGE_UNKNOWN : \
93 (b) == RUBY_ENC_CODERANGE_7BIT ? RUBY_ENC_CODERANGE_VALID : (b))
94
95 #define RB_ENCODING_CODERANGE_SET(obj, encindex, cr) \
96 do { \
97 VALUE rb_encoding_coderange_obj = (obj); \
98 RB_ENCODING_SET(rb_encoding_coderange_obj, (encindex)); \
99 RB_ENC_CODERANGE_SET(rb_encoding_coderange_obj, (cr)); \
100 } while (0)
101
102 #define ENC_CODERANGE_MASK RUBY_ENC_CODERANGE_MASK
103 #define ENC_CODERANGE_UNKNOWN RUBY_ENC_CODERANGE_UNKNOWN
104 #define ENC_CODERANGE_7BIT RUBY_ENC_CODERANGE_7BIT
105 #define ENC_CODERANGE_VALID RUBY_ENC_CODERANGE_VALID
106 #define ENC_CODERANGE_BROKEN RUBY_ENC_CODERANGE_BROKEN
107 #define ENC_CODERANGE_CLEAN_P(cr) RB_ENC_CODERANGE_CLEAN_P(cr)
108 #define ENC_CODERANGE(obj) RB_ENC_CODERANGE(obj)
109 #define ENC_CODERANGE_ASCIIONLY(obj) RB_ENC_CODERANGE_ASCIIONLY(obj)
110 #define ENC_CODERANGE_SET(obj,cr) RB_ENC_CODERANGE_SET(obj,cr)
111 #define ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_CLEAR(obj)
112 #define ENC_CODERANGE_AND(a, b) RB_ENC_CODERANGE_AND(a, b)
113 #define ENCODING_CODERANGE_SET(obj, encindex, cr) RB_ENCODING_CODERANGE_SET(obj, encindex, cr)
114
115 typedef const OnigEncodingType rb_encoding;
116
117 int rb_char_to_option_kcode(int c, int *option, int *kcode);
118
119 int rb_enc_replicate(const char *, rb_encoding *);
120 int rb_define_dummy_encoding(const char *);
121 PUREFUNC(int rb_enc_dummy_p(rb_encoding *enc));
122 PUREFUNC(int rb_enc_to_index(rb_encoding *enc));
123 int rb_enc_get_index(VALUE obj);
124 void rb_enc_set_index(VALUE obj, int encindex);
125 int rb_enc_capable(VALUE obj);
126 int rb_enc_find_index(const char *name);
127 int rb_enc_alias(const char *alias, const char *orig);
128 int rb_to_encoding_index(VALUE);
129 rb_encoding *rb_to_encoding(VALUE);
130 rb_encoding *rb_find_encoding(VALUE);
131 rb_encoding *rb_enc_get(VALUE);
132 rb_encoding *rb_enc_compatible(VALUE,VALUE);
133 rb_encoding *rb_enc_check(VALUE,VALUE);
134 VALUE rb_enc_associate_index(VALUE, int);
135 VALUE rb_enc_associate(VALUE, rb_encoding*);
136 void rb_enc_copy(VALUE dst, VALUE src);
137
138 VALUE rb_enc_str_new(const char*, long, rb_encoding*);
139 VALUE rb_enc_str_new_cstr(const char*, rb_encoding*);
140 VALUE rb_enc_str_new_static(const char*, long, rb_encoding*);
141 VALUE rb_enc_reg_new(const char*, long, rb_encoding*, int);
142 PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char*, ...), 2, 3);
143 VALUE rb_enc_vsprintf(rb_encoding *, const char*, va_list);
144 long rb_enc_strlen(const char*, const char*, rb_encoding*);
145 char* rb_enc_nth(const char*, const char*, long, rb_encoding*);
146 VALUE rb_obj_encoding(VALUE);
147 VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
148 VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
149
150 VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *);
151 VALUE rb_str_export_to_enc(VALUE, rb_encoding *);
152 VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to);
153 VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts);
154
155 #ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
156 #define rb_enc_str_new(str, len, enc) RB_GNUC_EXTENSION_BLOCK( \
157 (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \
158 rb_enc_str_new_static((str), (len), (enc)) : \
159 rb_enc_str_new((str), (len), (enc)) \
160 )
161 #define rb_enc_str_new_cstr(str, enc) RB_GNUC_EXTENSION_BLOCK( \
162 (__builtin_constant_p(str)) ? \
163 rb_enc_str_new_static((str), (long)strlen(str), (enc)) : \
164 rb_enc_str_new_cstr((str), (enc)) \
165 )
166 #endif
167
168 PRINTF_ARGS(NORETURN(void rb_enc_raise(rb_encoding *, VALUE, const char*, ...)), 3, 4);
169
170 /* index -> rb_encoding */
171 rb_encoding *rb_enc_from_index(int idx);
172
173 /* name -> rb_encoding */
174 rb_encoding *rb_enc_find(const char *name);
175
176 /* rb_encoding * -> name */
177 #define rb_enc_name(enc) (enc)->name
178
179 /* rb_encoding * -> minlen/maxlen */
180 #define rb_enc_mbminlen(enc) (enc)->min_enc_len
181 #define rb_enc_mbmaxlen(enc) (enc)->max_enc_len
182
183 /* -> mbclen (no error notification: 0 < ret <= e-p, no exception) */
184 int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc);
185
186 /* -> mbclen (only for valid encoding) */
187 int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc);
188
189 /* -> chlen, invalid or needmore */
190 int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc);
191 #define MBCLEN_CHARFOUND_P(ret) ONIGENC_MBCLEN_CHARFOUND_P(ret)
192 #define MBCLEN_CHARFOUND_LEN(ret) ONIGENC_MBCLEN_CHARFOUND_LEN(ret)
193 #define MBCLEN_INVALID_P(ret) ONIGENC_MBCLEN_INVALID_P(ret)
194 #define MBCLEN_NEEDMORE_P(ret) ONIGENC_MBCLEN_NEEDMORE_P(ret)
195 #define MBCLEN_NEEDMORE_LEN(ret) ONIGENC_MBCLEN_NEEDMORE_LEN(ret)
196
197 /* -> 0x00..0x7f, -1 */
198 int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc);
199
200
201 /* -> code (and len) or raise exception */
202 unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_encoding *enc);
203
204 /* prototype for obsolete function */
205 unsigned int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc);
206 /* overriding macro */
207 #define rb_enc_codepoint(p,e,enc) rb_enc_codepoint_len((p),(e),0,(enc))
208 #define rb_enc_mbc_to_codepoint(p, e, enc) ONIGENC_MBC_TO_CODE((enc),(UChar*)(p),(UChar*)(e))
209
210 /* -> codelen>0 or raise exception */
211 int rb_enc_codelen(int code, rb_encoding *enc);
212 /* -> 0 for invalid codepoint */
213 int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
214 #define rb_enc_code_to_mbclen(c, enc) ONIGENC_CODE_TO_MBCLEN((enc), (c));
215
216 /* code,ptr,encoding -> write buf */
217 #define rb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC((enc),(c),(UChar*)(buf))
218
219 /* start, ptr, end, encoding -> prev_char */
220 #define rb_enc_prev_char(s,p,e,enc) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
221 /* start, ptr, end, encoding -> next_char */
222 #define rb_enc_left_char_head(s,p,e,enc) ((char *)onigenc_get_left_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
223 #define rb_enc_right_char_head(s,p,e,enc) ((char *)onigenc_get_right_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
224 #define rb_enc_step_back(s,p,e,n,enc) ((char *)onigenc_step_back((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e),(int)(n)))
225
226 /* ptr, ptr, encoding -> newline_or_not */
227 #define rb_enc_is_newline(p,end,enc) ONIGENC_IS_MBC_NEWLINE((enc),(UChar*)(p),(UChar*)(end))
228
229 #define rb_enc_isctype(c,t,enc) ONIGENC_IS_CODE_CTYPE((enc),(c),(t))
230 #define rb_enc_isascii(c,enc) ONIGENC_IS_CODE_ASCII(c)
231 #define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA((enc),(c))
232 #define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER((enc),(c))
233 #define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER((enc),(c))
234 #define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT((enc),(c))
235 #define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM((enc),(c))
236 #define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT((enc),(c))
237 #define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE((enc),(c))
238 #define rb_enc_isdigit(c,enc) ONIGENC_IS_CODE_DIGIT((enc),(c))
239
240 static inline int
241 rb_enc_asciicompat_inline(rb_encoding *enc)
242 {
243 return rb_enc_mbminlen(enc)==1 && !rb_enc_dummy_p(enc);
244 }
245 #define rb_enc_asciicompat(enc) rb_enc_asciicompat_inline(enc)
246
247 int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc);
248 CONSTFUNC(int rb_enc_toupper(int c, rb_encoding *enc));
249 CONSTFUNC(int rb_enc_tolower(int c, rb_encoding *enc));
250 ID rb_intern3(const char*, long, rb_encoding*);
251 ID rb_interned_id_p(const char *, long, rb_encoding *);
252 int rb_enc_symname_p(const char*, rb_encoding*);
253 int rb_enc_symname2_p(const char*, long, rb_encoding*);
254 int rb_enc_str_coderange(VALUE);
255 long rb_str_coderange_scan_restartable(const char*, const char*, rb_encoding*, int*);
256 int rb_enc_str_asciionly_p(VALUE);
257 #define rb_enc_str_asciicompat_p(str) rb_enc_asciicompat(rb_enc_get(str))
258 VALUE rb_enc_from_encoding(rb_encoding *enc);
259 PUREFUNC(int rb_enc_unicode_p(rb_encoding *enc));
260 rb_encoding *rb_ascii8bit_encoding(void);
261 rb_encoding *rb_utf8_encoding(void);
262 rb_encoding *rb_usascii_encoding(void);
263 rb_encoding *rb_locale_encoding(void);
264 rb_encoding *rb_filesystem_encoding(void);
265 rb_encoding *rb_default_external_encoding(void);
266 rb_encoding *rb_default_internal_encoding(void);
267 #ifndef rb_ascii8bit_encindex
268 CONSTFUNC(int rb_ascii8bit_encindex(void));
269 #endif
270 #ifndef rb_utf8_encindex
271 CONSTFUNC(int rb_utf8_encindex(void));
272 #endif
273 #ifndef rb_usascii_encindex
274 CONSTFUNC(int rb_usascii_encindex(void));
275 #endif
276 int rb_locale_encindex(void);
277 int rb_filesystem_encindex(void);
278 VALUE rb_enc_default_external(void);
279 VALUE rb_enc_default_internal(void);
280 void rb_enc_set_default_external(VALUE encoding);
281 void rb_enc_set_default_internal(VALUE encoding);
282 VALUE rb_locale_charmap(VALUE klass);
283 long rb_memsearch(const void*,long,const void*,long,rb_encoding*);
284 char *rb_enc_path_next(const char *,const char *,rb_encoding*);
285 char *rb_enc_path_skip_prefix(const char *,const char *,rb_encoding*);
286 char *rb_enc_path_last_separator(const char *,const char *,rb_encoding*);
287 char *rb_enc_path_end(const char *,const char *,rb_encoding*);
288 const char *ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc);
289 const char *ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc);
290 ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc);
291 VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc);
292
293 RUBY_EXTERN VALUE rb_cEncoding;
294
295 /* econv stuff */
296
297 typedef enum {
298 econv_invalid_byte_sequence,
299 econv_undefined_conversion,
300 econv_destination_buffer_full,
301 econv_source_buffer_empty,
302 econv_finished,
303 econv_after_output,
304 econv_incomplete_input
305 } rb_econv_result_t;
306
307 typedef struct rb_econv_t rb_econv_t;
308
309 VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts);
310 int rb_econv_has_convpath_p(const char* from_encoding, const char* to_encoding);
311
312 int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags);
313 int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts);
314
315 rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags);
316 rb_econv_t *rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts);
317
318 rb_econv_result_t rb_econv_convert(rb_econv_t *ec,
319 const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end,
320 unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end,
321 int flags);
322 void rb_econv_close(rb_econv_t *ec);
323
324 /* result: 0:success -1:failure */
325 int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname);
326
327 /* result: 0:success -1:failure */
328 int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name);
329 int rb_econv_decorate_at_last(rb_econv_t *ec, const char *decorator_name);
330
331 VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags);
332
333 /* result: 0:success -1:failure */
334 int rb_econv_insert_output(rb_econv_t *ec,
335 const unsigned char *str, size_t len, const char *str_encoding);
336
337 /* encoding that rb_econv_insert_output doesn't need conversion */
338 const char *rb_econv_encoding_to_insert_output(rb_econv_t *ec);
339
340 /* raise an error if the last rb_econv_convert is error */
341 void rb_econv_check_error(rb_econv_t *ec);
342
343 /* returns an exception object or nil */
344 VALUE rb_econv_make_exception(rb_econv_t *ec);
345
346 int rb_econv_putbackable(rb_econv_t *ec);
347 void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n);
348
349 /* returns the corresponding ASCII compatible encoding for encname,
350 * or NULL if encname is not ASCII incompatible encoding. */
351 const char *rb_econv_asciicompat_encoding(const char *encname);
352
353 VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags);
354 VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags);
355 VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags);
356 VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags);
357 VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags);
358
359 void rb_econv_binmode(rb_econv_t *ec);
360
361 enum ruby_econv_flag_type {
362 /* flags for rb_econv_open */
363 RUBY_ECONV_ERROR_HANDLER_MASK = 0x000000ff,
364
365 RUBY_ECONV_INVALID_MASK = 0x0000000f,
366 RUBY_ECONV_INVALID_REPLACE = 0x00000002,
367
368 RUBY_ECONV_UNDEF_MASK = 0x000000f0,
369 RUBY_ECONV_UNDEF_REPLACE = 0x00000020,
370 RUBY_ECONV_UNDEF_HEX_CHARREF = 0x00000030,
371
372 RUBY_ECONV_DECORATOR_MASK = 0x0000ff00,
373 RUBY_ECONV_NEWLINE_DECORATOR_MASK = 0x00003f00,
374 RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK = 0x00000f00,
375 RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK = 0x00003000,
376
377 RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR = 0x00000100,
378 RUBY_ECONV_CRLF_NEWLINE_DECORATOR = 0x00001000,
379 RUBY_ECONV_CR_NEWLINE_DECORATOR = 0x00002000,
380 RUBY_ECONV_XML_TEXT_DECORATOR = 0x00004000,
381 RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR = 0x00008000,
382
383 RUBY_ECONV_STATEFUL_DECORATOR_MASK = 0x00f00000,
384 RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR = 0x00100000,
385
386 RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR =
387 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
388 RUBY_ECONV_CRLF_NEWLINE_DECORATOR,
389 #else
390 0,
391 #endif
392 #define ECONV_ERROR_HANDLER_MASK RUBY_ECONV_ERROR_HANDLER_MASK
393 #define ECONV_INVALID_MASK RUBY_ECONV_INVALID_MASK
394 #define ECONV_INVALID_REPLACE RUBY_ECONV_INVALID_REPLACE
395 #define ECONV_UNDEF_MASK RUBY_ECONV_UNDEF_MASK
396 #define ECONV_UNDEF_REPLACE RUBY_ECONV_UNDEF_REPLACE
397 #define ECONV_UNDEF_HEX_CHARREF RUBY_ECONV_UNDEF_HEX_CHARREF
398 #define ECONV_DECORATOR_MASK RUBY_ECONV_DECORATOR_MASK
399 #define ECONV_NEWLINE_DECORATOR_MASK RUBY_ECONV_NEWLINE_DECORATOR_MASK
400 #define ECONV_NEWLINE_DECORATOR_READ_MASK RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK
401 #define ECONV_NEWLINE_DECORATOR_WRITE_MASK RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK
402 #define ECONV_UNIVERSAL_NEWLINE_DECORATOR RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR
403 #define ECONV_CRLF_NEWLINE_DECORATOR RUBY_ECONV_CRLF_NEWLINE_DECORATOR
404 #define ECONV_CR_NEWLINE_DECORATOR RUBY_ECONV_CR_NEWLINE_DECORATOR
405 #define ECONV_XML_TEXT_DECORATOR RUBY_ECONV_XML_TEXT_DECORATOR
406 #define ECONV_XML_ATTR_CONTENT_DECORATOR RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR
407 #define ECONV_STATEFUL_DECORATOR_MASK RUBY_ECONV_STATEFUL_DECORATOR_MASK
408 #define ECONV_XML_ATTR_QUOTE_DECORATOR RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR
409 #define ECONV_DEFAULT_NEWLINE_DECORATOR RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR
410 /* end of flags for rb_econv_open */
411
412 /* flags for rb_econv_convert */
413 RUBY_ECONV_PARTIAL_INPUT = 0x00010000,
414 RUBY_ECONV_AFTER_OUTPUT = 0x00020000,
415 #define ECONV_PARTIAL_INPUT RUBY_ECONV_PARTIAL_INPUT
416 #define ECONV_AFTER_OUTPUT RUBY_ECONV_AFTER_OUTPUT
417 /* end of flags for rb_econv_convert */
418 RUBY_ECONV_FLAGS_PLACEHOLDER};
419
420 RUBY_SYMBOL_EXPORT_END
421
422 #if defined(__cplusplus)
423 #if 0
424 { /* satisfy cc-mode */
425 #endif
426 } /* extern "C" { */
427 #endif
428
429 #endif /* RUBY_ENCODING_H */
rb_econv_asciicompat_encoding
const char * rb_econv_asciicompat_encoding(const char *encname)
Definition: transcode.c:1768
RUBY_ECONV_DECORATOR_MASK
@ RUBY_ECONV_DECORATOR_MASK
Definition: encoding.h:372
rb_enc_capable
int rb_enc_capable(VALUE obj)
Definition: encoding.c:753
ID
unsigned long ID
Definition: ruby.h:103
rb_enc_path_next
char * rb_enc_path_next(const char *, const char *, rb_encoding *)
Definition: file.c:3358
RUBY_SYMBOL_EXPORT_END
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
rb_econv_prepare_options
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags)
Definition: transcode.c:2509
econv_source_buffer_empty
@ econv_source_buffer_empty
Definition: encoding.h:301
rb_econv_substr_append
VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags)
Definition: transcode.c:1838
rb_econv_decorate_at_last
int rb_econv_decorate_at_last(rb_econv_t *ec, const char *decorator_name)
Definition: transcode.c:1907
rb_econv_substr_convert
VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags)
Definition: transcode.c:1853
rb_enc_unicode_p
int rb_enc_unicode_p(rb_encoding *enc)
Definition: encoding.c:521
ruby_enc_find_basename
const char * ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc)
Definition: file.c:4502
rb_enc_str_buf_cat
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
Definition: string.c:2919
rb_enc_default_external
VALUE rb_enc_default_external(void)
Definition: encoding.c:1441
rb_enc_get
rb_encoding * rb_enc_get(VALUE)
Definition: encoding.c:872
CONSTFUNC
CONSTFUNC(int rb_enc_toupper(int c, rb_encoding *enc))
rb_econv_encoding_to_insert_output
const char * rb_econv_encoding_to_insert_output(rb_econv_t *ec)
Definition: transcode.c:1485
RUBY_ENCODING_MASK
@ RUBY_ENCODING_MASK
Definition: encoding.h:44
rb_enc_codepoint
#define rb_enc_codepoint(p, e, enc)
Definition: encoding.h:207
RUBY_ENC_CODERANGE_7BIT
@ RUBY_ENC_CODERANGE_7BIT
Definition: encoding.h:68
RUBY_FL_USHIFT
@ RUBY_FL_USHIFT
Definition: ruby.h:853
rb_enc_strlen
long rb_enc_strlen(const char *, const char *, rb_encoding *)
Definition: string.c:1740
rb_char_to_option_kcode
int rb_char_to_option_kcode(int c, int *option, int *kcode)
Definition: re.c:319
RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR
@ RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR
Definition: encoding.h:381
rb_enc_uint_chr
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
Definition: numeric.c:3375
rb_econv_str_convert
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
Definition: transcode.c:1859
NORETURN
#define NORETURN(x)
Definition: defines.h:528
rb_utf8_encindex
int rb_utf8_encindex(void)
Definition: encoding.c:1334
RUBY_ECONV_STATEFUL_DECORATOR_MASK
@ RUBY_ECONV_STATEFUL_DECORATOR_MASK
Definition: encoding.h:383
rb_enc_sprintf
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
Definition: sprintf.c:1178
rb_enc_set_default_internal
void rb_enc_set_default_internal(VALUE encoding)
Definition: encoding.c:1563
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_str_export_to_enc
VALUE rb_str_export_to_enc(VALUE, rb_encoding *)
Definition: string.c:1135
rb_enc_vsprintf
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
Definition: sprintf.c:1145
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
RUBY_ECONV_UNDEF_MASK
@ RUBY_ECONV_UNDEF_MASK
Definition: encoding.h:368
alias
const char * alias
Definition: nkf.c:1159
rb_enc_default_internal
VALUE rb_enc_default_internal(void)
Definition: encoding.c:1521
RUBY_ECONV_INVALID_REPLACE
@ RUBY_ECONV_INVALID_REPLACE
Definition: encoding.h:366
rb_intern3
ID rb_intern3(const char *, long, rb_encoding *)
Definition: symbol.c:603
rb_enc_precise_mbclen
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
Definition: encoding.c:1032
RUBY_ENCODING_SHIFT
@ RUBY_ENCODING_SHIFT
Definition: encoding.h:43
rb_econv_t
Definition: transcode.c:110
econv_after_output
@ econv_after_output
Definition: encoding.h:303
rb_enc_associate
VALUE rb_enc_associate(VALUE, rb_encoding *)
Definition: encoding.c:866
rb_enc_dummy_p
int rb_enc_dummy_p(rb_encoding *enc)
Definition: encoding.c:131
rb_econv_convert
rb_econv_result_t rb_econv_convert(rb_econv_t *ec, const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end, unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end, int flags)
Definition: transcode.c:1428
ptr
struct RIMemo * ptr
Definition: debug.c:74
RUBY_ECONV_UNDEF_HEX_CHARREF
@ RUBY_ECONV_UNDEF_HEX_CHARREF
Definition: encoding.h:370
PRINTF_ARGS
PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char *,...), 2, 3)
RUBY_ECONV_AFTER_OUTPUT
@ RUBY_ECONV_AFTER_OUTPUT
Definition: encoding.h:414
rb_enc_from_encoding
VALUE rb_enc_from_encoding(rb_encoding *enc)
Definition: encoding.c:116
rb_econv_str_append
VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags)
Definition: transcode.c:1847
rb_filesystem_encoding
rb_encoding * rb_filesystem_encoding(void)
Definition: encoding.c:1387
RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR
@ RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR
Definition: encoding.h:384
rb_locale_encoding
rb_encoding * rb_locale_encoding(void)
Definition: encoding.c:1372
rb_enc_set_index
void rb_enc_set_index(VALUE obj, int encindex)
Definition: encoding.c:830
RUBY_ENCODING_MAXNAMELEN
@ RUBY_ENCODING_MAXNAMELEN
Definition: encoding.h:46
ruby.h
rb_ascii8bit_encindex
int rb_ascii8bit_encindex(void)
Definition: encoding.c:1322
rb_check_symbol_cstr
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
Definition: symbol.c:999
RUBY_ENC_CODERANGE_VALID
@ RUBY_ENC_CODERANGE_VALID
Definition: encoding.h:69
rb_memsearch
long rb_memsearch(const void *, long, const void *, long, rb_encoding *)
Definition: re.c:239
rb_econv_check_error
void rb_econv_check_error(rb_econv_t *ec)
Definition: transcode.c:4223
rb_enc_str_new_cstr
VALUE rb_enc_str_new_cstr(const char *, rb_encoding *)
Definition: string.c:836
rb_ascii8bit_encoding
rb_encoding * rb_ascii8bit_encoding(void)
Definition: encoding.c:1316
RUBY_ECONV_CRLF_NEWLINE_DECORATOR
@ RUBY_ECONV_CRLF_NEWLINE_DECORATOR
Definition: encoding.h:378
rb_str_conv_enc_opts
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
Definition: string.c:914
rb_enc_check
rb_encoding * rb_enc_check(VALUE, VALUE)
Definition: encoding.c:891
RUBY_ENC_CODERANGE_MASK
@ RUBY_ENC_CODERANGE_MASK
Definition: encoding.h:71
rb_obj_encoding
VALUE rb_obj_encoding(VALUE)
Definition: encoding.c:1004
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
RUBY_ECONV_XML_TEXT_DECORATOR
@ RUBY_ECONV_XML_TEXT_DECORATOR
Definition: encoding.h:380
rb_enc_str_new_static
VALUE rb_enc_str_new_static(const char *, long, rb_encoding *)
Definition: string.c:890
rb_to_encoding
rb_encoding * rb_to_encoding(VALUE)
Definition: encoding.c:245
rb_define_dummy_encoding
int rb_define_dummy_encoding(const char *)
Definition: encoding.c:462
rb_enc_alias
int rb_enc_alias(const char *alias, const char *orig)
Definition: encoding.c:553
rb_econv_decorate_at_first
int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name)
Definition: transcode.c:1890
rb_econv_open_opts
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
Definition: transcode.c:2560
rb_encoding
const typedef OnigEncodingType rb_encoding
Definition: encoding.h:115
rb_econv_has_convpath_p
int rb_econv_has_convpath_p(const char *from_encoding, const char *to_encoding)
Definition: transcode.c:3166
rb_enc_replicate
int rb_enc_replicate(const char *, rb_encoding *)
Definition: encoding.c:402
RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK
@ RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK
Definition: encoding.h:375
rb_enc_find
rb_encoding * rb_enc_find(const char *name)
Definition: encoding.c:728
OnigEncodingTypeST
Definition: onigmo.h:160
rb_enc_find_index
int rb_enc_find_index(const char *name)
Definition: encoding.c:693
econv_incomplete_input
@ econv_incomplete_input
Definition: encoding.h:304
rb_enc_path_end
char * rb_enc_path_end(const char *, const char *, rb_encoding *)
Definition: file.c:3440
rb_econv_binmode
void rb_econv_binmode(rb_econv_t *ec)
Definition: transcode.c:1924
rb_enc_mbminlen
#define rb_enc_mbminlen(enc)
Definition: encoding.h:180
rb_enc_to_index
int rb_enc_to_index(rb_encoding *enc)
Definition: encoding.c:125
econv_invalid_byte_sequence
@ econv_invalid_byte_sequence
Definition: encoding.h:298
rb_econv_putbackable
int rb_econv_putbackable(rb_econv_t *ec)
Definition: transcode.c:1724
rb_enc_get_index
int rb_enc_get_index(VALUE obj)
Definition: encoding.c:779
rb_econv_open
rb_econv_t * rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags)
Definition: transcode.c:1051
rb_enc_casefold
int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc)
rb_find_encoding
rb_encoding * rb_find_encoding(VALUE)
Definition: encoding.c:252
RUBY_ECONV_NEWLINE_DECORATOR_MASK
@ RUBY_ECONV_NEWLINE_DECORATOR_MASK
Definition: encoding.h:373
RUBY_ENCODING_INLINE_MAX
@ RUBY_ENCODING_INLINE_MAX
Definition: encoding.h:42
ruby_econv_flag_type
ruby_econv_flag_type
Definition: encoding.h:361
rb_econv_putback
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n)
Definition: transcode.c:1735
rb_econv_set_replacement
int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname)
Definition: transcode.c:2180
RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR
@ RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR
Definition: encoding.h:386
rb_enc_path_skip_prefix
char * rb_enc_path_skip_prefix(const char *, const char *, rb_encoding *)
Definition: file.c:3372
rb_econv_close
void rb_econv_close(rb_econv_t *ec)
Definition: transcode.c:1684
rb_locale_charmap
VALUE rb_locale_charmap(VALUE klass)
Definition: localeinit.c:91
src
__inline__ const void *__restrict src
Definition: rb_mjit_min_header-2.7.0.h:2836
RUBY_ECONV_PARTIAL_INPUT
@ RUBY_ECONV_PARTIAL_INPUT
Definition: encoding.h:413
rb_utf8_encoding
rb_encoding * rb_utf8_encoding(void)
Definition: encoding.c:1328
n
const char size_t n
Definition: rb_mjit_min_header-2.7.0.h:5456
rb_usascii_encindex
int rb_usascii_encindex(void)
Definition: encoding.c:1346
rb_enc_mbclen
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
Definition: encoding.c:1020
rb_econv_prepare_opts
int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts)
Definition: transcode.c:2554
rb_enc_str_coderange
int rb_enc_str_coderange(VALUE)
Definition: string.c:657
RUBY_ENC_CODERANGE_UNKNOWN
@ RUBY_ENC_CODERANGE_UNKNOWN
Definition: encoding.h:67
rb_enc_symname2_p
int rb_enc_symname2_p(const char *, long, rb_encoding *)
Definition: symbol.c:339
RUBY_ENC_CODERANGE_BROKEN
@ RUBY_ENC_CODERANGE_BROKEN
Definition: encoding.h:70
rb_enc_from_index
rb_encoding * rb_enc_from_index(int idx)
Definition: encoding.c:609
RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR
@ RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR
Definition: encoding.h:377
RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
rb_enc_copy
void rb_enc_copy(VALUE dst, VALUE src)
Definition: encoding.c:990
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.0.h:13254
rb_enc_compatible
rb_encoding * rb_enc_compatible(VALUE, VALUE)
Definition: encoding.c:974
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_enc_codelen
int rb_enc_codelen(int code, rb_encoding *enc)
Definition: encoding.c:1089
rb_default_internal_encoding
rb_encoding * rb_default_internal_encoding(void)
Definition: encoding.c:1512
RUBY_ECONV_FLAGS_PLACEHOLDER
@ RUBY_ECONV_FLAGS_PLACEHOLDER
Definition: encoding.h:418
econv_finished
@ econv_finished
Definition: encoding.h:302
rb_econv_insert_output
int rb_econv_insert_output(rb_econv_t *ec, const unsigned char *str, size_t len, const char *str_encoding)
Definition: transcode.c:1569
oniguruma.h
rb_econv_t::flags
int flags
Definition: transcode.c:111
RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK
@ RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK
Definition: encoding.h:374
rb_enc_raise
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
Definition: error.c:2650
rb_filesystem_encindex
int rb_filesystem_encindex(void)
Definition: encoding.c:1378
rb_check_id_cstr
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
Definition: symbol.c:988
rb_external_str_new_with_enc
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *)
Definition: string.c:1036
econv_undefined_conversion
@ econv_undefined_conversion
Definition: encoding.h:299
rb_interned_id_p
ID rb_interned_id_p(const char *, long, rb_encoding *)
rb_enc_nth
char * rb_enc_nth(const char *, const char *, long, rb_encoding *)
Definition: string.c:2388
rb_enc_toupper
int rb_enc_toupper(int c, rb_encoding *enc)
Definition: encoding.c:1106
RUBY_EXTERN
#define RUBY_EXTERN
Definition: missing.h:77
ruby_coderange_type
ruby_coderange_type
Definition: encoding.h:66
econv_destination_buffer_full
@ econv_destination_buffer_full
Definition: encoding.h:300
RUBY_ECONV_UNDEF_REPLACE
@ RUBY_ECONV_UNDEF_REPLACE
Definition: encoding.h:369
rb_enc_symname_p
int rb_enc_symname_p(const char *, rb_encoding *)
Definition: symbol.c:188
rb_enc_set_default_external
void rb_enc_set_default_external(VALUE encoding)
Definition: encoding.c:1479
len
uint8_t len
Definition: escape.c:17
rb_enc_fast_mbclen
int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc)
Definition: encoding.c:1014
rb_enc_reg_new
VALUE rb_enc_reg_new(const char *, long, rb_encoding *, int)
Definition: re.c:2932
rb_enc_path_last_separator
char * rb_enc_path_last_separator(const char *, const char *, rb_encoding *)
Definition: file.c:3406
va_list
__gnuc_va_list va_list
Definition: rb_mjit_min_header-2.7.0.h:836
rb_econv_append
VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags)
Definition: transcode.c:1795
rb_str_encode
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
Definition: transcode.c:2869
rb_to_encoding_index
int rb_to_encoding_index(VALUE)
Definition: encoding.c:197
ruby_encoding_consts
ruby_encoding_consts
Definition: encoding.h:32
RUBY_ECONV_ERROR_HANDLER_MASK
@ RUBY_ECONV_ERROR_HANDLER_MASK
Definition: encoding.h:363
rb_enc_codepoint_len
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_encoding *enc)
Definition: encoding.c:1068
rb_enc_associate_index
VALUE rb_enc_associate_index(VALUE, int)
Definition: encoding.c:838
RUBY_ECONV_INVALID_MASK
@ RUBY_ECONV_INVALID_MASK
Definition: encoding.h:365
rb_enc_str_asciionly_p
int rb_enc_str_asciionly_p(VALUE)
Definition: string.c:678
rb_enc_tolower
int rb_enc_tolower(int c, rb_encoding *enc)
Definition: encoding.c:1112
rb_cEncoding
RUBY_EXTERN VALUE rb_cEncoding
Definition: encoding.h:293
rb_econv_make_exception
VALUE rb_econv_make_exception(rb_econv_t *ec)
Definition: transcode.c:4217
rb_default_external_encoding
rb_encoding * rb_default_external_encoding(void)
Definition: encoding.c:1427
rb_str_coderange_scan_restartable
long rb_str_coderange_scan_restartable(const char *, const char *, rb_encoding *, int *)
Definition: string.c:567
rb_econv_t::destination_encoding
const char * destination_encoding
Definition: transcode.c:137
rb_usascii_encoding
rb_encoding * rb_usascii_encoding(void)
Definition: encoding.c:1340
rb_str_conv_enc
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
Definition: string.c:1030
rb_econv_t::source_encoding
const char * source_encoding
Definition: transcode.c:136
PUREFUNC
PUREFUNC(int rb_enc_dummy_p(rb_encoding *enc))
rb_enc_str_new
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
Definition: string.c:796
rb_enc_code_to_mbclen
#define rb_enc_code_to_mbclen(c, enc)
Definition: encoding.h:214
RUBY_ECONV_CR_NEWLINE_DECORATOR
@ RUBY_ECONV_CR_NEWLINE_DECORATOR
Definition: encoding.h:379
rb_econv_result_t
rb_econv_result_t
Definition: encoding.h:297
rb_locale_encindex
int rb_locale_encindex(void)
Definition: encoding.c:1354
rb_enc_ascget
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
Definition: encoding.c:1044
ruby_enc_find_extname
const char * ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc)
Definition: file.c:4699
name
const char * name
Definition: nkf.c:208
rb_econv_open_exc
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags)
Definition: transcode.c:2018