stringio.c: non-ascii encoding
* ext/stringio/stringio.c (strio_putc): fix for non-ascii encoding, like as IO#putc. [ruby-dev:48114] [Bug #9765] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
862618d224
commit
90e393b368
@ -1,3 +1,8 @@
|
|||||||
|
Mon Apr 21 14:11:48 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/stringio/stringio.c (strio_putc): fix for non-ascii
|
||||||
|
encoding, like as IO#putc. [ruby-dev:48114] [Bug #9765]
|
||||||
|
|
||||||
Sun Apr 20 12:57:15 2014 Masaya Tarui <tarui@ruby-lang.org>
|
Sun Apr 20 12:57:15 2014 Masaya Tarui <tarui@ruby-lang.org>
|
||||||
|
|
||||||
* st.c (st_foreach_check): change start point of search at check
|
* st.c (st_foreach_check): change start point of search at check
|
||||||
|
@ -1233,17 +1233,17 @@ static VALUE
|
|||||||
strio_putc(VALUE self, VALUE ch)
|
strio_putc(VALUE self, VALUE ch)
|
||||||
{
|
{
|
||||||
struct StringIO *ptr = writable(self);
|
struct StringIO *ptr = writable(self);
|
||||||
int c = NUM2CHR(ch);
|
VALUE str;
|
||||||
long olen;
|
|
||||||
|
|
||||||
check_modifiable(ptr);
|
check_modifiable(ptr);
|
||||||
olen = RSTRING_LEN(ptr->string);
|
if (RB_TYPE_P(ch, T_STRING)) {
|
||||||
if (ptr->flags & FMODE_APPEND) {
|
str = rb_str_substr(ch, 0, 1);
|
||||||
ptr->pos = olen;
|
|
||||||
}
|
}
|
||||||
strio_extend(ptr, ptr->pos, 1);
|
else {
|
||||||
RSTRING_PTR(ptr->string)[ptr->pos++] = c;
|
char c = NUM2CHR(ch);
|
||||||
OBJ_INFECT(ptr->string, self);
|
str = rb_str_new(&c, 1);
|
||||||
|
}
|
||||||
|
strio_write(self, str);
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,6 +419,22 @@ class TestStringIO < Test::Unit::TestCase
|
|||||||
assert_equal("foo123", s)
|
assert_equal("foo123", s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_putc_nonascii
|
||||||
|
s = ""
|
||||||
|
f = StringIO.new(s, "w")
|
||||||
|
f.putc("\u{3042}")
|
||||||
|
f.putc(0x3044)
|
||||||
|
f.close
|
||||||
|
assert_equal("\u{3042}D", s)
|
||||||
|
|
||||||
|
s = "foo"
|
||||||
|
f = StringIO.new(s, "a")
|
||||||
|
f.putc("\u{3042}")
|
||||||
|
f.putc(0x3044)
|
||||||
|
f.close
|
||||||
|
assert_equal("foo\u{3042}D", s)
|
||||||
|
end
|
||||||
|
|
||||||
def test_read
|
def test_read
|
||||||
f = StringIO.new("\u3042\u3044")
|
f = StringIO.new("\u3042\u3044")
|
||||||
assert_raise(ArgumentError) { f.read(-1) }
|
assert_raise(ArgumentError) { f.read(-1) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user