Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Typedefs | Functions | Variables
encoding.c File Reference
#include "internal.h"
#include "encindex.h"
#include "regenc.h"
#include <ctype.h>
#include "ruby/util.h"
#include "ruby_assert.h"

Go to the source code of this file.

Data Structures

struct  rb_encoding_entry
 
struct  default_encoding
 

Macros

#define ENC_DEBUG   0
 
#define ENC_ASSERT   (!ENC_DEBUG)?(void)0:assert
 
#define MUST_STRING(str)   (ENC_ASSERT(RB_TYPE_P(str, T_STRING)), str)
 
#define ENC_DUMMY_FLAG   (1<<24)
 
#define ENC_INDEX_MASK   (~(~0U<<24))
 
#define ENC_TO_ENCINDEX(enc)   (int)((enc)->ruby_encoding_index & ENC_INDEX_MASK)
 
#define ENC_DUMMY_P(enc)   ((enc)->ruby_encoding_index & ENC_DUMMY_FLAG)
 
#define ENC_SET_DUMMY(enc)   ((enc)->ruby_encoding_index |= ENC_DUMMY_FLAG)
 
#define ENCODING_COUNT   ENCINDEX_BUILTIN_MAX
 
#define UNSPECIFIED_ENCODING   INT_MAX
 
#define ENCODING_NAMELEN_MAX   63
 
#define valid_encoding_name_p(name)   ((name) && strlen(name) <= ENCODING_NAMELEN_MAX)
 
#define enc_autoload_p(enc)   (!rb_enc_mbmaxlen(enc))
 
#define is_data_encoding(obj)   (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj) == &encoding_data_type)
 
#define is_obj_encoding(obj)   (RB_TYPE_P((obj), T_DATA) && is_data_encoding(obj))
 
#define ENC_REGISTER(enc)   enc_register_at(ENCINDEX_##enc, rb_enc_name(&OnigEncoding##enc), &OnigEncoding##enc)
 
#define ENCDB_REGISTER(name, enc)   enc_register_at(ENCINDEX_##enc, name, NULL)
 
#define rb_intern(str)   rb_intern_const(str)
 

Typedefs

typedef OnigEncodingType rb_raw_encoding
 

Functions

void rb_enc_init (void)
 
int rb_data_is_encoding (VALUE obj)
 
VALUE rb_enc_from_encoding (rb_encoding *encoding)
 
int rb_enc_to_index (rb_encoding *enc)
 
int rb_enc_dummy_p (rb_encoding *enc)
 
 NORETURN (static void not_encoding(VALUE enc))
 
int rb_to_encoding_index (VALUE enc)
 
rb_encodingrb_to_encoding (VALUE enc)
 
rb_encodingrb_find_encoding (VALUE enc)
 
void rb_gc_mark_encodings (void)
 
int rb_enc_registered (const char *name)
 
int rb_enc_register (const char *name, rb_encoding *encoding)
 
void rb_encdb_declare (const char *name)
 
void rb_enc_set_base (const char *name, const char *orig)
 
int rb_enc_set_dummy (int index)
 
int rb_enc_replicate (const char *name, rb_encoding *encoding)
 
int rb_encdb_replicate (const char *name, const char *orig)
 
int rb_define_dummy_encoding (const char *name)
 
int rb_encdb_dummy (const char *name)
 
int rb_enc_unicode_p (rb_encoding *enc)
 
int rb_enc_alias (const char *alias, const char *orig)
 
int rb_encdb_alias (const char *alias, const char *orig)
 
void rb_encdb_set_unicode (int index)
 
rb_encodingrb_enc_from_index (int index)
 
rb_encodingrb_enc_get_from_index (int index)
 
int rb_enc_find_index (const char *name)
 
rb_encodingrb_enc_find (const char *name)
 
ID rb_id_encoding (void)
 
int rb_enc_get_index (VALUE obj)
 
void rb_enc_set_index (VALUE obj, int idx)
 
VALUE rb_enc_associate_index (VALUE obj, int idx)
 
VALUE rb_enc_associate (VALUE obj, rb_encoding *enc)
 
rb_encodingrb_enc_get (VALUE obj)
 
rb_encodingrb_enc_check_str (VALUE str1, VALUE str2)
 
rb_encodingrb_enc_check (VALUE str1, VALUE str2)
 
