Method: StringScanner#peek
- Defined in:
- strscan.c
#peek(len) ⇒ Object
Extracts a string corresponding to string[pos,len], without advancing the scan pointer.
s = StringScanner.new('test string')
s.peek(7) # => "test st"
s.peek(7) # => "test st"
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
# File 'strscan.c', line 935
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 str_new(p, "", 0);
len = minl(len, S_RESTLEN(p));
return extract_beg_len(p, p->curr, len);
}
|