peek(p1)
public
Show source
/*
* call-seq: peek(len)
*
* Extracts a string corresponding to <tt>string[pos,len]</tt>, without
* advancing the scan pointer.
*
* s = StringScanner.new('test string')
* s.peek(7)
* s.peek(7)
*
*/
static VALUE
strscan_peek(VALUE self, VALUE vlen)
{
struct strscanner *p;
long len;
GET_SCANNER(self, p);
len = NUM2LONG(vlen);
if (EOS_P(p)) {
return infect(rb_str_new("", 0), p);
}
if (p->curr + len > S_LEN(p)) {
len = S_LEN(p) - p->curr;
}
return extract_beg_len(p, p->curr, len);
}