OLD | NEW |
(Empty) | |
| 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 library glob.utils; |
| 6 |
| 7 /// A range from [min] to [max], inclusive. |
| 8 class Range { |
| 9 /// The minimum value included by the range. |
| 10 final int min; |
| 11 |
| 12 /// The maximum value included by the range. |
| 13 final int max; |
| 14 |
| 15 /// Whether this range covers only a single number. |
| 16 bool get isSingleton => min == max; |
| 17 |
| 18 Range(this.min, this.max); |
| 19 |
| 20 /// Returns a range that covers only [value]. |
| 21 Range.singleton(int value) |
| 22 : this(value, value); |
| 23 |
| 24 /// Whether [this] contains [value]. |
| 25 bool contains(int value) => value >= min && value <= max; |
| 26 } |
| 27 |
| 28 /// An implementation of [Match] constructed by [Glob]s. |
| 29 class GlobMatch implements Match { |
| 30 final String input; |
| 31 final Pattern pattern; |
| 32 final int start = 0; |
| 33 |
| 34 int get end => input.length; |
| 35 int get groupCount => 0; |
| 36 |
| 37 GlobMatch(this.input, this.pattern); |
| 38 |
| 39 String operator [](int group) => this.group(group); |
| 40 |
| 41 String group(int group) { |
| 42 if (group != 0) throw new RangeError.range(group, 0, 0); |
| 43 return input; |
| 44 } |
| 45 |
| 46 List<String> groups(List<int> groupIndices) => |
| 47 groupIndices.map((index) => group(index)).toList(); |
| 48 } |
| 49 |
| 50 final _quote = new RegExp(r"[+*?{}|[\]\\().^$-]"); |
| 51 |
| 52 /// Returns [contents] with characters that are meaningful in regular |
| 53 /// expressions backslash-escaped. |
| 54 String regExpQuote(String contents) => |
| 55 contents.replaceAllMapped(_quote, (char) => "\\${char[0]}"); |
OLD | NEW |