Line data Source code
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 3 : // BSD-style license that can be found in the LICENSE file. 4 : 5 : import 'string_scanner.dart'; 6 : 7 : /// Validates the arguments passed to [StringScanner.error]. 8 0 : void validateErrorArgs( 9 : String string, Match? match, int? position, int? length) { 10 : if (match != null && (position != null || length != null)) { 11 0 : throw ArgumentError("Can't pass both match and position/length."); 12 : } 13 : 14 : if (position != null) { 15 0 : if (position < 0) { 16 0 : throw RangeError('position must be greater than or equal to 0.'); 17 0 : } else if (position > string.length) { 18 0 : throw RangeError('position must be less than or equal to the ' 19 : 'string length.'); 20 : } 21 : } 22 : 23 0 : if (length != null && length < 0) { 24 0 : throw RangeError('length must be greater than or equal to 0.'); 25 : } 26 : 27 0 : if (position != null && length != null && position + length > string.length) { 28 0 : throw RangeError('position plus length must not go beyond the end of ' 29 : 'the string.'); 30 : } 31 : }