OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:charcode/ascii.dart'; | 5 import 'package:charcode/ascii.dart'; |
6 | 6 |
7 import 'string_scanner.dart'; | 7 import 'string_scanner.dart'; |
8 | 8 |
9 // Note that much of this code is duplicated in eager_span_scanner.dart. | 9 // Note that much of this code is duplicated in eager_span_scanner.dart. |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 } else { | 66 } else { |
67 _column = newPosition - | 67 _column = newPosition - |
68 string.lastIndexOf(_newlineRegExp, newPosition) - 1; | 68 string.lastIndexOf(_newlineRegExp, newPosition) - 1; |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 LineScanner(String string, {sourceUrl, int position}) | 73 LineScanner(String string, {sourceUrl, int position}) |
74 : super(string, sourceUrl: sourceUrl, position: position); | 74 : super(string, sourceUrl: sourceUrl, position: position); |
75 | 75 |
76 bool scanChar(int character) { | |
77 if (!super.scanChar(character)) return false; | |
78 if (character == $lf || (character == $cr && peekChar() != $lf)) { | |
Jennifer Messerly
2016/06/06 23:46:51
Would it be worth a doc comment on what the behavi
| |
79 _line += 1; | |
80 _column = 0; | |
81 } else { | |
82 _column += 1; | |
83 } | |
84 return true; | |
85 } | |
86 | |
76 int readChar() { | 87 int readChar() { |
77 var char = super.readChar(); | 88 var char = super.readChar(); |
78 if (char == $lf || (char == $cr && peekChar() != $lf)) { | 89 if (char == $lf || (char == $cr && peekChar() != $lf)) { |
79 _line += 1; | 90 _line += 1; |
80 _column = 0; | 91 _column = 0; |
81 } else { | 92 } else { |
82 _column += 1; | 93 _column += 1; |
83 } | 94 } |
84 return char; | 95 return char; |
85 } | 96 } |
(...skipping 30 matching lines...) Expand all Loading... | |
116 final int position; | 127 final int position; |
117 | 128 |
118 /// The zero-based line number of the scanner in this state. | 129 /// The zero-based line number of the scanner in this state. |
119 final int line; | 130 final int line; |
120 | 131 |
121 /// The zero-based column number of the scanner in this state. | 132 /// The zero-based column number of the scanner in this state. |
122 final int column; | 133 final int column; |
123 | 134 |
124 LineScannerState._(this._scanner, this.position, this.line, this.column); | 135 LineScannerState._(this._scanner, this.position, this.line, this.column); |
125 } | 136 } |
OLD | NEW |