| 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 glob.utils; | 5 library glob.utils; |
| 6 | 6 |
| 7 import 'package:path/path.dart' as p; |
| 8 |
| 7 /// A range from [min] to [max], inclusive. | 9 /// A range from [min] to [max], inclusive. |
| 8 class Range { | 10 class Range { |
| 9 /// The minimum value included by the range. | 11 /// The minimum value included by the range. |
| 10 final int min; | 12 final int min; |
| 11 | 13 |
| 12 /// The maximum value included by the range. | 14 /// The maximum value included by the range. |
| 13 final int max; | 15 final int max; |
| 14 | 16 |
| 15 /// Whether this range covers only a single number. | 17 /// Whether this range covers only a single number. |
| 16 bool get isSingleton => min == max; | 18 bool get isSingleton => min == max; |
| 17 | 19 |
| 18 Range(this.min, this.max); | 20 Range(this.min, this.max); |
| 19 | 21 |
| 20 /// Returns a range that covers only [value]. | 22 /// Returns a range that covers only [value]. |
| 21 Range.singleton(int value) | 23 Range.singleton(int value) |
| 22 : this(value, value); | 24 : this(value, value); |
| 23 | 25 |
| 24 /// Whether [this] contains [value]. | 26 /// Whether [this] contains [value]. |
| 25 bool contains(int value) => value >= min && value <= max; | 27 bool contains(int value) => value >= min && value <= max; |
| 28 |
| 29 bool operator==(Object other) => other is Range && |
| 30 other.min == min && other.max == max; |
| 31 |
| 32 int get hashCode => 3 * min + 7 * max; |
| 26 } | 33 } |
| 27 | 34 |
| 28 /// An implementation of [Match] constructed by [Glob]s. | 35 /// An implementation of [Match] constructed by [Glob]s. |
| 29 class GlobMatch implements Match { | 36 class GlobMatch implements Match { |
| 30 final String input; | 37 final String input; |
| 31 final Pattern pattern; | 38 final Pattern pattern; |
| 32 final int start = 0; | 39 final int start = 0; |
| 33 | 40 |
| 34 int get end => input.length; | 41 int get end => input.length; |
| 35 int get groupCount => 0; | 42 int get groupCount => 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 46 List<String> groups(List<int> groupIndices) => | 53 List<String> groups(List<int> groupIndices) => |
| 47 groupIndices.map((index) => group(index)).toList(); | 54 groupIndices.map((index) => group(index)).toList(); |
| 48 } | 55 } |
| 49 | 56 |
| 50 final _quote = new RegExp(r"[+*?{}|[\]\\().^$-]"); | 57 final _quote = new RegExp(r"[+*?{}|[\]\\().^$-]"); |
| 51 | 58 |
| 52 /// Returns [contents] with characters that are meaningful in regular | 59 /// Returns [contents] with characters that are meaningful in regular |
| 53 /// expressions backslash-escaped. | 60 /// expressions backslash-escaped. |
| 54 String regExpQuote(String contents) => | 61 String regExpQuote(String contents) => |
| 55 contents.replaceAllMapped(_quote, (char) => "\\${char[0]}"); | 62 contents.replaceAllMapped(_quote, (char) => "\\${char[0]}"); |
| 63 |
| 64 /// Returns [path] with all its separators replaced with forward slashes. |
| 65 /// |
| 66 /// This is useful when converting from Windows paths to globs. |
| 67 String separatorToForwardSlash(String path) { |
| 68 if (p.context != p.Style.windows) return path; |
| 69 return path.replaceAll('\\', '/'); |
| 70 } |
| OLD | NEW |