コード例 #1
0
ファイル: encoding.c プロジェクト: 217/ruby
static int
enc_register_at(int index, const char *name, rb_encoding *encoding)
{
    struct rb_encoding_entry *ent = &enc_table.list[index];
    VALUE list;

    if (!valid_encoding_name_p(name)) return -1;
    if (!ent->name) {
	ent->name = name = strdup(name);
    }
    else if (STRCASECMP(name, ent->name)) {
	return -1;
    }
    if (!ent->enc) {
	ent->enc = xmalloc(sizeof(rb_encoding));
    }
    if (encoding) {
	*ent->enc = *encoding;
    }
    else {
	memset(ent->enc, 0, sizeof(*ent->enc));
    }
    encoding = ent->enc;
    encoding->name = name;
    encoding->ruby_encoding_index = index;
    st_insert(enc_table.names, (st_data_t)name, (st_data_t)index);
    list = rb_encoding_list;
    if (list && NIL_P(rb_ary_entry(list, index))) {
	/* initialize encoding data */
	rb_ary_store(list, index, enc_new(encoding));
    }
    return index;
}
コード例 #2
0
ファイル: encoding.c プロジェクト: 217/ruby
static int
enc_alias(const char *alias, int idx)
{
    if (!valid_encoding_name_p(alias)) return -1;
    alias = enc_alias_internal(alias, idx);
    set_encoding_const(alias, rb_enc_from_index(idx));
    return idx;
}
コード例 #3
0
ファイル: encoding.c プロジェクト: angui/mruby
static int
enc_register_at(mrb_state *mrb, int index, const char *name, mrb_encoding *encoding)
{
    struct mrb_encoding_entry *ent = &enc_table.list[index];
    mrb_value list;
    mrb_value ref_ary;

    if (!valid_encoding_name_p(name)) return -1;
    if (!ent->name) {
    ent->name = name = strdup(name);
    }
    else if (STRCASECMP(name, ent->name)) {
    return -1;
    }
    if (!ent->enc) {
    ent->enc = xmalloc(sizeof(mrb_encoding));
    }
    if (encoding) {
    *ent->enc = *encoding;
    }
    else {
    memset(ent->enc, 0, sizeof(*ent->enc));
    }
    encoding = ent->enc;
    encoding->name = name;
    encoding->ruby_encoding_index = index;
    st_insert(enc_table.names, (st_data_t)name, (st_data_t)index);
    list = mrb_encoding_list;
    //if (list && mrb_nil_p((mrb_ary_ref(mrb, list, index)))) {
    if (list.tt) {
      ref_ary = mrb_ary_ref(mrb, list, index);
      if mrb_nil_p(ref_ary) {
        /* initialize encoding data */
        mrb_ary_set(mrb, list, index, enc_new(mrb, encoding));//rb_ary_store(list, index, enc_new(encoding));
      }
    }