OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * A class for holding onto the data for a date so that it can be built | 6 * A class for holding onto the data for a date so that it can be built |
7 * up incrementally. | 7 * up incrementally. |
8 */ | 8 */ |
9 class _DateBuilder { | 9 class _DateBuilder { |
10 int year = 0, | 10 int year = 0, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 /** | 81 /** |
82 * Return the next [howMany] items, or as many as there are remaining. | 82 * Return the next [howMany] items, or as many as there are remaining. |
83 * Does not modify the stream position. | 83 * Does not modify the stream position. |
84 */ | 84 */ |
85 peek([howMany = 1]) { | 85 peek([howMany = 1]) { |
86 var result; | 86 var result; |
87 if (contents is String) { | 87 if (contents is String) { |
88 result = contents.substring( | 88 result = contents.substring( |
89 index, | 89 index, |
90 Math.min(index + howMany, contents.length)); | 90 min(index + howMany, contents.length)); |
91 } else { | 91 } else { |
92 // Assume List | 92 // Assume List |
93 result = contents.getRange(index, howMany); | 93 result = contents.getRange(index, howMany); |
94 } | 94 } |
95 return result; | 95 return result; |
96 } | 96 } |
97 | 97 |
98 /** Return the remaining contents of the stream */ | 98 /** Return the remaining contents of the stream */ |
99 rest() => peek(contents.length - index); | 99 rest() => peek(contents.length - index); |
100 | 100 |
(...skipping 25 matching lines...) Expand all Loading... |
126 * can see and then return the corresponding integer. Advance the stream. | 126 * can see and then return the corresponding integer. Advance the stream. |
127 */ | 127 */ |
128 var digitMatcher = const RegExp(@'\d'); | 128 var digitMatcher = const RegExp(@'\d'); |
129 int nextInteger() { | 129 int nextInteger() { |
130 // Doing this with a regular expression is slightly slower on the VM, | 130 // Doing this with a regular expression is slightly slower on the VM, |
131 // but makes a moderate difference in Javascript right now. | 131 // but makes a moderate difference in Javascript right now. |
132 var digits = []; | 132 var digits = []; |
133 while (!atEnd() && (digitMatcher.hasMatch(peek()))) { | 133 while (!atEnd() && (digitMatcher.hasMatch(peek()))) { |
134 digits.add(next().charCodeAt(0)); | 134 digits.add(next().charCodeAt(0)); |
135 } | 135 } |
136 return Math.parseInt(new String.fromCharCodes(digits)); | 136 return parseInt(new String.fromCharCodes(digits)); |
137 } | 137 } |
138 } | 138 } |
OLD | NEW |