getch()
public
Show source
/*
* Scans one character and returns it.
* This method is multi-byte character sensitive.
* See also #get_byte.
*
* s = StringScanner.new('ab')
* s.getch # => "a"
* s.getch # => "b"
* s.getch # => nil
*
* $KCODE = 'EUC'
* s = StringScanner.new("\244\242")
* s.getch # => "\244\242" # Japanese hira-kana "A" in EUC-JP
* s.getch # => nil
*/
static VALUE
strscan_getch(VALUE self)
{
struct strscanner *p;
long len;
GET_SCANNER(self, p);
CLEAR_MATCH_STATUS(p);
if (EOS_P(p))
return Qnil;
len = mbclen(*CURPTR(p));
if (p->curr + len > S_LEN(p)) {
len = S_LEN(p) - p->curr;
}
p->prev = p->curr;
p->curr += len;
MATCHED(p);
adjust_registers_to_matched(p);
return extract_range(p, p->prev + p->regs.beg[0],
p->prev + p->regs.end[0]);
}