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

Side by Side Diff: packages/string_scanner/lib/src/eager_span_scanner.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 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 unified diff | Download patch
« no previous file with comments | « packages/string_scanner/CHANGELOG.md ('k') | packages/string_scanner/lib/src/exception.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library string_scanner.eager_span_scanner;
6
7 import 'package:charcode/ascii.dart'; 5 import 'package:charcode/ascii.dart';
8 6
9 import 'line_scanner.dart'; 7 import 'line_scanner.dart';
10 import 'span_scanner.dart'; 8 import 'span_scanner.dart';
11 9
12 // TODO(nweiz): Currently this duplicates code in line_scanner.dart. Once 10 // TODO(nweiz): Currently this duplicates code in line_scanner.dart. Once
13 // sdk#23770 is fully complete, we should move the shared code into a mixin. 11 // sdk#23770 is fully complete, we should move the shared code into a mixin.
14 12
15 /// A regular expression matching newlines across platforms. 13 /// A regular expression matching newlines across platforms.
16 final _newlineRegExp = new RegExp(r"\r\n?|\n"); 14 final _newlineRegExp = new RegExp(r"\r\n?|\n");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } else { 60 } else {
63 _column = newPosition - 61 _column = newPosition -
64 string.lastIndexOf(_newlineRegExp, newPosition) - 1; 62 string.lastIndexOf(_newlineRegExp, newPosition) - 1;
65 } 63 }
66 } 64 }
67 } 65 }
68 66
69 EagerSpanScanner(String string, {sourceUrl, int position}) 67 EagerSpanScanner(String string, {sourceUrl, int position})
70 : super(string, sourceUrl: sourceUrl, position: position); 68 : super(string, sourceUrl: sourceUrl, position: position);
71 69
70 bool scanChar(int character) {
71 if (!super.scanChar(character)) return false;
72 _adjustLineAndColumn(character);
73 return true;
74 }
75
72 int readChar() { 76 int readChar() {
73 var char = super.readChar(); 77 var character = super.readChar();
74 if (char == $lf || (char == $cr && peekChar() != $lf)) { 78 _adjustLineAndColumn(character);
79 return character;
80 }
81
82 /// Adjusts [_line] and [_column] after having consumed [character].
83 void _adjustLineAndColumn(int character) {
84 if (character == $lf || (character == $cr && peekChar() != $lf)) {
75 _line += 1; 85 _line += 1;
76 _column = 0; 86 _column = 0;
77 } else { 87 } else {
78 _column += 1; 88 _column += 1;
79 } 89 }
80 return char;
81 } 90 }
82 91
83 bool scan(Pattern pattern) { 92 bool scan(Pattern pattern) {
84 if (!super.scan(pattern)) return false; 93 if (!super.scan(pattern)) return false;
85 94
86 var newlines = _newlinesIn(lastMatch[0]); 95 var newlines = _newlinesIn(lastMatch[0]);
87 _line += newlines.length; 96 _line += newlines.length;
88 if (newlines.isEmpty) { 97 if (newlines.isEmpty) {
89 _column += lastMatch[0].length; 98 _column += lastMatch[0].length;
90 } else { 99 } else {
(...skipping 15 matching lines...) Expand all
106 /// A class representing the state of an [EagerSpanScanner]. 115 /// A class representing the state of an [EagerSpanScanner].
107 class _EagerSpanScannerState implements LineScannerState { 116 class _EagerSpanScannerState implements LineScannerState {
108 final EagerSpanScanner _scanner; 117 final EagerSpanScanner _scanner;
109 final int position; 118 final int position;
110 final int line; 119 final int line;
111 final int column; 120 final int column;
112 121
113 _EagerSpanScannerState(this._scanner, this.position, this.line, this.column); 122 _EagerSpanScannerState(this._scanner, this.position, this.line, this.column);
114 } 123 }
115 124
OLDNEW
« no previous file with comments | « packages/string_scanner/CHANGELOG.md ('k') | packages/string_scanner/lib/src/exception.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698