| 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 part of intl; | 6 part of intl; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * A class for holding onto the data for a date so that it can be built | 9 * A class for holding onto the data for a date so that it can be built |
| 10 * up incrementally. | 10 * up incrementally. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 _Stream(this.contents); | 117 _Stream(this.contents); |
| 118 | 118 |
| 119 bool atEnd() => index >= contents.length; | 119 bool atEnd() => index >= contents.length; |
| 120 | 120 |
| 121 next() => contents[index++]; | 121 next() => contents[index++]; |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Return the next [howMany] items, or as many as there are remaining. | 124 * Return the next [howMany] items, or as many as there are remaining. |
| 125 * Advance the stream by that many positions. | 125 * Advance the stream by that many positions. |
| 126 */ | 126 */ |
| 127 read([howMany = 1]) { | 127 read([int howMany = 1]) { |
| 128 var result = peek(howMany); | 128 var result = peek(howMany); |
| 129 index += howMany; | 129 index += howMany; |
| 130 return result; | 130 return result; |
| 131 } | 131 } |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * Does the input start with the given string, if we start from the | 134 * Does the input start with the given string, if we start from the |
| 135 * current position. | 135 * current position. |
| 136 */ | 136 */ |
| 137 bool startsWith(String pattern) { | 137 bool startsWith(String pattern) { |
| 138 if (contents is String) return contents.startsWith(pattern, index); | 138 if (contents is String) return contents.startsWith(pattern, index); |
| 139 return pattern == peek(pattern.length); | 139 return pattern == peek(pattern.length); |
| 140 } | 140 } |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Return the next [howMany] items, or as many as there are remaining. | 143 * Return the next [howMany] items, or as many as there are remaining. |
| 144 * Does not modify the stream position. | 144 * Does not modify the stream position. |
| 145 */ | 145 */ |
| 146 peek([howMany = 1]) { | 146 peek([int howMany = 1]) { |
| 147 var result; | 147 var result; |
| 148 if (contents is String) { | 148 if (contents is String) { |
| 149 result = contents.substring( | 149 result = contents.substring( |
| 150 index, | 150 index, |
| 151 min(index + howMany, contents.length)); | 151 min(index + howMany, contents.length)); |
| 152 } else { | 152 } else { |
| 153 // Assume List | 153 // Assume List |
| 154 result = contents.sublist(index, index + howMany); | 154 result = contents.sublist(index, index + howMany); |
| 155 } | 155 } |
| 156 return result; | 156 return result; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 187 * can see and then return the corresponding integer. Advance the stream. | 187 * can see and then return the corresponding integer. Advance the stream. |
| 188 */ | 188 */ |
| 189 var digitMatcher = new RegExp(r'\d+'); | 189 var digitMatcher = new RegExp(r'\d+'); |
| 190 int nextInteger() { | 190 int nextInteger() { |
| 191 var string = digitMatcher.stringMatch(rest()); | 191 var string = digitMatcher.stringMatch(rest()); |
| 192 if (string == null || string.isEmpty) return null; | 192 if (string == null || string.isEmpty) return null; |
| 193 read(string.length); | 193 read(string.length); |
| 194 return int.parse(string); | 194 return int.parse(string); |
| 195 } | 195 } |
| 196 } | 196 } |
| OLD | NEW |