Ruby
2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
|
Go to the documentation of this file.
12 #ifndef RUBY_ENCODING_H
13 #define RUBY_ENCODING_H 1
15 #ifdef RUBY_INTERNAL_H
16 #error "Include this file before internal.h"
19 #if defined(__cplusplus)
40 #define ENCODING_INLINE_MAX RUBY_ENCODING_INLINE_MAX
41 #define ENCODING_SHIFT RUBY_ENCODING_SHIFT
42 #define ENCODING_MASK RUBY_ENCODING_MASK
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;\
48 #define RB_ENCODING_SET(obj,i) rb_enc_set_index((obj), (i))
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))
57 #define RB_ENCODING_IS_ASCII8BIT(obj) (RB_ENCODING_GET_INLINED(obj) == 0)
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
77 rb_enc_coderange_clean_p(
int cr)
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)
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))
95 #define RB_ENCODING_CODERANGE_SET(obj, encindex, cr) \
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)); \
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)
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)) \
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)) \
177 #define rb_enc_name(enc) (enc)->name
180 #define rb_enc_mbminlen(enc) (enc)->min_enc_len
181 #define rb_enc_mbmaxlen(enc) (enc)->max_enc_len
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)
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))
214 #define rb_enc_code_to_mbclen(c, enc) ONIGENC_CODE_TO_MBCLEN((enc), (c));
217 #define rb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC((enc),(c),(UChar*)(buf))
220 #define rb_enc_prev_char(s,p,e,enc) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
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)))
227 #define rb_enc_is_newline(p,end,enc) ONIGENC_IS_MBC_NEWLINE((enc),(UChar*)(p),(UChar*)(end))
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))
245 #define rb_enc_asciicompat(enc) rb_enc_asciicompat_inline(enc)
257 #define rb_enc_str_asciicompat_p(str) rb_enc_asciicompat(rb_enc_get(str))
267 #ifndef rb_ascii8bit_encindex
270 #ifndef rb_utf8_encindex
273 #ifndef rb_usascii_encindex
319 const unsigned char **source_buffer_ptr,
const unsigned char *source_buffer_end,
320 unsigned char **destination_buffer_ptr,
unsigned char *destination_buffer_end,
335 const unsigned char *
str,
size_t len,
const char *str_encoding);
387 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
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
415 #define ECONV_PARTIAL_INPUT RUBY_ECONV_PARTIAL_INPUT
416 #define ECONV_AFTER_OUTPUT RUBY_ECONV_AFTER_OUTPUT
422 #if defined(__cplusplus)
const char * rb_econv_asciicompat_encoding(const char *encname)
@ RUBY_ECONV_DECORATOR_MASK
int rb_enc_capable(VALUE obj)
char * rb_enc_path_next(const char *, const char *, rb_encoding *)
#define RUBY_SYMBOL_EXPORT_END
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags)
@ econv_source_buffer_empty
VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags)
int rb_econv_decorate_at_last(rb_econv_t *ec, const char *decorator_name)
VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags)
int rb_enc_unicode_p(rb_encoding *enc)
const char * ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc)
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
VALUE rb_enc_default_external(void)
rb_encoding * rb_enc_get(VALUE)
CONSTFUNC(int rb_enc_toupper(int c, rb_encoding *enc))
const char * rb_econv_encoding_to_insert_output(rb_econv_t *ec)
#define rb_enc_codepoint(p, e, enc)
@ RUBY_ENC_CODERANGE_7BIT
long rb_enc_strlen(const char *, const char *, rb_encoding *)
int rb_char_to_option_kcode(int c, int *option, int *kcode)
@ RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
int rb_utf8_encindex(void)
@ RUBY_ECONV_STATEFUL_DECORATOR_MASK
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
void rb_enc_set_default_internal(VALUE encoding)
VALUE rb_str_export_to_enc(VALUE, rb_encoding *)
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
VALUE rb_enc_default_internal(void)
@ RUBY_ECONV_INVALID_REPLACE
ID rb_intern3(const char *, long, rb_encoding *)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
VALUE rb_enc_associate(VALUE, rb_encoding *)
int rb_enc_dummy_p(rb_encoding *enc)
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)
@ RUBY_ECONV_UNDEF_HEX_CHARREF
PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char *,...), 2, 3)
@ RUBY_ECONV_AFTER_OUTPUT
VALUE rb_enc_from_encoding(rb_encoding *enc)
VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags)
rb_encoding * rb_filesystem_encoding(void)
@ RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR
rb_encoding * rb_locale_encoding(void)
void rb_enc_set_index(VALUE obj, int encindex)
@ RUBY_ENCODING_MAXNAMELEN
int rb_ascii8bit_encindex(void)
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
@ RUBY_ENC_CODERANGE_VALID
long rb_memsearch(const void *, long, const void *, long, rb_encoding *)
void rb_econv_check_error(rb_econv_t *ec)
VALUE rb_enc_str_new_cstr(const char *, rb_encoding *)
rb_encoding * rb_ascii8bit_encoding(void)
@ RUBY_ECONV_CRLF_NEWLINE_DECORATOR
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
rb_encoding * rb_enc_check(VALUE, VALUE)
@ RUBY_ENC_CODERANGE_MASK
VALUE rb_obj_encoding(VALUE)
@ RUBY_ECONV_XML_TEXT_DECORATOR
VALUE rb_enc_str_new_static(const char *, long, rb_encoding *)
rb_encoding * rb_to_encoding(VALUE)
int rb_define_dummy_encoding(const char *)
int rb_enc_alias(const char *alias, const char *orig)
int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name)
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
const typedef OnigEncodingType rb_encoding
int rb_econv_has_convpath_p(const char *from_encoding, const char *to_encoding)
int rb_enc_replicate(const char *, rb_encoding *)
@ RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK
rb_encoding * rb_enc_find(const char *name)
int rb_enc_find_index(const char *name)
char * rb_enc_path_end(const char *, const char *, rb_encoding *)
void rb_econv_binmode(rb_econv_t *ec)
#define rb_enc_mbminlen(enc)
int rb_enc_to_index(rb_encoding *enc)
@ econv_invalid_byte_sequence
int rb_econv_putbackable(rb_econv_t *ec)
int rb_enc_get_index(VALUE obj)
rb_econv_t * rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags)
int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc)
rb_encoding * rb_find_encoding(VALUE)
@ RUBY_ECONV_NEWLINE_DECORATOR_MASK
@ RUBY_ENCODING_INLINE_MAX
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n)
int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname)
@ RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR
char * rb_enc_path_skip_prefix(const char *, const char *, rb_encoding *)
void rb_econv_close(rb_econv_t *ec)
VALUE rb_locale_charmap(VALUE klass)
@ RUBY_ECONV_PARTIAL_INPUT
rb_encoding * rb_utf8_encoding(void)
int rb_usascii_encindex(void)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts)
int rb_enc_str_coderange(VALUE)
@ RUBY_ENC_CODERANGE_UNKNOWN
int rb_enc_symname2_p(const char *, long, rb_encoding *)
@ RUBY_ENC_CODERANGE_BROKEN
rb_encoding * rb_enc_from_index(int idx)
@ RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR
#define RUBY_SYMBOL_EXPORT_BEGIN
void rb_enc_copy(VALUE dst, VALUE src)
rb_encoding * rb_enc_compatible(VALUE, VALUE)
char str[HTML_ESCAPE_MAX_LEN+1]
int rb_enc_codelen(int code, rb_encoding *enc)
rb_encoding * rb_default_internal_encoding(void)
@ RUBY_ECONV_FLAGS_PLACEHOLDER
int rb_econv_insert_output(rb_econv_t *ec, const unsigned char *str, size_t len, const char *str_encoding)
@ RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
int rb_filesystem_encindex(void)
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *)
@ econv_undefined_conversion
ID rb_interned_id_p(const char *, long, rb_encoding *)
char * rb_enc_nth(const char *, const char *, long, rb_encoding *)
int rb_enc_toupper(int c, rb_encoding *enc)
@ econv_destination_buffer_full
@ RUBY_ECONV_UNDEF_REPLACE
int rb_enc_symname_p(const char *, rb_encoding *)
void rb_enc_set_default_external(VALUE encoding)
int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc)
VALUE rb_enc_reg_new(const char *, long, rb_encoding *, int)
char * rb_enc_path_last_separator(const char *, const char *, rb_encoding *)
VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags)
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
int rb_to_encoding_index(VALUE)
@ RUBY_ECONV_ERROR_HANDLER_MASK
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_encoding *enc)
VALUE rb_enc_associate_index(VALUE, int)
@ RUBY_ECONV_INVALID_MASK
int rb_enc_str_asciionly_p(VALUE)
int rb_enc_tolower(int c, rb_encoding *enc)
RUBY_EXTERN VALUE rb_cEncoding
VALUE rb_econv_make_exception(rb_econv_t *ec)
rb_encoding * rb_default_external_encoding(void)
long rb_str_coderange_scan_restartable(const char *, const char *, rb_encoding *, int *)
const char * destination_encoding
rb_encoding * rb_usascii_encoding(void)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
const char * source_encoding
PUREFUNC(int rb_enc_dummy_p(rb_encoding *enc))
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
#define rb_enc_code_to_mbclen(c, enc)
@ RUBY_ECONV_CR_NEWLINE_DECORATOR
int rb_locale_encindex(void)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
const char * ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc)
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags)