/*
* Returns a string that represents the StringScanner object, showing:
* - the current position
* - the size of the string
* - the characters surrounding the scan pointer
*
* s = StringScanner.new("Fri Dec 12 1975 14:39")
* s.inspect # -> '#<StringScanner 0/21 @ "Fri D...">'
* s.scan_until /12/ # -> "Fri Dec 12"
* s.inspect # -> '
*/
static VALUE
strscan_inspect(VALUE self)
{
struct strscanner *p;
char buf[BUFSIZE];
long len;
VALUE a, b;
Data_Get_Struct(self, struct strscanner, p);
if (NIL_P(p->str)) {
len = snprintf(buf, BUFSIZE, "#<%s (uninitialized)>",
rb_class2name(CLASS_OF(self)));
return infect(rb_str_new(buf, len), p);
}
if (EOS_P(p)) {
len = snprintf(buf, BUFSIZE, "#<%s fin>",
rb_class2name(CLASS_OF(self)));
return infect(rb_str_new(buf, len), p);
}
if (p->curr == 0) {
b = inspect2(p);
len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld @ %s>",
rb_class2name(CLASS_OF(self)),
p->curr, S_LEN(p),
RSTRING(b)->ptr);
return infect(rb_str_new(buf, len), p);
}
a = inspect1(p);
b = inspect2(p);
len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld %s @ %s>",
rb_class2name(CLASS_OF(self)),
p->curr, S_LEN(p),
RSTRING(a)->ptr,
RSTRING(b)->ptr);
return infect(rb_str_new(buf, len), p);
}