Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(630)

Unified Diff: lib/src/line_scanner.dart

Issue 2041813002: Add StringScanner.scanChar() and .expectChar(). (Closed) Base URL: git@github.com:dart-lang/string_scanner@master
Patch Set: Code review changes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/eager_span_scanner.dart ('k') | lib/src/string_scanner.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/line_scanner.dart
diff --git a/lib/src/line_scanner.dart b/lib/src/line_scanner.dart
index b4391934d0ba338ab9b7d30effa6453eb6f975f4..fe6359212c303d6900050f3c9db1ec5dfc84d66a 100644
--- a/lib/src/line_scanner.dart
+++ b/lib/src/line_scanner.dart
@@ -73,15 +73,26 @@ class LineScanner extends StringScanner {
LineScanner(String string, {sourceUrl, int position})
: super(string, sourceUrl: sourceUrl, position: position);
+ bool scanChar(int character) {
+ if (!super.scanChar(character)) return false;
+ _adjustLineAndColumn(character);
+ return true;
+ }
+
int readChar() {
- var char = super.readChar();
- if (char == $lf || (char == $cr && peekChar() != $lf)) {
+ var character = super.readChar();
+ _adjustLineAndColumn(character);
+ return character;
+ }
+
+ /// Adjusts [_line] and [_column] after having consumed [character].
+ void _adjustLineAndColumn(int character) {
+ if (character == $lf || (character == $cr && peekChar() != $lf)) {
_line += 1;
_column = 0;
} else {
_column += 1;
}
- return char;
}
bool scan(Pattern pattern) {
« no previous file with comments | « lib/src/eager_span_scanner.dart ('k') | lib/src/string_scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698