OLD | NEW |
(Empty) | |
| 1 part of mustache; |
| 2 |
| 3 class _CharReader { |
| 4 |
| 5 String _source; |
| 6 Iterator<int> _itr; |
| 7 int _i, _c; |
| 8 int _line = 1, _column = 1; |
| 9 |
| 10 _CharReader(String source) |
| 11 : _source = source, |
| 12 _itr = source.runes.iterator { //FIXME runes etc. Not sure if this is t
he right count. |
| 13 |
| 14 if (source == null) |
| 15 throw new ArgumentError('Source is null.'); |
| 16 |
| 17 _i = 0; |
| 18 |
| 19 if (source == '') { |
| 20 _c = _EOF; |
| 21 } else { |
| 22 _itr.moveNext(); |
| 23 _c = _itr.current; |
| 24 } |
| 25 } |
| 26 |
| 27 int get line => _line; |
| 28 int get column => _column; |
| 29 |
| 30 int read() { |
| 31 var c = _c; |
| 32 if (_itr.moveNext()) { |
| 33 _i++; |
| 34 _c = _itr.current; |
| 35 } else { |
| 36 _c = _EOF; |
| 37 } |
| 38 |
| 39 if (c == _NEWLINE) { |
| 40 _line++; |
| 41 _column = 1; |
| 42 } else { |
| 43 _column++; |
| 44 } |
| 45 |
| 46 return c; |
| 47 } |
| 48 |
| 49 int peek() => _c; |
| 50 |
| 51 String readWhile(bool test(int charCode)) { |
| 52 |
| 53 if (peek() == _EOF) |
| 54 throw new MustacheFormatException('Unexpected end of input.', line, column
); |
| 55 |
| 56 int start = _i; |
| 57 |
| 58 while (peek() != _EOF && test(peek())) { |
| 59 read(); |
| 60 } |
| 61 |
| 62 int end = peek() == _EOF ? _source.length : _i; |
| 63 return _source.substring(start, end); |
| 64 } |
| 65 } |
OLD | NEW |