Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: pkg/glob/lib/src/utils.dart

Issue 506993004: Create a glob package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/glob/lib/src/parser.dart ('k') | pkg/glob/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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]}");
OLDNEW
« no previous file with comments | « pkg/glob/lib/src/parser.dart ('k') | pkg/glob/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698