12 #ifndef RUBY_ENCODING_H 13 #define RUBY_ENCODING_H 1 15 #if defined(__cplusplus) 36 #define ENCODING_INLINE_MAX RUBY_ENCODING_INLINE_MAX 37 #define ENCODING_SHIFT RUBY_ENCODING_SHIFT 38 #define ENCODING_MASK RUBY_ENCODING_MASK 40 #define RB_ENCODING_SET_INLINED(obj,i) do {\ 41 RBASIC(obj)->flags &= ~RUBY_ENCODING_MASK;\ 42 RBASIC(obj)->flags |= (VALUE)(i) << RUBY_ENCODING_SHIFT;\ 44 #define RB_ENCODING_SET(obj,i) rb_enc_set_index((obj), (i)) 46 #define RB_ENCODING_GET_INLINED(obj) \ 47 (int)((RBASIC(obj)->flags & RUBY_ENCODING_MASK)>>RUBY_ENCODING_SHIFT) 48 #define RB_ENCODING_GET(obj) \ 49 (RB_ENCODING_GET_INLINED(obj) != RUBY_ENCODING_INLINE_MAX ? \ 50 RB_ENCODING_GET_INLINED(obj) : \ 51 rb_enc_get_index(obj)) 53 #define RB_ENCODING_IS_ASCII8BIT(obj) (RB_ENCODING_GET_INLINED(obj) == 0) 55 #define ENCODING_SET_INLINED(obj,i) RB_ENCODING_SET_INLINED(obj,i) 56 #define ENCODING_SET(obj,i) RB_ENCODING_SET(obj,i) 57 #define ENCODING_GET_INLINED(obj) RB_ENCODING_GET_INLINED(obj) 58 #define ENCODING_GET(obj) RB_ENCODING_GET(obj) 59 #define ENCODING_IS_ASCII8BIT(obj) RB_ENCODING_IS_ASCII8BIT(obj) 60 #define ENCODING_MAXNAMELEN RUBY_ENCODING_MAXNAMELEN 73 rb_enc_coderange_clean_p(
int cr)
77 #define RB_ENC_CODERANGE_CLEAN_P(cr) rb_enc_coderange_clean_p(cr) 78 #define RB_ENC_CODERANGE(obj) ((int)RBASIC(obj)->flags & RUBY_ENC_CODERANGE_MASK) 79 #define RB_ENC_CODERANGE_ASCIIONLY(obj) (RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT) 80 #define RB_ENC_CODERANGE_SET(obj,cr) (\ 81 RBASIC(obj)->flags = \ 82 (RBASIC(obj)->flags & ~RUBY_ENC_CODERANGE_MASK) | (cr)) 83 #define RB_ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_SET((obj),0) 86 #define RB_ENC_CODERANGE_AND(a, b) \ 87 ((a) == RUBY_ENC_CODERANGE_7BIT ? (b) : \ 88 (a) != RUBY_ENC_CODERANGE_VALID ? RUBY_ENC_CODERANGE_UNKNOWN : \ 89 (b) == RUBY_ENC_CODERANGE_7BIT ? RUBY_ENC_CODERANGE_VALID : (b)) 91 #define RB_ENCODING_CODERANGE_SET(obj, encindex, cr) \ 93 VALUE rb_encoding_coderange_obj = (obj); \ 94 RB_ENCODING_SET(rb_encoding_coderange_obj, (encindex)); \ 95 RB_ENC_CODERANGE_SET(rb_encoding_coderange_obj, (cr)); \ 98 #define ENC_CODERANGE_MASK RUBY_ENC_CODERANGE_MASK 99 #define ENC_CODERANGE_UNKNOWN RUBY_ENC_CODERANGE_UNKNOWN 100 #define ENC_CODERANGE_7BIT RUBY_ENC_CODERANGE_7BIT 101 #define ENC_CODERANGE_VALID RUBY_ENC_CODERANGE_VALID 102 #define ENC_CODERANGE_BROKEN RUBY_ENC_CODERANGE_BROKEN 103 #define ENC_CODERANGE_CLEAN_P(cr) RB_ENC_CODERANGE_CLEAN_P(cr) 104 #define ENC_CODERANGE(obj) RB_ENC_CODERANGE(obj) 105 #define ENC_CODERANGE_ASCIIONLY(obj) RB_ENC_CODERANGE_ASCIIONLY(obj) 106 #define ENC_CODERANGE_SET(obj,cr) RB_ENC_CODERANGE_SET(obj,cr) 107 #define ENC_CODERANGE_CLEAR(obj) RB_ENC_CODERANGE_CLEAR(obj) 108 #define ENC_CODERANGE_AND(a, b) RB_ENC_CODERANGE_AND(a, b) 109 #define ENCODING_CODERANGE_SET(obj, encindex, cr) RB_ENCODING_CODERANGE_SET(obj, encindex, cr) 139 char*
rb_enc_nth(
const char*,
const char*,
long, rb_encoding*);
149 #ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P 150 #define rb_enc_str_new(str, len, enc) RB_GNUC_EXTENSION_BLOCK( \ 151 (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ 152 rb_enc_str_new_static((str), (len), (enc)) : \ 153 rb_enc_str_new((str), (len), (enc)) \ 155 #define rb_enc_str_new_cstr(str, enc) RB_GNUC_EXTENSION_BLOCK( \ 156 (__builtin_constant_p(str)) ? \ 157 rb_enc_str_new_static((str), (long)strlen(str), (enc)) : \ 158 rb_enc_str_new_cstr((str), (enc)) \ 171 #define rb_enc_name(enc) (enc)->name 174 #define rb_enc_mbminlen(enc) (enc)->min_enc_len 175 #define rb_enc_mbmaxlen(enc) (enc)->max_enc_len 178 int rb_enc_mbclen(
const char *p,
const char *e, rb_encoding *enc);
185 #define MBCLEN_CHARFOUND_P(ret) ONIGENC_MBCLEN_CHARFOUND_P(ret) 186 #define MBCLEN_CHARFOUND_LEN(ret) ONIGENC_MBCLEN_CHARFOUND_LEN(ret) 187 #define MBCLEN_INVALID_P(ret) ONIGENC_MBCLEN_INVALID_P(ret) 188 #define MBCLEN_NEEDMORE_P(ret) ONIGENC_MBCLEN_NEEDMORE_P(ret) 189 #define MBCLEN_NEEDMORE_LEN(ret) ONIGENC_MBCLEN_NEEDMORE_LEN(ret) 192 int rb_enc_ascget(
const char *p,
const char *e,
int *
len, rb_encoding *enc);
199 unsigned int rb_enc_codepoint(
const char *p,
const char *e, rb_encoding *enc);
201 #define rb_enc_codepoint(p,e,enc) rb_enc_codepoint_len((p),(e),0,(enc)) 202 #define rb_enc_mbc_to_codepoint(p, e, enc) ONIGENC_MBC_TO_CODE((enc),(UChar*)(p),(UChar*)(e)) 208 #define rb_enc_code_to_mbclen(c, enc) ONIGENC_CODE_TO_MBCLEN((enc), (c)); 211 #define rb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC((enc),(c),(UChar*)(buf)) 214 #define rb_enc_prev_char(s,p,e,enc) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e))) 216 #define rb_enc_left_char_head(s,p,e,enc) ((char *)onigenc_get_left_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e))) 217 #define rb_enc_right_char_head(s,p,e,enc) ((char *)onigenc_get_right_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e))) 218 #define rb_enc_step_back(s,p,e,n,enc) ((char *)onigenc_step_back((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e),(int)(n))) 221 #define rb_enc_is_newline(p,end,enc) ONIGENC_IS_MBC_NEWLINE((enc),(UChar*)(p),(UChar*)(end)) 223 #define rb_enc_isctype(c,t,enc) ONIGENC_IS_CODE_CTYPE((enc),(c),(t)) 224 #define rb_enc_isascii(c,enc) ONIGENC_IS_CODE_ASCII(c) 225 #define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA((enc),(c)) 226 #define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER((enc),(c)) 227 #define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER((enc),(c)) 228 #define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT((enc),(c)) 229 #define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM((enc),(c)) 230 #define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT((enc),(c)) 231 #define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE((enc),(c)) 232 #define rb_enc_isdigit(c,enc) ONIGENC_IS_CODE_DIGIT((enc),(c)) 235 rb_enc_asciicompat_inline(rb_encoding *enc)
239 #define rb_enc_asciicompat(enc) rb_enc_asciicompat_inline(enc) 241 int rb_enc_casefold(
char *to,
const char *p,
const char *e, rb_encoding *enc);
251 #define rb_enc_str_asciicompat_p(str) rb_enc_asciicompat(rb_enc_get(str)) 261 #ifndef rb_ascii8bit_encindex 264 #ifndef rb_utf8_encindex 267 #ifndef rb_usascii_encindex 277 long rb_memsearch(
const void*,
long,
const void*,
long,rb_encoding*);
313 const unsigned char **source_buffer_ptr,
const unsigned char *source_buffer_end,
314 unsigned char **destination_buffer_ptr,
unsigned char *destination_buffer_end,
329 const unsigned char *str,
size_t len,
const char *str_encoding);
381 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32) 386 #define ECONV_ERROR_HANDLER_MASK RUBY_ECONV_ERROR_HANDLER_MASK 387 #define ECONV_INVALID_MASK RUBY_ECONV_INVALID_MASK 388 #define ECONV_INVALID_REPLACE RUBY_ECONV_INVALID_REPLACE 389 #define ECONV_UNDEF_MASK RUBY_ECONV_UNDEF_MASK 390 #define ECONV_UNDEF_REPLACE RUBY_ECONV_UNDEF_REPLACE 391 #define ECONV_UNDEF_HEX_CHARREF RUBY_ECONV_UNDEF_HEX_CHARREF 392 #define ECONV_DECORATOR_MASK RUBY_ECONV_DECORATOR_MASK 393 #define ECONV_NEWLINE_DECORATOR_MASK RUBY_ECONV_NEWLINE_DECORATOR_MASK 394 #define ECONV_NEWLINE_DECORATOR_READ_MASK RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK 395 #define ECONV_NEWLINE_DECORATOR_WRITE_MASK RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK 396 #define ECONV_UNIVERSAL_NEWLINE_DECORATOR RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR 397 #define ECONV_CRLF_NEWLINE_DECORATOR RUBY_ECONV_CRLF_NEWLINE_DECORATOR 398 #define ECONV_CR_NEWLINE_DECORATOR RUBY_ECONV_CR_NEWLINE_DECORATOR 399 #define ECONV_XML_TEXT_DECORATOR RUBY_ECONV_XML_TEXT_DECORATOR 400 #define ECONV_XML_ATTR_CONTENT_DECORATOR RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR 401 #define ECONV_STATEFUL_DECORATOR_MASK RUBY_ECONV_STATEFUL_DECORATOR_MASK 402 #define ECONV_XML_ATTR_QUOTE_DECORATOR RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR 403 #define ECONV_DEFAULT_NEWLINE_DECORATOR RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR 409 #define ECONV_PARTIAL_INPUT RUBY_ECONV_PARTIAL_INPUT 410 #define ECONV_AFTER_OUTPUT RUBY_ECONV_AFTER_OUTPUT 416 #if defined(__cplusplus) int rb_enc_replicate(const char *, rb_encoding *)
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags)
const char * rb_econv_asciicompat_encoding(const char *encname)
PUREFUNC(int rb_enc_dummy_p(rb_encoding *enc))
int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname)
RUBY_EXTERN VALUE rb_cEncoding
long rb_str_coderange_scan_restartable(const char *, const char *, rb_encoding *, int *)
int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc)
rb_econv_t * rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags)
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)
rb_encoding * rb_find_encoding(VALUE)
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
int rb_enc_dummy_p(rb_encoding *enc)
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *)
int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts)
void rb_econv_close(rb_econv_t *ec)
rb_encoding * rb_enc_from_index(int idx)
int rb_enc_tolower(int c, rb_encoding *enc)
int rb_enc_symname2_p(const char *, long, rb_encoding *)
long rb_memsearch(const void *, long, const void *, long, rb_encoding *)
int rb_usascii_encindex(void)
char * rb_enc_path_skip_prefix(const char *, const char *, rb_encoding *)
VALUE rb_locale_charmap(VALUE klass)
int rb_enc_str_coderange(VALUE)
int rb_enc_codelen(int code, rb_encoding *enc)
rb_encoding * rb_enc_get(VALUE)
rb_encoding * rb_utf8_encoding(void)
VALUE rb_obj_encoding(VALUE)
ID rb_interned_id_p(const char *, long, rb_encoding *)
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
void rb_enc_copy(VALUE dst, VALUE src)
void rb_enc_set_default_internal(VALUE encoding)
int rb_define_dummy_encoding(const char *)
void rb_enc_set_index(VALUE obj, int encindex)
int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name)
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
int rb_enc_symname_p(const char *, rb_encoding *)
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
char * rb_enc_nth(const char *, const char *, long, rb_encoding *)
VALUE rb_enc_str_new_static(const char *, long, rb_encoding *)
int rb_enc_toupper(int c, rb_encoding *enc)
ID rb_intern3(const char *, long, rb_encoding *)
VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags)
VALUE rb_econv_make_exception(rb_econv_t *ec)
void rb_econv_check_error(rb_econv_t *ec)
int rb_econv_insert_output(rb_econv_t *ec, const unsigned char *str, size_t len, const char *str_encoding)
int rb_enc_to_index(rb_encoding *enc)
VALUE rb_enc_associate_index(VALUE, int)
int rb_enc_find_index(const char *name)
const char * destination_encoding
rb_encoding * rb_default_external_encoding(void)
rb_encoding * rb_to_encoding(VALUE)
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
int rb_ascii8bit_encindex(void)
int rb_econv_has_convpath_p(const char *from_encoding, const char *to_encoding)
int rb_locale_encindex(void)
rb_encoding * rb_enc_find(const char *name)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
char * rb_enc_path_next(const char *, const char *, rb_encoding *)
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
#define rb_enc_codepoint(p, e, enc)
#define rb_enc_mbminlen(enc)
CONSTFUNC(int rb_enc_toupper(int c, rb_encoding *enc))
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
rb_encoding * rb_usascii_encoding(void)
VALUE rb_enc_default_external(void)
int rb_enc_unicode_p(rb_encoding *enc)
#define RUBY_SYMBOL_EXPORT_END
const char * source_encoding
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
char * rb_enc_path_end(const char *, const char *, rb_encoding *)
VALUE rb_enc_associate(VALUE, rb_encoding *)
int rb_utf8_encindex(void)
#define RUBY_SYMBOL_EXPORT_BEGIN
VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags)
rb_encoding * rb_enc_compatible(VALUE, VALUE)
VALUE rb_enc_from_encoding(rb_encoding *enc)
int rb_char_to_option_kcode(int c, int *option, int *kcode)
register unsigned int len
int rb_econv_putbackable(rb_econv_t *ec)
int rb_enc_get_index(VALUE obj)
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_encoding *enc)
int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc)
long rb_enc_strlen(const char *, const char *, rb_encoding *)
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)
rb_encoding * rb_filesystem_encoding(void)
char * rb_enc_path_last_separator(const char *, const char *, rb_encoding *)
rb_encoding * rb_locale_encoding(void)
int rb_filesystem_encindex(void)
VALUE rb_enc_default_internal(void)
VALUE rb_str_export_to_enc(VALUE, rb_encoding *)
PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char *,...), 2, 3)
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
const OnigEncodingType rb_encoding
rb_encoding * rb_ascii8bit_encoding(void)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
rb_encoding * rb_default_internal_encoding(void)
const char * ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc)
int rb_to_encoding_index(VALUE)
const char * rb_econv_encoding_to_insert_output(rb_econv_t *ec)
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)
void rb_enc_set_default_external(VALUE encoding)
int rb_enc_str_asciionly_p(VALUE)
const char * ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc)
VALUE rb_enc_reg_new(const char *, long, rb_encoding *, int)
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags)
void rb_econv_binmode(rb_econv_t *ec)
VALUE rb_enc_str_new_cstr(const char *, rb_encoding *)
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n)
#define rb_enc_code_to_mbclen(c, enc)
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
rb_encoding * rb_enc_check(VALUE, VALUE)