1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

New API Encoding#ascii_compatible?.

* encoding.c (enc_ascii_compatible_p): added. [ruby-core:24793]
  (Init_Encoding): New API Encoding#ascii_compatible?.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2009-08-08 23:25:32 +00:00
parent 28f00681ca
commit e56bf07b16
3 changed files with 28 additions and 0 deletions

View file

@ -1,3 +1,7 @@
Sat Aug 8 17:03:21 2009 NARUSE, Yui <naruse@ruby-lang.org>
* encoding.c (enc_ascii_compatible_p): added. [ruby-core:24793]
(Init_Encoding): New API Encoding#ascii_compatible?.
Sun Aug 9 07:25:07 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/ripper/eventids2.c (token_to_eventid): added

View file

@ -377,6 +377,22 @@ enc_dummy_p(VALUE enc)
return ENC_DUMMY_P(enc_table.list[must_encoding(enc)].enc) ? Qtrue : Qfalse;
}
/*
* call-seq:
* enc.ascii_compatible? => true or false
*
* Returns whether ASCII-compatible or not.
*
* Encoding::UTF_8.ascii_compatible? #=> true
* Encoding::UTF_16BE.ascii_compatible? #=> false
*
*/
static VALUE
enc_ascii_compatible_p(VALUE enc)
{
return rb_enc_asciicompat(enc_table.list[must_encoding(enc)].enc) ? Qtrue : Qfalse;
}
static const char *
enc_alias_internal(const char *alias, int idx)
{
@ -1428,6 +1444,7 @@ Init_Encoding(void)
rb_define_method(rb_cEncoding, "name", enc_name, 0);
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_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);

View file

@ -44,6 +44,13 @@ class TestEncoding < Test::Unit::TestCase
assert_equal(false, Encoding::UTF_8.dummy?)
end
def test_ascii_compatible_p
assert_equal(true, Encoding::ASCII_8BIT.ascii_compatible?)
assert_equal(true, Encoding::UTF_8.ascii_compatible?)
assert_equal(false, Encoding::UTF_16BE.ascii_compatible?)
assert_equal(false, Encoding::ISO_2022_JP.ascii_compatible?)
end
def test_name_list
assert_instance_of(Array, Encoding.name_list)
Encoding.name_list.each do |x|