mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/stringio/stringio.c (strio_close, strio_close_read, strio_close_write):
should return nil instead of self as well as IO. [ruby-dev:25623] * ext/stringio/stringio.c (strio_extend, strio_putc): fill with zero extended portion. [ruby-dev:25626] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e849cce8a0
commit
0a1cd99af2
2 changed files with 41 additions and 30 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Thu Feb 3 23:42:36 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/stringio/stringio.c (strio_close, strio_close_read, strio_close_write):
|
||||||
|
should return nil instead of self as well as IO. [ruby-dev:25623]
|
||||||
|
|
||||||
|
* ext/stringio/stringio.c (strio_extend, strio_putc): fill with zero
|
||||||
|
extended portion. [ruby-dev:25626]
|
||||||
|
|
||||||
Wed Feb 3 03:31:20 2005 NARUSE, Yui <naruse@ruby-lang.org>
|
Wed Feb 3 03:31:20 2005 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* ext/nkf/nkf-utf8/nkf.c: follow original v 1.57
|
* ext/nkf/nkf-utf8/nkf.c: follow original v 1.57
|
||||||
|
|
|
@ -339,7 +339,7 @@ strio_close(self)
|
||||||
}
|
}
|
||||||
ptr->string = Qnil;
|
ptr->string = Qnil;
|
||||||
ptr->flags &= ~FMODE_READWRITE;
|
ptr->flags &= ~FMODE_READWRITE;
|
||||||
return self;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -353,7 +353,7 @@ strio_close_read(self)
|
||||||
if (!((ptr->flags &= ~FMODE_READABLE) & FMODE_READWRITE)) {
|
if (!((ptr->flags &= ~FMODE_READABLE) & FMODE_READWRITE)) {
|
||||||
ptr->string = Qnil;
|
ptr->string = Qnil;
|
||||||
}
|
}
|
||||||
return self;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -367,7 +367,7 @@ strio_close_write(self)
|
||||||
if (!((ptr->flags &= ~FMODE_WRITABLE) & FMODE_READWRITE)) {
|
if (!((ptr->flags &= ~FMODE_WRITABLE) & FMODE_READWRITE)) {
|
||||||
ptr->string = Qnil;
|
ptr->string = Qnil;
|
||||||
}
|
}
|
||||||
return self;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -559,6 +559,25 @@ strio_getc(self)
|
||||||
return CHR2FIX(c);
|
return CHR2FIX(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
strio_extend(ptr, pos, len)
|
||||||
|
struct StringIO *ptr;
|
||||||
|
long pos, len;
|
||||||
|
{
|
||||||
|
long olen;
|
||||||
|
|
||||||
|
check_modifiable(ptr);
|
||||||
|
olen = RSTRING(ptr->string)->len;
|
||||||
|
if (pos + len > olen) {
|
||||||
|
rb_str_resize(ptr->string, pos + len);
|
||||||
|
if (pos > olen)
|
||||||
|
MEMZERO(RSTRING(ptr->string)->ptr + olen, char, pos - olen);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_str_modify(ptr->string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
strio_ungetc(self, ch)
|
strio_ungetc(self, ch)
|
||||||
VALUE self, ch;
|
VALUE self, ch;
|
||||||
|
@ -568,18 +587,11 @@ strio_ungetc(self, ch)
|
||||||
long len, pos = ptr->pos;
|
long len, pos = ptr->pos;
|
||||||
|
|
||||||
if (cc != EOF && pos > 0) {
|
if (cc != EOF && pos > 0) {
|
||||||
if ((len = RSTRING(ptr->string)->len) < pos ||
|
if ((len = RSTRING(ptr->string)->len) < pos-- ||
|
||||||
(unsigned char)RSTRING(ptr->string)->ptr[pos - 1] !=
|
(unsigned char)RSTRING(ptr->string)->ptr[pos] !=
|
||||||
(unsigned char)cc) {
|
(unsigned char)cc) {
|
||||||
check_modifiable(ptr);
|
strio_extend(ptr, pos, 1);
|
||||||
if (len < pos) {
|
RSTRING(ptr->string)->ptr[pos] = cc;
|
||||||
rb_str_resize(ptr->string, pos);
|
|
||||||
MEMZERO(RSTRING(ptr->string)->ptr + len, char, pos - len - 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
rb_str_modify(ptr->string);
|
|
||||||
}
|
|
||||||
RSTRING(ptr->string)->ptr[pos - 1] = cc;
|
|
||||||
OBJ_INFECT(ptr->string, self);
|
OBJ_INFECT(ptr->string, self);
|
||||||
}
|
}
|
||||||
--ptr->pos;
|
--ptr->pos;
|
||||||
|
@ -784,13 +796,7 @@ strio_write(self, str)
|
||||||
rb_str_cat(ptr->string, RSTRING(str)->ptr, len);
|
rb_str_cat(ptr->string, RSTRING(str)->ptr, len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (ptr->pos + len > olen) {
|
strio_extend(ptr, ptr->pos, len);
|
||||||
rb_str_resize(ptr->string, ptr->pos + len);
|
|
||||||
MEMZERO(RSTRING(ptr->string)->ptr + olen, char, ptr->pos + len - olen);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
rb_str_modify(ptr->string);
|
|
||||||
}
|
|
||||||
rb_str_update(ptr->string, ptr->pos, len, str);
|
rb_str_update(ptr->string, ptr->pos, len, str);
|
||||||
}
|
}
|
||||||
OBJ_INFECT(ptr->string, self);
|
OBJ_INFECT(ptr->string, self);
|
||||||
|
@ -810,17 +816,14 @@ strio_putc(self, ch)
|
||||||
{
|
{
|
||||||
struct StringIO *ptr = writable(StringIO(self));
|
struct StringIO *ptr = writable(StringIO(self));
|
||||||
int c = NUM2CHR(ch);
|
int c = NUM2CHR(ch);
|
||||||
|
long olen;
|
||||||
|
|
||||||
check_modifiable(ptr);
|
check_modifiable(ptr);
|
||||||
|
olen = RSTRING(ptr->string)->len;
|
||||||
if (ptr->flags & FMODE_APPEND) {
|
if (ptr->flags & FMODE_APPEND) {
|
||||||
ptr->pos = RSTRING(ptr->string)->len;
|
ptr->pos = olen;
|
||||||
}
|
|
||||||
if (ptr->pos >= RSTRING(ptr->string)->len) {
|
|
||||||
rb_str_resize(ptr->string, ptr->pos + 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
rb_str_modify(ptr->string);
|
|
||||||
}
|
}
|
||||||
|
strio_extend(ptr, ptr->pos, 1);
|
||||||
RSTRING(ptr->string)->ptr[ptr->pos++] = c;
|
RSTRING(ptr->string)->ptr[ptr->pos++] = c;
|
||||||
OBJ_INFECT(ptr->string, self);
|
OBJ_INFECT(ptr->string, self);
|
||||||
return ch;
|
return ch;
|
||||||
|
|
Loading…
Reference in a new issue