rb_encodingrb_enc_compatible (VALUE str1, VALUE str2)
 
void rb_enc_copy (VALUE obj1, VALUE obj2)
 
VALUE rb_obj_encoding (VALUE obj)
 
int rb_enc_fast_mbclen (const char *p, const char *e, rb_encoding *enc)
 
int rb_enc_mbclen (const char *p, const char *e, rb_encoding *enc)
 
int rb_enc_precise_mbclen (const char *p, const char *e, rb_encoding *enc)
 
int rb_enc_ascget (const char *p, const char *e, int *len, rb_encoding *enc)
 
unsigned int rb_enc_codepoint_len (const char *p, const char *e, int *len_p, rb_encoding *enc)
 
unsigned int rb_enc_codepoint (const char *p, const char *e, rb_encoding *enc)
 
int rb_enc_codelen (int c, rb_encoding *enc)
 
int rb_enc_code_to_mbclen (int code, rb_encoding *enc)
 
int rb_enc_toupper (int c, rb_encoding *enc)
 
int rb_enc_tolower (int c, rb_encoding *enc)
 
rb_encodingrb_ascii8bit_encoding (void)
 
int rb_ascii8bit_encindex (void)
 
rb_encodingrb_utf8_encoding (void)
 
int rb_utf8_encindex (void)
 
rb_encodingrb_usascii_encoding (void)
 
int rb_usascii_encindex (void)
 
int rb_locale_charmap_index (void)
 
int rb_locale_encindex (void)
 
rb_encodingrb_locale_encoding (void)
 
int rb_filesystem_encindex (void)
 
rb_encodingrb_filesystem_encoding (void)
 
rb_encodingrb_default_external_encoding (void)
 
VALUE rb_enc_default_external (void)
 
void rb_enc_set_default_external (VALUE encoding)
 
rb_encodingrb_default_internal_encoding (void)
 
VALUE rb_enc_default_internal (void)
 
void rb_enc_set_default_internal (VALUE encoding)
 
void Init_Encoding (void)
 
void rb_enc_foreach_name (int(*func)(st_data_t name, st_data_t idx, st_data_t arg), st_data_t arg)
 

Variables

VALUE rb_cEncoding
 

Macro Definition Documentation

◆ ENC_ASSERT

#define ENC_ASSERT   (!ENC_DEBUG)?(void)0:assert

Definition at line 22 of file encoding.c.

◆ enc_autoload_p

#define enc_autoload_p (   enc)    (!rb_enc_mbmaxlen(enc))

Definition at line 76 of file encoding.c.

◆ ENC_DEBUG

#define ENC_DEBUG   0

Definition at line 20 of file encoding.c.

◆ ENC_DUMMY_FLAG

#define ENC_DUMMY_FLAG   (1<<24)

Definition at line 61 of file encoding.c.

◆ ENC_DUMMY_P

#define ENC_DUMMY_P (   enc)    ((enc)->ruby_encoding_index & ENC_DUMMY_FLAG)

Definition at line 65 of file encoding.c.

Referenced by rb_enc_dummy_p().

◆ ENC_INDEX_MASK

#define ENC_INDEX_MASK   (~(~0U<<24))

Definition at line 62 of file encoding.c.

◆ ENC_REGISTER

#define ENC_REGISTER (   enc)    enc_register_at(ENCINDEX_##enc, rb_enc_name(&OnigEncoding##enc), &OnigEncoding##enc)

◆ ENC_SET_DUMMY

#define ENC_SET_DUMMY (   enc)    ((enc)->ruby_encoding_index |= ENC_DUMMY_FLAG)

Definition at line 66 of file encoding.c.

◆ ENC_TO_ENCINDEX

#define ENC_TO_ENCINDEX (   enc)    (int)((enc)->ruby_encoding_index & ENC_INDEX_MASK)

Definition at line 64 of file encoding.c.

Referenced by rb_enc_from_encoding(), and rb_enc_to_index().

◆ ENCDB_REGISTER

