17 #ifndef NO_LOCALE_CHARMAP
21 #ifdef HAVE_LANGINFO_H
27 #if defined __GNUC__ && __GNUC__ >= 4
28 #pragma GCC visibility push(default)
36 #pragma GCC visibility pop
58 #define ENCODING_COUNT ENCINDEX_BUILTIN_MAX
59 #define UNSPECIFIED_ENCODING INT_MAX
61 #define ENCODING_NAMELEN_MAX 63
62 #define valid_encoding_name_p(name) ((name) && strlen(name) <= ENCODING_NAMELEN_MAX)
64 #define enc_autoload_p(enc) (!rb_enc_mbmaxlen(enc))
79 #define is_data_encoding(obj) (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj) == &encoding_data_type)
93 rb_bug(
"rb_enc_from_encoding_index(%d): no rb_encoding_list", idx);
97 rb_bug(
"rb_enc_from_encoding_index(%d): not created yet", idx);
106 if (!encoding)
return Qnil;
206 if (idx < 0)
return NULL;
221 if (
enc_table.size >= newsize)
return newsize;
222 newsize = (newsize + 7) / 8 * 8;
248 *ent->
enc = *encoding;
251 memset(ent->
enc, 0,
sizeof(*ent->
enc));
539 #define ENC_REGISTER(enc) enc_register_at(ENCINDEX_##enc, rb_enc_name(&OnigEncoding##enc), &OnigEncoding##enc)
553 if (index < 0 ||
enc_table.count <= index) {
564 if (!name)
return -1;
604 if (
NIL_P(loaded))
return -1;
620 }
while (
enc_table.list[i].enc != base && (++i, 1));
650 rb_warn(
"failed to load encoding (%s); use ASCII-8BIT instead",
662 if (idx < 0) idx = 0;
716 if (
NIL_P(obj))
break;
798 if (idx1 < 0 || idx2 < 0)
893 return min <= e-p ? min : (int)(e-p);
916 c = (
unsigned char)*p;
946 #undef rb_enc_codepoint
1013 if ((
int)idx == (int)arg[0]) {
1133 if (!enc)
return Qnil;
1223 #if defined NO_LOCALE_CHARMAP
1225 #elif defined _WIN32 || defined __CYGWIN__
1226 char cp[
sizeof(int) * 8 / 3 + 4];
1227 snprintf(cp,
sizeof cp,
"CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
1263 int overridden =
FALSE;
1265 if (def->
index != -2)
1269 if (
NIL_P(encoding)) {
1281 if (def == &default_external)
1290 if (default_external.
enc)
return default_external.
enc;
1292 if (default_external.
index >= 0) {
1294 return default_external.
enc;
1342 if (
NIL_P(encoding)) {
1365 rb_warning(
"setting Encoding.default_external");
1375 if (!default_internal.
enc && default_internal.
index >= 0) {
1378 return default_internal.
enc;
1448 rb_warning(
"setting Encoding.default_internal");
1481 #if defined NO_LOCALE_CHARMAP
1483 #elif defined _WIN32 || defined __CYGWIN__
1484 const char *codeset = 0;
1485 char cp[
sizeof(int) * 3 + 4];
1491 UINT codepage = GetConsoleCP();
1492 if (!codepage) codepage = GetACP();
1493 snprintf(cp,
sizeof(cp),
"CP%d", codepage);
1497 #elif defined HAVE_LANGINFO_H
1499 codeset = nl_langinfo(CODESET);
1510 char *s = (
char *)name;
1511 int haslower = 0, hasupper = 0, valid = 0;
1516 while (*++s && (
ISALNUM(*s) || *s ==
'_')) {
1517 if (
ISLOWER(*s)) haslower = 1;
1525 if (!valid || haslower) {
1526 size_t len = s -
name;
1528 if (!haslower || !hasupper) {
1530 if (
ISLOWER(*s)) haslower = 1;
1531 if (
ISUPPER(*s)) hasupper = 1;
1532 }
while (*++s && (!haslower || !hasupper));
1549 for (s = (
char *)name; *s; ++s) {
1593 VALUE aliases = p[0], ary = p[1];
1594 int idx = (int)orig;
1840 #define rb_intern(str) rb_intern_const(str)
1881 #define ctype_test(c, ctype) \
1882 (rb_isascii(c) && ONIGENC_IS_ASCII_CODE_CTYPE((c), (ctype)))
static void enc_set_index(VALUE obj, int idx)
static int rb_enc_name_list_i(st_data_t name, st_data_t idx, st_data_t arg)
rb_encoding OnigEncodingUS_ASCII
#define ONIGENC_CTYPE_BLANK
#define ONIGENC_CTYPE_PUNCT
int rb_enc_codelen(int c, rb_encoding *enc)
int rb_enc_get_index(VALUE obj)
#define MBCLEN_CHARFOUND_P(ret)
rb_encoding * rb_enc_check(VALUE str1, VALUE str2)
VALUE rb_ary_entry(VALUE ary, long offset)
#define MBCLEN_CHARFOUND_LEN(ret)
void rb_bug(const char *fmt,...)
#define rb_enc_mbc_to_codepoint(p, e, enc)
void rb_enc_copy(VALUE obj1, VALUE obj2)
void rb_enc_set_base(const char *name, const char *orig)
size_t strlen(const char *)
#define ENCODING_CODERANGE_SET(obj, encindex, cr)
static VALUE enc_load(VALUE klass, VALUE str)
void rb_undef_alloc_func(VALUE)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static int rb_enc_aliases_enc_i(st_data_t name, st_data_t orig, st_data_t arg)
static VALUE enc_inspect(VALUE self)
static rb_encoding * set_base_encoding(int index, rb_encoding *base)
static VALUE rb_enc_name_list(VALUE klass)
static VALUE enc_list(VALUE klass)
static int enc_register_at(int index, const char *name, rb_encoding *encoding)
int st_insert(st_table *, st_data_t, st_data_t)
#define TypedData_Wrap_Struct(klass, data_type, sval)
static int str_to_encindex(VALUE enc)
rb_encoding * rb_to_encoding(VALUE enc)
#define ENC_CODERANGE_CLEAR(obj)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
int rb_enc_tolower(int c, rb_encoding *enc)
const char * nl_langinfo_codeset(void)
rb_encoding * rb_default_internal_encoding(void)
VALUE rb_ary_push(VALUE ary, VALUE item)
int rb_usascii_encindex(void)
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
static VALUE enc_names(VALUE self)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
static int enc_table_expand(int newsize)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
#define ENCODING_GET_INLINED(obj)
int rb_enc_str_coderange(VALUE)
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len_p, rb_encoding *enc)
static VALUE enc_new(rb_encoding *encoding)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ivar_get(VALUE, ID)
#define ONIGENC_CTYPE_CNTRL
void rb_enc_set_default_external(VALUE encoding)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
static VALUE rb_enc_aliases(VALUE klass)
static VALUE set_default_external(VALUE klass, VALUE encoding)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
VALUE rb_locale_charmap(VALUE klass)
#define ENC_SET_DUMMY(enc)
#define ENC_REGISTER(enc)
int rb_enc_registered(const char *name)
static int enc_alias_internal(const char *alias, int idx)
#define ONIGENC_CTYPE_ALNUM
int rb_filesystem_encindex(void)
rb_encoding * rb_utf8_encoding(void)
void rb_undef_method(VALUE klass, const char *name)
#define ONIGENC_CTYPE_ALPHA
#define ENC_CODERANGE_7BIT
const char * rb_obj_classname(VALUE)
static VALUE enc_dummy_p(VALUE enc)
static VALUE rb_enc_from_encoding_index(int idx)
int rb_enc_toupper(int c, rb_encoding *enc)
#define ONIGENC_CTYPE_UPPER
int st_insert2(st_table *, st_data_t, st_data_t, st_data_t(*)(st_data_t))
st_table * st_init_strcasetable(void)
#define ctype_test(c, ctype)
#define RB_TYPE_P(obj, type)
void rb_encdb_set_unicode(int index)
int st_lookup(st_table *, st_data_t, st_data_t *)
static struct @4 enc_table
static int str_find_encindex(VALUE enc)
int rb_to_encoding_index(VALUE enc)
rb_encoding * rb_default_external_encoding(void)
#define ONIGENC_CTYPE_DIGIT
#define ONIGENC_MBC_ENC_LEN(enc, p, e)
int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc)
RUBY_EXTERN VALUE rb_cObject
#define ONIGENC_CTYPE_XDIGIT
#define rb_enc_isascii(c, enc)
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_ary_replace(VALUE copy, VALUE orig)
int rb_ascii8bit_encindex(void)
VALUE rb_enc_default_external(void)
static VALUE enc_name(VALUE self)
#define ENC_CODERANGE_ASCIIONLY(obj)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_enc_set_index(VALUE obj, int idx)
int rb_enc_replicate(const char *name, rb_encoding *encoding)
void rb_define_const(VALUE, const char *, VALUE)
void rb_ary_store(VALUE ary, long idx, VALUE val)
static void set_encoding_const(const char *, rb_encoding *)
static VALUE enc_dump(int argc, VALUE *argv, VALUE self)
int rb_encdb_alias(const char *alias, const char *orig)
VALUE rb_require_safe(VALUE, int)
int rb_locale_encindex(void)
#define ALLOCA_N(type, n)
static rb_encoding * str_to_encoding(VALUE enc)
void rb_gc_register_mark_object(VALUE obj)
#define MEMCPY(p1, p2, type, n)
VALUE rb_enc_associate_index(VALUE obj, int idx)
#define rb_enc_mbminlen(enc)
#define ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(n)
#define ONIGENC_CODE_TO_MBCLEN(enc, code)
static int enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const char *name)
rb_encoding * rb_find_encoding(VALUE enc)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
int rb_encdb_dummy(const char *name)
static int enc_register(const char *name, rb_encoding *encoding)
static int enc_check_encoding(VALUE obj)
VALUE rb_sprintf(const char *format,...)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
int rb_enc_unicode_p(rb_encoding *enc)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define ONIGENC_ASCII_CODE_TO_UPPER_CASE(c)
VALUE rb_ivar_set(VALUE, ID, VALUE)
#define ONIGENC_CTYPE_PRINT
rb_encoding * rb_usascii_encoding(void)
int rb_encdb_replicate(const char *name, const char *orig)
#define ENCODING_NAMELEN_MAX
int rb_define_dummy_encoding(const char *name)
static struct default_encoding default_internal
static VALUE enc_compatible_p(VALUE klass, VALUE str1, VALUE str2)
rb_encoding * rb_locale_encoding(void)
#define ONIGENC_IS_ASCII_CODE(code)
int rb_utf8_encindex(void)
#define ENCODING_SET_INLINED(obj, i)
VALUE rb_obj_encoding(VALUE obj)
static int rb_enc_dummy_p(rb_encoding *enc)
static int enc_autoload(rb_encoding *)
#define rb_enc_asciicompat(enc)
#define ONIGENC_CTYPE_SPACE
static VALUE set_default_internal(VALUE klass, VALUE encoding)
#define ONIGENC_IS_UNICODE(enc)
#define enc_autoload_p(enc)
static void enc_check_duplication(const char *name)
#define StringValueCStr(v)
static size_t enc_memsize(const void *p)
VALUE rb_usascii_str_new2(const char *)
static int enc_names_i(st_data_t name, st_data_t idx, st_data_t args)
rb_encoding * rb_enc_get(VALUE obj)
static VALUE get_default_external(VALUE klass)
static struct default_encoding default_external
#define ONIGENC_FLAG_UNICODE
#define ONIGENC_PRECISE_MBC_ENC_LEN(enc, p, e)
#define ENCODING_INLINE_MAX
void rb_set_errinfo(VALUE err)
static VALUE enc_replicate(VALUE encoding, VALUE name)
static int enc_set_filesystem_encoding(void)
VALUE rb_check_string_type(VALUE)
void rb_enc_set_default_internal(VALUE encoding)
static VALUE enc_ascii_compatible_p(VALUE enc)
#define valid_encoding_name_p(name)
int rb_enc_alias(const char *alias, const char *orig)
static VALUE require_enc(VALUE enclib)
#define is_data_encoding(obj)
struct rb_encoding_entry * list
rb_encoding * rb_filesystem_encoding(void)
static int enc_capable(VALUE obj)
static const rb_data_type_t encoding_data_type
static st_data_t enc_dup_name(st_data_t name)
VALUE rb_enc_default_internal(void)
VALUE rb_ary_new2(long capa)
static int check_encoding(rb_encoding *enc)
static VALUE get_default_internal(VALUE klass)
#define ENC_TO_ENCINDEX(enc)
static int enc_replicate_with_index(const char *name, rb_encoding *origenc, int idx)
unsigned int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc)
#define STRCASECMP(s1, s2)
#define rb_enc_to_index(enc)
static int enc_alias(const char *alias, int idx)
rb_encoding * rb_ascii8bit_encoding(void)
void rb_warning(const char *fmt,...)
int rb_enc_find_index(const char *name)
#define rb_check_frozen(obj)
#define CONST_ID(var, str)
int rb_enc_register(const char *name, rb_encoding *encoding)
#define SPECIAL_CONST_P(x)
static VALUE rb_encoding_list
#define ONIGENC_CTYPE_GRAPH
void rb_encdb_declare(const char *name)
int rb_enc_str_asciionly_p(VALUE)
void rb_gc_mark_encodings(void)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
#define UNSPECIFIED_ENCODING
rb_encoding OnigEncodingUTF_8
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
#define ONIGENC_CTYPE_LOWER
void rb_warn(const char *fmt,...)
static int load_encoding(const char *name)
rb_encoding * rb_enc_find(const char *name)
static VALUE enc_find(VALUE klass, VALUE enc)
#define ONIGENC_ASCII_CODE_TO_LOWER_CASE(c)
static int must_encoding(VALUE enc)
rb_encoding * rb_enc_from_index(int index)