Sha256: 092c111c0690777261f7d8353220782116363d1cf7e9c01aaea0a37495bcc6b4
Contents?: true
Size: 1.12 KB
Versions: 3
Compression:
Stored size: 1.12 KB
Contents
class StringScanner def initialize(str) `self._str = str; self._at = 0; self._matched = ""; self._working_string = str;` nil end def scan(reg) `reg = new RegExp('^' + reg.toString().substr(1, reg.toString().length - 2)); var res = reg.exec(self._working_string); if (res == null) { self.matched = ""; return false; } else if (typeof res == 'object') { self._at += res[0].length; self._working_string = self._working_string.substr(res[0].length); self._matched = res[0]; return res[0]; } else if (typeof res == 'string') { self._at += res.length; self._working_string = self._working_string.substr(res.length); return res; } else { return false; }` end def check(reg) `reg = new RegExp('^' + reg.toString().substr(1, reg.toString().length - 2)); return reg.exec(self._working_string) ? true : false;` end def peek(len) `return self._working_string.substr(0, len);` end def eos? `return self._working_string.length == 0;` end def matched `return self._matched;` end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
opal-0.3.11 | stdlib/strscan.rb |
opal-0.3.10 | stdlib/strscan.rb |
opal-0.3.9 | stdlib/strscan.rb |