* io.c (rb_io_ungetc): use unsigned int for GB18030.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0a8f047a98
commit
7587eb706a
@ -1,3 +1,7 @@
|
|||||||
|
Tue Oct 12 15:36:09 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (rb_io_ungetc): use unsigned int for GB18030.
|
||||||
|
|
||||||
Tue Oct 12 15:14:21 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
Tue Oct 12 15:14:21 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (rb_io_putc): support multibyte characters.
|
* io.c (rb_io_putc): support multibyte characters.
|
||||||
|
11
io.c
11
io.c
@ -3229,12 +3229,13 @@ rb_io_ungetc(VALUE io, VALUE c)
|
|||||||
rb_io_check_char_readable(fptr);
|
rb_io_check_char_readable(fptr);
|
||||||
if (NIL_P(c)) return Qnil;
|
if (NIL_P(c)) return Qnil;
|
||||||
if (FIXNUM_P(c)) {
|
if (FIXNUM_P(c)) {
|
||||||
int cc = FIX2INT(c);
|
c = rb_enc_uint_chr(FIX2UINT(c), io_read_encoding(fptr));
|
||||||
rb_encoding *enc = io_read_encoding(fptr);
|
|
||||||
char buf[16];
|
|
||||||
|
|
||||||
c = rb_str_new(buf, rb_enc_mbcput(cc, buf, enc));
|
|
||||||
}
|
}
|
||||||
|
#if SIZEOF_LONG > SIZEOF_INT
|
||||||
|
else if (TYPE(c) == T_BIGNUM) {
|
||||||
|
c = rb_enc_uint_chr(NUM2UINT(c), io_read_encoding(fptr));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else {
|
else {
|
||||||
SafeStringValue(c);
|
SafeStringValue(c);
|
||||||
}
|
}
|
||||||
|
@ -418,6 +418,30 @@ EOT
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ungetc_int
|
||||||
|
with_tmpdir {
|
||||||
|
generate_file('tmp', "A")
|
||||||
|
s = open("tmp", "r:GB18030") {|f|
|
||||||
|
f.ungetc(0x8431A439)
|
||||||
|
f.read
|
||||||
|
}
|
||||||
|
assert_equal(Encoding::GB18030, s.encoding)
|
||||||
|
assert_str_equal(0x8431A439.chr("GB18030")+"A", s)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ungetc_str
|
||||||
|
with_tmpdir {
|
||||||
|
generate_file('tmp', "A")
|
||||||
|
s = open("tmp", "r:GB18030") {|f|
|
||||||
|
f.ungetc(0x8431A439.chr("GB18030"))
|
||||||
|
f.read
|
||||||
|
}
|
||||||
|
assert_equal(Encoding::GB18030, s.encoding)
|
||||||
|
assert_str_equal(0x8431A439.chr("GB18030")+"A", s)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_ungetc_stateful_conversion
|
def test_ungetc_stateful_conversion
|
||||||
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user