Skip to content

Commit

Permalink
* encoding.c (enc_replicate): add Encoding#replicate(name).
Browse files Browse the repository at this point in the history
* encoding.c (enc_replicate_with_index): renamed from old
  enc_replicate.

* encoding.c (rb_enc_from_encoding_index): split from
  rb_enc_from_encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Dec 10, 2009
1 parent ae76a23 commit 614a842
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Thu Dec 10 12:56:02 2009 NARUSE, Yui <[email protected]>

* encoding.c (enc_replicate): add Encoding#replicate(name).

* encoding.c (enc_replicate_with_index): renamed from old
enc_replicate.

* encoding.c (rb_enc_from_encoding_index): split from
rb_enc_from_encoding.

Thu Dec 10 09:15:00 2009 NARUSE, Yui <[email protected]>

* string.c (rb_str_inspect): CHAR_ESC_LEN should be 13.
Expand Down
39 changes: 26 additions & 13 deletions encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,30 @@ enc_new(rb_encoding *encoding)
return TypedData_Wrap_Struct(rb_cEncoding, &encoding_data_type, encoding);
}

VALUE
rb_enc_from_encoding(rb_encoding *encoding)
static VALUE
rb_enc_from_encoding_index(int idx)
{
VALUE list, enc;
int idx;

if (!encoding) return Qnil;
idx = ENC_TO_ENCINDEX(encoding);
if (!(list = rb_encoding_list)) {
rb_bug("rb_enc_from_encoding(%d\"%s\"): no rb_encoding_list",
idx, rb_enc_name(encoding));
rb_bug("rb_enc_from_encoding_index(%d): no rb_encoding_list", idx);
}
enc = rb_ary_entry(list, idx);
if (NIL_P(enc)) {
rb_bug("rb_enc_from_encoding(%d\"%s\"): not created yet",
idx, rb_enc_name(encoding));
rb_bug("rb_enc_from_encoding_index(%d): not created yet", idx);
}
return enc;
}

VALUE
rb_enc_from_encoding(rb_encoding *encoding)
{
int idx;
if (!encoding) return Qnil;
idx = ENC_TO_ENCINDEX(encoding);
return rb_enc_from_encoding_index(idx);
}

static int enc_autoload(rb_encoding *);

static int
Expand Down Expand Up @@ -309,8 +313,16 @@ rb_enc_replicate(const char *name, rb_encoding *encoding)
return idx;
}

static VALUE
enc_replicate(VALUE encoding, VALUE name)
{
return rb_enc_from_encoding_index(
rb_enc_replicate(RSTRING_PTR(name),
rb_to_encoding(encoding)));
}

static int
enc_replicate(int idx, const char *name, rb_encoding *origenc)
enc_replicate_with_index(const char *name, rb_encoding *origenc, int idx)
{
if (idx < 0) {
idx = enc_register(name, origenc);
Expand All @@ -334,7 +346,7 @@ rb_encdb_replicate(const char *name, const char *orig)
if (origidx < 0) {
origidx = enc_register(orig, 0);
}
return enc_replicate(idx, name, rb_enc_from_index(origidx));
return enc_replicate_with_index(name, rb_enc_from_index(origidx), idx);
}

int
Expand All @@ -350,8 +362,8 @@ rb_define_dummy_encoding(const char *name)
int
rb_encdb_dummy(const char *name)
{
int index = enc_replicate(rb_enc_registered(name), name,
rb_ascii8bit_encoding());
int index = enc_replicate_with_index(name, rb_ascii8bit_encoding(),
rb_enc_registered(name));
rb_encoding *enc = enc_table.list[index].enc;

ENC_SET_DUMMY(enc);
Expand Down Expand Up @@ -1490,6 +1502,7 @@ Init_Encoding(void)
rb_define_method(rb_cEncoding, "names", enc_names, 0);
rb_define_method(rb_cEncoding, "dummy?", enc_dummy_p, 0);
rb_define_method(rb_cEncoding, "ascii_compatible?", enc_ascii_compatible_p, 0);
rb_define_method(rb_cEncoding, "replicate", enc_replicate, 1);
rb_define_singleton_method(rb_cEncoding, "list", enc_list, 0);
rb_define_singleton_method(rb_cEncoding, "name_list", rb_enc_name_list, 0);
rb_define_singleton_method(rb_cEncoding, "aliases", rb_enc_aliases, 0);
Expand Down

0 comments on commit 614a842

Please sign in to comment.