pos=(p1)
public
Show source
/*
* call-seq: pos=(n)
*
* Modify the scan pointer.
*
* s = StringScanner.new('test string')
* s.pos = 7 # -> 7
* s.rest # -> "ring"
*/
static VALUE
strscan_set_pos(VALUE self, VALUE v)
{
struct strscanner *p;
long i;
GET_SCANNER(self, p);
i = NUM2INT(v);
if (i < 0) i += S_LEN(p);
if (i < 0) rb_raise(rb_eRangeError, "index out of range");
if (i > S_LEN(p)) rb_raise(rb_eRangeError, "index out of range");
p->curr = i;
return INT2NUM(i);
}