method
ungetbyte
v1_9_1_378 -
Show latest stable
- Class:
StringIO
ungetbyte(p1)public
See IO#ungetbyte
static VALUE
strio_ungetbyte(VALUE self, VALUE c)
{
struct StringIO *ptr = readable(StringIO(self));
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;
} Related methods
- Instance methods
- <<
- binmode
- bytes
- chars
- close
- close_read
- close_write
- closed?
- closed_read?
- closed_write?
- each
- each_byte
- each_char
- each_line
- eof
- eof?
- external_encoding
- fcntl
- fileno
- flush
- fsync
- getbyte
- getc
- gets
- initialize_copy
- internal_encoding
- isatty
- length
- lineno
- lineno=
- lines
- path
- pid
- pos
- pos=
- printf
- putc
- puts
- read
- readbyte
- readchar
- readline
- readlines
- readpartial
- reopen
- rewind
- seek
- set_encoding
- size
- string
- string=
- sync
- sync=
- sysread
- syswrite
- tell
- truncate
- tty?
- ungetbyte
- ungetc
- write
- Class methods
- new
- new
- open