mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/stringio/stringio.c (strio_ungetc): should allow ungetc at
the top of the buffer. ref #701 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@20151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ef1e9185f4
commit
ecdd96c58d
2 changed files with 22 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Nov 8 17:47:28 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* ext/stringio/stringio.c (strio_ungetc): should allow ungetc at
|
||||
the top of the buffer. ref #701
|
||||
|
||||
Sat Nov 8 01:38:07 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* ext/nkf/nkf-utf8/nkf.c (h_conv): can't guess UTF-8 input in
|
||||
|
|
|
@ -781,15 +781,24 @@ strio_ungetc(self, ch)
|
|||
int cc = NUM2INT(ch);
|
||||
long len, pos = ptr->pos;
|
||||
|
||||
if (cc != EOF && pos > 0) {
|
||||
if ((len = RSTRING(ptr->string)->len) < pos-- ||
|
||||
(unsigned char)RSTRING(ptr->string)->ptr[pos] !=
|
||||
(unsigned char)cc) {
|
||||
strio_extend(ptr, pos, 1);
|
||||
RSTRING(ptr->string)->ptr[pos] = cc;
|
||||
OBJ_INFECT(ptr->string, self);
|
||||
if (cc != EOF) {
|
||||
len = RSTRING(ptr->string)->len;
|
||||
if (pos == 0) {
|
||||
char *p;
|
||||
rb_str_resize(ptr->string, len + 1);
|
||||
p = RSTRING(ptr->string)->ptr;
|
||||
memmove(p + 1, p, len);
|
||||
}
|
||||
--ptr->pos;
|
||||
else {
|
||||
if (len < pos-- ||
|
||||
(unsigned char)RSTRING(ptr->string)->ptr[pos] !=
|
||||
(unsigned char)cc) {
|
||||
strio_extend(ptr, pos, 1);
|
||||
}
|
||||
--ptr->pos;
|
||||
}
|
||||
RSTRING(ptr->string)->ptr[pos] = cc;
|
||||
OBJ_INFECT(ptr->string, self);
|
||||
ptr->flags &= ~STRIO_EOF;
|
||||
}
|
||||
return Qnil;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue