* io.c (io_ungetc): raise NotImplementedError when ungetc is called
against dummy encoding IO. * io.c (rb_io_getline_1): ditto when gets with delimiter is called. * io.c (io_getc): ditto when getc is called. * test/ruby/test_io_m17n.rb (test_terminator_stateful_conversion, test_getc_stateful_conversion, test_ungetc_stateful_conversion): these tests should raise NotImplementedError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d866ba69a1
commit
be9994a03a
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
Tue Jul 29 23:37:37 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* io.c (io_ungetc): raise NotImplementedError when ungetc is called
|
||||||
|
against dummy encoding IO.
|
||||||
|
|
||||||
|
* io.c (rb_io_getline_1): ditto when gets with delimiter is called.
|
||||||
|
|
||||||
|
* io.c (io_getc): ditto when getc is called.
|
||||||
|
|
||||||
|
* test/ruby/test_io_m17n.rb (test_terminator_stateful_conversion,
|
||||||
|
test_getc_stateful_conversion, test_ungetc_stateful_conversion):
|
||||||
|
these tests should raise NotImplementedError.
|
||||||
|
|
||||||
Tue Jul 29 22:55:34 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
Tue Jul 29 22:55:34 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
* test/ruby/test_io.rb (pipe): run reader thread and writer thread.
|
* test/ruby/test_io.rb (pipe): run reader thread and writer thread.
|
||||||
|
13
io.c
13
io.c
@ -323,11 +323,17 @@ io_unread(rb_io_t *fptr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static rb_encoding *io_input_encoding(rb_io_t *fptr);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
io_ungetc(VALUE str, rb_io_t *fptr)
|
io_ungetc(VALUE str, rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
int len = RSTRING_LEN(str);
|
int len = RSTRING_LEN(str);
|
||||||
|
|
||||||
|
if (rb_enc_dummy_p(io_input_encoding(fptr))) {
|
||||||
|
rb_raise(rb_eNotImpError, "ungetc against dummy encoding is not currently supported");
|
||||||
|
}
|
||||||
|
|
||||||
if (fptr->rbuf == NULL) {
|
if (fptr->rbuf == NULL) {
|
||||||
fptr->rbuf_off = 0;
|
fptr->rbuf_off = 0;
|
||||||
fptr->rbuf_len = 0;
|
fptr->rbuf_len = 0;
|
||||||
@ -1950,6 +1956,9 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
|
|||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_readable(fptr);
|
rb_io_check_readable(fptr);
|
||||||
|
if (rb_enc_dummy_p(io_input_encoding(fptr)) && rs != rb_default_rs) {
|
||||||
|
rb_raise(rb_eNotImpError, "gets with delimiter against dummy encoding is not currently supported");
|
||||||
|
}
|
||||||
if (NIL_P(rs)) {
|
if (NIL_P(rs)) {
|
||||||
str = read_all(fptr, 0, Qnil);
|
str = read_all(fptr, 0, Qnil);
|
||||||
if (RSTRING_LEN(str) == 0) return Qnil;
|
if (RSTRING_LEN(str) == 0) return Qnil;
|
||||||
@ -2265,6 +2274,10 @@ io_getc(rb_io_t *fptr, rb_encoding *enc)
|
|||||||
int r, n, cr = 0;
|
int r, n, cr = 0;
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
|
if (rb_enc_dummy_p(enc)) {
|
||||||
|
rb_raise(rb_eNotImpError, "getc against dummy encoding is not currently supported");
|
||||||
|
}
|
||||||
|
|
||||||
if (io_fillbuf(fptr) < 0) {
|
if (io_fillbuf(fptr) < 0) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -161,11 +161,13 @@ EOT
|
|||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
src = "before \e$B\x23\x30\x23\x31\e(B after".force_encoding("iso-2022-jp")
|
src = "before \e$B\x23\x30\x23\x31\e(B after".force_encoding("iso-2022-jp")
|
||||||
generate_file('tmp', src)
|
generate_file('tmp', src)
|
||||||
s = open("tmp", "r:iso-2022-jp:euc-jp") {|f|
|
assert_raise(NotImplementedError) do
|
||||||
f.gets("0".force_encoding("euc-jp"))
|
s = open("tmp", "r:iso-2022-jp:euc-jp") {|f|
|
||||||
}
|
f.gets("0".force_encoding("euc-jp"))
|
||||||
assert_equal(Encoding.find("euc-jp"), s.encoding)
|
}
|
||||||
assert_str_equal(src.encode("euc-jp"), s)
|
assert_equal(Encoding.find("euc-jp"), s.encoding)
|
||||||
|
assert_str_equal(src.encode("euc-jp"), s)
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -218,10 +220,27 @@ EOT
|
|||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
src = "\e$B\x23\x30\x23\x31\e(B".force_encoding("iso-2022-jp")
|
src = "\e$B\x23\x30\x23\x31\e(B".force_encoding("iso-2022-jp")
|
||||||
generate_file('tmp', src)
|
generate_file('tmp', src)
|
||||||
open("tmp", "r:iso-2022-jp:euc-jp") {|f|
|
assert_raise(NotImplementedError) do
|
||||||
assert_equal("\xa3\xb0".force_encoding("euc-jp"), f.getc)
|
open("tmp", "r:iso-2022-jp:euc-jp") {|f|
|
||||||
assert_equal("\xa3\xb1".force_encoding("euc-jp"), f.getc)
|
assert_equal("\xa3\xb0".force_encoding("euc-jp"), f.getc)
|
||||||
}
|
assert_equal("\xa3\xb1".force_encoding("euc-jp"), f.getc)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ungetc_stateful_conversion
|
||||||
|
with_tmpdir {
|
||||||
|
src = "before \e$B\x23\x30\x23\x31\e(B after".force_encoding("iso-2022-jp")
|
||||||
|
generate_file('tmp', src)
|
||||||
|
assert_raise(NotImplementedError) do
|
||||||
|
s = open("tmp", "r:iso-2022-jp:euc-jp") {|f|
|
||||||
|
f.ungetc("0".force_encoding("euc-jp"))
|
||||||
|
f.read
|
||||||
|
}
|
||||||
|
assert_equal(Encoding.find("euc-jp"), s.encoding)
|
||||||
|
assert_str_equal(("0" + src).encode("euc-jp"), s)
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user