mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (rb_io_extract_encoding_option): accept Encoding object as
encoding: optional argument. [ruby-dev:42884] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f83bc706bf
commit
522c538e93
3 changed files with 60 additions and 7 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Dec 25 14:27:09 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (rb_io_extract_encoding_option): accept Encoding object as
|
||||||
|
encoding: optional argument. [ruby-dev:42884]
|
||||||
|
|
||||||
Sat Dec 25 13:37:55 2010 Ryan Davis <ryand-ruby@zenspider.com>
|
Sat Dec 25 13:37:55 2010 Ryan Davis <ryand-ruby@zenspider.com>
|
||||||
|
|
||||||
* lib/minitest/*.rb: Imported minitest 2.0.2 r6093.
|
* lib/minitest/*.rb: Imported minitest 2.0.2 r6093.
|
||||||
|
|
12
io.c
12
io.c
|
@ -4384,9 +4384,12 @@ rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2
|
||||||
if (v != Qundef) intenc = v;
|
if (v != Qundef) intenc = v;
|
||||||
}
|
}
|
||||||
if ((extenc != Qundef || intenc != Qundef) && !NIL_P(encoding)) {
|
if ((extenc != Qundef || intenc != Qundef) && !NIL_P(encoding)) {
|
||||||
|
if (!NIL_P(ruby_verbose)) {
|
||||||
|
int idx = rb_to_encoding_index(encoding);
|
||||||
rb_warn("Ignoring encoding parameter '%s': %s_encoding is used",
|
rb_warn("Ignoring encoding parameter '%s': %s_encoding is used",
|
||||||
StringValueCStr(encoding),
|
idx < 0 ? StringValueCStr(encoding) : rb_enc_name(rb_enc_from_index(idx)),
|
||||||
extenc == Qundef ? "internal" : "external");
|
extenc == Qundef ? "internal" : "external");
|
||||||
|
}
|
||||||
encoding = Qnil;
|
encoding = Qnil;
|
||||||
}
|
}
|
||||||
if (extenc != Qundef && !NIL_P(extenc)) {
|
if (extenc != Qundef && !NIL_P(extenc)) {
|
||||||
|
@ -4417,7 +4420,12 @@ rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2
|
||||||
}
|
}
|
||||||
if (!NIL_P(encoding)) {
|
if (!NIL_P(encoding)) {
|
||||||
extracted = 1;
|
extracted = 1;
|
||||||
parse_mode_enc(StringValueCStr(encoding), enc_p, enc2_p, fmode_p);
|
if (!NIL_P(tmp = rb_check_string_type(encoding))) {
|
||||||
|
parse_mode_enc(StringValueCStr(tmp), enc_p, enc2_p, fmode_p);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_io_ext_int_to_encs(rb_to_encoding(encoding), NULL, enc_p, enc2_p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (extenc != Qundef || intenc != Qundef) {
|
else if (extenc != Qundef || intenc != Qundef) {
|
||||||
extracted = 1;
|
extracted = 1;
|
||||||
|
|
|
@ -114,7 +114,27 @@ EOT
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_r_enc_in_opt2
|
def test_open_r_encname_in_opt
|
||||||
|
with_tmpdir {
|
||||||
|
generate_file('tmp', "")
|
||||||
|
open("tmp", "r", encoding: Encoding::EUC_JP) {|f|
|
||||||
|
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||||
|
assert_equal(nil, f.internal_encoding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_open_r_ext_enc_in_opt
|
||||||
|
with_tmpdir {
|
||||||
|
generate_file('tmp', "")
|
||||||
|
open("tmp", "r", external_encoding: Encoding::EUC_JP) {|f|
|
||||||
|
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||||
|
assert_equal(nil, f.internal_encoding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_open_r_ext_encname_in_opt
|
||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
generate_file('tmp', "")
|
generate_file('tmp', "")
|
||||||
open("tmp", "r", external_encoding: "euc-jp") {|f|
|
open("tmp", "r", external_encoding: "euc-jp") {|f|
|
||||||
|
@ -125,6 +145,16 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_r_enc_enc
|
def test_open_r_enc_enc
|
||||||
|
with_tmpdir {
|
||||||
|
generate_file('tmp', "")
|
||||||
|
open("tmp", "r", external_encoding: Encoding::EUC_JP, internal_encoding: Encoding::UTF_8) {|f|
|
||||||
|
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||||
|
assert_equal(Encoding::UTF_8, f.internal_encoding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_open_r_encname_encname
|
||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
generate_file('tmp', "")
|
generate_file('tmp', "")
|
||||||
open("tmp", "r:euc-jp:utf-8") {|f|
|
open("tmp", "r:euc-jp:utf-8") {|f|
|
||||||
|
@ -134,7 +164,7 @@ EOT
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_r_enc_enc_in_opt
|
def test_open_r_encname_encname_in_opt
|
||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
generate_file('tmp', "")
|
generate_file('tmp', "")
|
||||||
open("tmp", "r", encoding: "euc-jp:utf-8") {|f|
|
open("tmp", "r", encoding: "euc-jp:utf-8") {|f|
|
||||||
|
@ -144,7 +174,17 @@ EOT
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_r_enc_enc_in_opt2
|
def test_open_r_enc_enc_in_opt
|
||||||
|
with_tmpdir {
|
||||||
|
generate_file('tmp', "")
|
||||||
|
open("tmp", "r", external_encoding: Encoding::EUC_JP, internal_encoding: Encoding::UTF_8) {|f|
|
||||||
|
assert_equal(Encoding::EUC_JP, f.external_encoding)
|
||||||
|
assert_equal(Encoding::UTF_8, f.internal_encoding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_open_r_encname_encname_in_opt
|
||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
generate_file('tmp', "")
|
generate_file('tmp', "")
|
||||||
open("tmp", "r", external_encoding: "euc-jp", internal_encoding: "utf-8") {|f|
|
open("tmp", "r", external_encoding: "euc-jp", internal_encoding: "utf-8") {|f|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue