| OLD | NEW |
| 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 import 'package:string_scanner/string_scanner.dart'; | 5 import 'package:string_scanner/string_scanner.dart'; |
| 6 | 6 |
| 7 /// A regular expression that matches text until a letter or whitespace. | 7 /// A regular expression that matches text until a letter or whitespace. |
| 8 /// | 8 /// |
| 9 /// This is intended to scan through a number without actually encoding the full | 9 /// This is intended to scan through a number without actually encoding the full |
| 10 /// Dart number grammar. It doesn't stop on "e" because that can be a component | 10 /// Dart number grammar. It doesn't stop on "e" because that can be a component |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 var number = double.parse(scanner.lastMatch[0]); | 82 var number = double.parse(scanner.lastMatch[0]); |
| 83 | 83 |
| 84 // A number followed by "x" is a scale factor. | 84 // A number followed by "x" is a scale factor. |
| 85 if (scanner.scan("x") || scanner.scan("X")) { | 85 if (scanner.scan("x") || scanner.scan("X")) { |
| 86 scanner.expectDone(); | 86 scanner.expectDone(); |
| 87 return new Timeout.factor(number); | 87 return new Timeout.factor(number); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Parse time units until none are left. The condition is in the middle of | 90 // Parse time units until none are left. The condition is in the middle of |
| 91 // the loop because we've already parsed the first number. | 91 // the loop because we've already parsed the first number. |
| 92 var microseconds = 0; | 92 var microseconds = 0.0; |
| 93 while (true) { | 93 while (true) { |
| 94 scanner.expect(_unit, name: "unit"); | 94 scanner.expect(_unit, name: "unit"); |
| 95 microseconds += _microsecondsFor(number, scanner.lastMatch[0]); | 95 microseconds += _microsecondsFor(number, scanner.lastMatch[0]); |
| 96 | 96 |
| 97 scanner.scan(_whitespace); | 97 scanner.scan(_whitespace); |
| 98 | 98 |
| 99 // Scan the next number, if it's avaialble. | 99 // Scan the next number, if it's avaialble. |
| 100 if (!scanner.scan(_untilUnit)) break; | 100 if (!scanner.scan(_untilUnit)) break; |
| 101 number = double.parse(scanner.lastMatch[0]); | 101 number = double.parse(scanner.lastMatch[0]); |
| 102 } | 102 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 bool operator==(other) => other is Timeout && other.duration == duration && | 144 bool operator==(other) => other is Timeout && other.duration == duration && |
| 145 other.scaleFactor == scaleFactor; | 145 other.scaleFactor == scaleFactor; |
| 146 | 146 |
| 147 String toString() { | 147 String toString() { |
| 148 if (duration != null) return duration.toString(); | 148 if (duration != null) return duration.toString(); |
| 149 if (scaleFactor != null) return "${scaleFactor}x"; | 149 if (scaleFactor != null) return "${scaleFactor}x"; |
| 150 return "none"; | 150 return "none"; |
| 151 } | 151 } |
| 152 } | 152 } |
| OLD | NEW |