#define ENCDB_REGISTER (   name,
  enc 
)    enc_register_at(ENCINDEX_##enc, name, NULL)

◆ ENCODING_COUNT

#define ENCODING_COUNT   ENCINDEX_BUILTIN_MAX

Definition at line 70 of file encoding.c.

◆ ENCODING_NAMELEN_MAX

#define ENCODING_NAMELEN_MAX   63

Definition at line 73 of file encoding.c.

◆ is_data_encoding

#define is_data_encoding (   obj)    (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj) == &encoding_data_type)

Definition at line 86 of file encoding.c.

Referenced by rb_data_is_encoding().

◆ is_obj_encoding

#define is_obj_encoding (   obj)    (RB_TYPE_P((obj), T_DATA) && is_data_encoding(obj))

Definition at line 87 of file encoding.c.

◆ MUST_STRING

#define MUST_STRING (   str)    (ENC_ASSERT(RB_TYPE_P(str, T_STRING)), str)

Definition at line 23 of file encoding.c.

◆ rb_intern

#define rb_intern (   str)    rb_intern_const(str)

◆ UNSPECIFIED_ENCODING

#define UNSPECIFIED_ENCODING   INT_MAX

Definition at line 71 of file encoding.c.

◆ valid_encoding_name_p

#define valid_encoding_name_p (   name)    ((name) && strlen(name) <= ENCODING_NAMELEN_MAX)

Definition at line 74 of file encoding.c.

Typedef Documentation

◆ rb_raw_encoding

Definition at line 29 of file encoding.c.

Function Documentation

◆ Init_Encoding()

void Init_Encoding ( void  )

Definition at line 1917 of file encoding.c.

References list, rb_cEncoding, rb_cObject, rb_define_alloc_func(), and rb_define_class().

◆ NORETURN()

NORETURN ( static void   not_encodingVALUE enc)

◆ rb_ascii8bit_encindex()

int rb_ascii8bit_encindex ( void  )

◆ rb_ascii8bit_encoding()

rb_encoding* rb_ascii8bit_encoding ( void  )

◆ rb_data_is_encoding()

int rb_data_is_encoding ( VALUE  obj)

Definition at line 90 of file encoding.c.

References is_data_encoding.

◆ rb_default_external_encoding()

rb_encoding* rb_default_external_encoding ( void  )

◆ rb_default_internal_encoding()

rb_encoding* rb_default_internal_encoding ( void  )

◆ rb_define_dummy_encoding()

int rb_define_dummy_encoding ( const char *  name)

Definition at line 466 of file encoding.c.

References rb_ascii8bit_encoding(), and rb_enc_replicate().

◆ rb_enc_alias()

int rb_enc_alias ( const char *  alias,
const char *  orig 
)

Definition at line 557 of file encoding.c.

◆ rb_enc_ascget()

int rb_enc_ascget ( const char *  p,
const char *  e,
int *  len,
rb_encoding enc 
)

◆ rb_enc_associate()

VALUE rb_enc_associate ( VALUE  obj,
rb_encoding enc 
)

◆ rb_enc_associate_index()

VALUE rb_enc_associate_index ( VALUE  obj,
int  idx 
)

◆ rb_enc_check()

rb_encoding* rb_enc_check ( VALUE  str1,
VALUE  str2 
)

◆ rb_enc_check_str()

rb_encoding* rb_enc_check_str ( VALUE  str1,
VALUE  str2 
)

Definition at line 868 of file encoding.c.

Referenced by rb_str_plus().

◆ rb_enc_code_to_mbclen()

int rb_enc_code_to_mbclen ( int  code,
rb_encoding enc 
)

Definition at line 1088 of file encoding.c.

References ONIGENC_CODE_TO_MBCLEN.

◆ rb_enc_codelen()

int rb_enc_codelen ( int  c,
rb_encoding enc 
)

◆ rb_enc_codepoint()

unsigned int rb_enc_codepoint ( const char *  p,
const char *  e,
rb_encoding enc 
)

Definition at line 1071 of file encoding.c.

References rb_enc_codepoint_len().

◆ rb_enc_codepoint_len()

unsigned int rb_enc_codepoint_len ( const char *  p,
const char *  e,
int *  len_p,
rb_encoding enc 
)

◆ rb_enc_compatible()

rb_encoding* rb_enc_compatible ( VALUE  str1,
VALUE  str2 
)

Definition at line 962 of file encoding.c.

References rb_enc_from_index(), and rb_enc_get_index().

Referenced by rb_enc_check().

◆ rb_enc_copy()

void rb_enc_copy ( VALUE  obj1,
VALUE  obj2 
)

◆ rb_enc_default_external()

VALUE rb_enc_default_external ( void  )

Definition at line 1439 of file encoding.c.

References rb_default_external_encoding(), and rb_enc_from_encoding().

◆ rb_enc_default_internal()

VALUE rb_enc_default_internal ( void  )

Definition at line 1519 of file encoding.c.

References rb_default_internal_encoding(), and rb_enc_from_encoding().

◆ rb_enc_dummy_p()

int rb_enc_dummy_p ( rb_encoding enc)

Definition at line 132 of file encoding.c.

References ENC_DUMMY_P.

Referenced by rb_enc_str_coderange().

◆ rb_enc_fast_mbclen()

int rb_enc_fast_mbclen ( const char *  p,
const char *  e,
rb_encoding enc 
)

Definition at line 1002 of file encoding.c.

References ONIGENC_MBC_ENC_LEN, and UChar.

◆ rb_enc_find()

rb_encoding* rb_enc_find ( const char *  name)

Definition at line 728 of file encoding.c.

References rb_enc_find_index(), and rb_enc_from_index().

◆ rb_enc_find_index()

int rb_enc_find_index ( const char *  name)

◆ rb_enc_foreach_name()

void rb_enc_foreach_name ( int(*)(st_data_t name, st_data_t idx, st_data_t arg)  func,
st_data_t  arg 
)

Definition at line 1964 of file encoding.c.

References st_foreach.

◆ rb_enc_from_encoding()

VALUE rb_enc_from_encoding ( rb_encoding encoding)

◆ rb_enc_from_index()

rb_encoding* rb_enc_from_index ( int  index)

◆ rb_enc_get()

rb_encoding* rb_enc_get ( VALUE  obj)

◆ rb_enc_get_from_index()

rb_encoding* rb_enc_get_from_index ( int  index)

Definition at line 628 of file encoding.c.

◆ rb_enc_get_index()

int rb_enc_get_index ( VALUE  obj)

◆ rb_enc_init()

void rb_enc_init ( void  )

Definition at line 589 of file encoding.c.

◆ rb_enc_mbclen()

int rb_enc_mbclen ( const char *  p,
const char *  e,
rb_encoding enc 
)

◆ rb_enc_precise_mbclen()

int rb_enc_precise_mbclen ( const char *  p,
const char *  e,
rb_encoding enc 
)

◆ rb_enc_register()

int rb_enc_register ( const char *  name,
rb_encoding encoding 
)

Definition at line 333 of file encoding.c.

References rb_enc_from_index(), rb_enc_name, rb_enc_registered(), and STRCASECMP.

◆ rb_enc_registered()

int rb_enc_registered ( const char *  name)

◆ rb_enc_replicate()

int rb_enc_replicate ( const char *  name,
rb_encoding encoding 
)

Definition at line 409 of file encoding.c.

Referenced by rb_define_dummy_encoding().

◆ rb_enc_set_base()

void rb_enc_set_base ( const char *  name,
const char *  orig 
)

Definition at line 389 of file encoding.c.

References rb_enc_registered().

◆ rb_enc_set_default_external()

void rb_enc_set_default_external ( VALUE  encoding)

Definition at line 1477 of file encoding.c.

References NIL_P, rb_eArgError, and rb_raise().

◆ rb_enc_set_default_internal()

void rb_enc_set_default_internal ( VALUE  encoding)

Definition at line 1561 of file encoding.c.

◆ rb_enc_set_dummy()

int rb_enc_set_dummy ( int  index)

Definition at line 400 of file encoding.c.

◆ rb_enc_set_index()

void rb_enc_set_index ( VALUE  obj,
int  idx 
)

Definition at line 818 of file encoding.c.

References rb_check_frozen.

Referenced by rb_str_concat_literals().

◆ rb_enc_to_index()

int rb_enc_to_index ( rb_encoding enc)

◆ rb_enc_tolower()

int rb_enc_tolower ( int  c,
rb_encoding enc 
)

Definition at line 1100 of file encoding.c.

References ONIGENC_ASCII_CODE_TO_LOWER_CASE, and ONIGENC_IS_ASCII_CODE.

◆ rb_enc_toupper()

int rb_enc_toupper ( int  c,
rb_encoding enc 
)

Definition at line 1094 of file encoding.c.

References ONIGENC_ASCII_CODE_TO_UPPER_CASE, and ONIGENC_IS_ASCII_CODE.

◆ rb_enc_unicode_p()

int rb_enc_unicode_p ( rb_encoding enc)

Definition at line 525 of file encoding.c.

References ONIGENC_IS_UNICODE, and st_data_t.

◆ rb_encdb_alias()

int rb_encdb_alias ( const char *  alias,
const char *  orig 
)

Definition at line 572 of file encoding.c.

References rb_enc_registered().

Referenced by Init_enc(), and Init_enc_set_filesystem_encoding().

◆ rb_encdb_declare()

void rb_encdb_declare ( const char *  name)

Definition at line 357 of file encoding.c.

References rb_enc_registered().

Referenced by Init_enc(), and Init_enc_set_filesystem_encoding().

◆ rb_encdb_dummy()

int rb_encdb_dummy ( const char *  name)

Definition at line 476 of file encoding.c.

◆ rb_encdb_replicate()

int rb_encdb_replicate ( const char *  name,
const char *  orig 
)

Definition at line 454 of file encoding.c.

References rb_enc_registered().

◆ rb_encdb_set_unicode()

void rb_encdb_set_unicode ( int  index)

Definition at line 583 of file encoding.c.

References ONIGENC_FLAG_UNICODE, and rb_enc_from_index().

◆ rb_filesystem_encindex()

int rb_filesystem_encindex ( void  )

Definition at line 1376 of file encoding.c.

References ENCINDEX_ASCII, and rb_enc_registered().

Referenced by rb_filesystem_encoding(), and rb_str_encode_ospath().

◆ rb_filesystem_encoding()

rb_encoding* rb_filesystem_encoding ( void  )

◆ rb_find_encoding()

rb_encoding* rb_find_encoding ( VALUE  enc)

Definition at line 253 of file encoding.c.

◆ rb_gc_mark_encodings()

void rb_gc_mark_encodings ( void  )

Definition at line 263 of file encoding.c.

◆ rb_id_encoding()

ID rb_id_encoding ( void  )

Definition at line 753 of file encoding.c.

References CONST_ID.

◆ rb_locale_charmap_index()

int rb_locale_charmap_index ( void  )

Definition at line 108 of file localeinit.c.

References ENCINDEX_US_ASCII.

Referenced by rb_locale_encindex(), and rb_usascii_encindex().

◆ rb_locale_encindex()

int rb_locale_encindex ( void  )

◆ rb_locale_encoding()

rb_encoding* rb_locale_encoding ( void  )

◆ rb_obj_encoding()

VALUE rb_obj_encoding ( VALUE  obj)

Definition at line 992 of file encoding.c.

References rb_enc_get_index(), rb_eTypeError, and rb_raise().

◆ rb_to_encoding()

rb_encoding* rb_to_encoding ( VALUE  enc)

Definition at line 246 of file encoding.c.

◆ rb_to_encoding_index()

int rb_to_encoding_index ( VALUE  enc)

Definition at line 198 of file encoding.c.

◆ rb_usascii_encindex()

int rb_usascii_encindex ( void  )

◆ rb_usascii_encoding()

rb_encoding* rb_usascii_encoding ( void  )

Definition at line 1335 of file encoding.c.

Referenced by rb_intern2(), rb_reg_fragment_setenc(), rb_reg_quote(), and rb_sym_intern_ascii().

◆ rb_utf8_encindex()

int rb_utf8_encindex ( void  )

Definition at line 1329 of file encoding.c.

References ENCINDEX_UTF_8.

Referenced by rb_char_to_option_kcode(), and rb_utf8_str_new_cstr().

◆ rb_utf8_encoding()

rb_encoding* rb_utf8_encoding ( void  )

Definition at line 1320 of file encoding.c.

Referenced by rb_str_encode_ospath().

Variable Documentation

◆ count

int count

Definition at line 56 of file encoding.c.

Referenced by asn1time_to_time(), clock_gettime(), EVENTSINK_Invoke(), and rb_ivar_count().

◆ list

struct rb_encoding_entry* list

◆ names

st_table* names

Definition at line 58 of file encoding.c.

◆ rb_cEncoding

VALUE rb_cEncoding

Definition at line 45 of file encoding.c.

Referenced by Init_Encoding(), and InitVM_transcode().

◆ size

int size