Method: StringScanner#unscan
- Defined in:
- strscan.c
#unscan ⇒ Object
Set the scan pointer to the previous position. Only one previous position is remembered, and it changes with each scanning operation.
s = StringScanner.new('test string')
s.scan(/\w+/) # => "test"
s.unscan
s.scan(/../) # => "te"
s.scan(/\d/) # => nil
s.unscan # ScanError: unscan failed: previous match record not exist
837 838 839 840 841 842 843 844 845 846 847 848 |
# File 'strscan.c', line 837
static VALUE
strscan_unscan(VALUE self)
{
struct strscanner *p;
GET_SCANNER(self, p);
if (! MATCHED_P(p))
rb_raise(ScanError, "unscan failed: previous match record not exist");
p->curr = p->prev;
CLEAR_MATCH_STATUS(p);
return self;
}
|