OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.utils; | |
6 | |
7 /// Validates the arguments passed to [StringScanner.error]. | 5 /// Validates the arguments passed to [StringScanner.error]. |
8 void validateErrorArgs(String string, Match match, int position, int length) { | 6 void validateErrorArgs(String string, Match match, int position, int length) { |
9 if (match != null && (position != null || length != null)) { | 7 if (match != null && (position != null || length != null)) { |
10 throw new ArgumentError("Can't pass both match and position/length."); | 8 throw new ArgumentError("Can't pass both match and position/length."); |
11 } | 9 } |
12 | 10 |
13 if (position != null) { | 11 if (position != null) { |
14 if (position < 0) { | 12 if (position < 0) { |
15 throw new RangeError("position must be greater than or equal to 0."); | 13 throw new RangeError("position must be greater than or equal to 0."); |
16 } else if (position > string.length) { | 14 } else if (position > string.length) { |
17 throw new RangeError("position must be less than or equal to the " | 15 throw new RangeError("position must be less than or equal to the " |
18 "string length."); | 16 "string length."); |
19 } | 17 } |
20 } | 18 } |
21 | 19 |
22 if (length != null && length < 0) { | 20 if (length != null && length < 0) { |
23 throw new RangeError("length must be greater than or equal to 0."); | 21 throw new RangeError("length must be greater than or equal to 0."); |
24 } | 22 } |
25 | 23 |
26 if (position != null && length != null && position + length > string.length) { | 24 if (position != null && length != null && position + length > string.length) { |
27 throw new RangeError("position plus length must not go beyond the end of " | 25 throw new RangeError("position plus length must not go beyond the end of " |
28 "the string."); | 26 "the string."); |
29 } | 27 } |
30 } | 28 } |
OLD | NEW |