mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/stringio/stringio.c (strio_ungetc): pads with \000 when the
current position is after the end. [ruby-dev:40271] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
63cbe555b7
commit
e5757042f9
2 changed files with 24 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Feb 6 01:55:02 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* ext/stringio/stringio.c (strio_ungetc): pads with \000 when the
|
||||||
|
current position is after the end. [ruby-dev:40271]
|
||||||
|
|
||||||
Sat Feb 6 01:14:54 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
Sat Feb 6 01:14:54 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
* ext/purelib.rb, common.mk: to simulate ruby command more precisely,
|
* ext/purelib.rb, common.mk: to simulate ruby command more precisely,
|
||||||
|
|
|
@ -725,17 +725,26 @@ strio_ungetc(VALUE self, VALUE c)
|
||||||
c = rb_str_conv_enc(c, enc2, enc);
|
c = rb_str_conv_enc(c, enc2, enc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* get logical position */
|
if (RSTRING_LEN(ptr->string) < ptr->pos) {
|
||||||
lpos = 0; p = RSTRING_PTR(ptr->string); pend = p + ptr->pos;
|
long len = RSTRING_LEN(ptr->string);
|
||||||
for (;;) {
|
rb_str_resize(ptr->string, ptr->pos - 1);
|
||||||
clen = rb_enc_mbclen(p, pend, enc);
|
memset(RSTRING_PTR(ptr->string) + len, 0, ptr->pos - len - 1);
|
||||||
if (p+clen >= pend) break;
|
rb_str_concat(ptr->string, c);
|
||||||
p += clen;
|
ptr->pos--;
|
||||||
lpos++;
|
}
|
||||||
|
else {
|
||||||
|
/* get logical position */
|
||||||
|
lpos = 0; p = RSTRING_PTR(ptr->string); pend = p + ptr->pos;
|
||||||
|
for (;;) {
|
||||||
|
clen = rb_enc_mbclen(p, pend, enc);
|
||||||
|
if (p+clen >= pend) break;
|
||||||
|
p += clen;
|
||||||
|
lpos++;
|
||||||
|
}
|
||||||
|
clen = p - RSTRING_PTR(ptr->string);
|
||||||
|
rb_str_update(ptr->string, lpos, ptr->pos ? 1 : 0, c);
|
||||||
|
ptr->pos = clen;
|
||||||
}
|
}
|
||||||
clen = p - RSTRING_PTR(ptr->string);
|
|
||||||
rb_str_update(ptr->string, lpos, ptr->pos ? 1 : 0, c);
|
|
||||||
ptr->pos = clen;
|
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue