mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merges r23424 from trunk into ruby_1_9_1.
-- * ext/stringio/stringio.c (strio_ungetbyte): encoding should not be effective. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@23520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6fac4c5f9f
commit
ce1a4ee112
5 changed files with 68 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu May 14 16:07:48 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/stringio/stringio.c (strio_ungetbyte): encoding should no
|
||||||
|
be effective.
|
||||||
|
|
||||||
Sun May 10 11:36:11 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun May 10 11:36:11 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/dl/cfunc.c (rb_dlcfunc_instance_p): new function to check if
|
* ext/dl/cfunc.c (rb_dlcfunc_instance_p): new function to check if
|
||||||
|
|
|
@ -744,8 +744,37 @@ strio_ungetc(VALUE self, VALUE c)
|
||||||
static VALUE
|
static VALUE
|
||||||
strio_ungetbyte(VALUE self, VALUE c)
|
strio_ungetbyte(VALUE self, VALUE c)
|
||||||
{
|
{
|
||||||
NUM2INT(c);
|
struct StringIO *ptr = readable(StringIO(self));
|
||||||
return strio_ungetc(self, c);
|
char buf[1], *cp = buf;
|
||||||
|
long pos = ptr->pos, cl = 1;
|
||||||
|
VALUE str = ptr->string;
|
||||||
|
|
||||||
|
if (NIL_P(c)) return Qnil;
|
||||||
|
if (FIXNUM_P(c)) {
|
||||||
|
buf[0] = (char)FIX2INT(c);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SafeStringValue(c);
|
||||||
|
cp = RSTRING_PTR(c);
|
||||||
|
cl = RSTRING_LEN(c);
|
||||||
|
if (cl == 0) return Qnil;
|
||||||
|
}
|
||||||
|
rb_str_modify(str);
|
||||||
|
if (cl > pos) {
|
||||||
|
char *s;
|
||||||
|
long rest = RSTRING_LEN(str) - pos;
|
||||||
|
rb_str_resize(str, rest + cl);
|
||||||
|
s = RSTRING_PTR(str);
|
||||||
|
memmove(s + cl, s + pos, rest);
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pos -= cl;
|
||||||
|
}
|
||||||
|
memcpy(RSTRING_PTR(str) + pos, cp, cl);
|
||||||
|
ptr->pos = pos;
|
||||||
|
RB_GC_GUARD(c);
|
||||||
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -77,6 +77,22 @@ class TestIO < Test::Unit::TestCase
|
||||||
r.close
|
r.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ungetbyte
|
||||||
|
t = make_tempfile
|
||||||
|
t.open
|
||||||
|
t.ungetbyte(0x41)
|
||||||
|
assert_equal(0x41, t.getbyte)
|
||||||
|
t.rewind
|
||||||
|
t.ungetbyte("qux")
|
||||||
|
assert_equal("quxfoo\n", t.gets)
|
||||||
|
t.set_encoding("utf-8")
|
||||||
|
t.ungetbyte(0x89)
|
||||||
|
t.ungetbyte(0x8e)
|
||||||
|
t.ungetbyte("\xe7")
|
||||||
|
t.ungetbyte("\xe7\xb4\x85")
|
||||||
|
assert_equal("\u7d05\u7389bar\n", t.gets)
|
||||||
|
end
|
||||||
|
|
||||||
def test_each_byte
|
def test_each_byte
|
||||||
r, w = IO.pipe
|
r, w = IO.pipe
|
||||||
w << "abc def"
|
w << "abc def"
|
||||||
|
|
|
@ -293,6 +293,21 @@ class TestStringIO < Test::Unit::TestCase
|
||||||
f.close unless f.closed?
|
f.close unless f.closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ungetbyte
|
||||||
|
s = "foo\nbar\n"
|
||||||
|
t = StringIO.new(s, "r")
|
||||||
|
t.ungetbyte(0x41)
|
||||||
|
assert_equal(0x41, t.getbyte)
|
||||||
|
t.ungetbyte("qux")
|
||||||
|
assert_equal("quxfoo\n", t.gets)
|
||||||
|
t.set_encoding("utf-8")
|
||||||
|
t.ungetbyte(0x89)
|
||||||
|
t.ungetbyte(0x8e)
|
||||||
|
t.ungetbyte("\xe7")
|
||||||
|
t.ungetbyte("\xe7\xb4\x85")
|
||||||
|
assert_equal("\u7d05\u7389bar\n", t.gets)
|
||||||
|
end
|
||||||
|
|
||||||
def test_ungetc
|
def test_ungetc
|
||||||
s = "1234"
|
s = "1234"
|
||||||
f = StringIO.new(s, "r")
|
f = StringIO.new(s, "r")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "1.9.1"
|
#define RUBY_VERSION "1.9.1"
|
||||||
#define RUBY_RELEASE_DATE "2009-05-12"
|
#define RUBY_RELEASE_DATE "2009-05-12"
|
||||||
#define RUBY_PATCHLEVEL 137
|
#define RUBY_PATCHLEVEL 138
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
#define RUBY_VERSION_MINOR 9
|
#define RUBY_VERSION_MINOR 9
|
||||||
#define RUBY_VERSION_TEENY 1
|
#define RUBY_VERSION_TEENY 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue