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

Side by Side Diff: lib/glob.dart

Issue 1491003002: Add a caseSensitive flag to new Glob(). (Closed) Base URL: git@github.com:dart-lang/glob@master
Patch Set: Code review changes Created 5 years 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
« no previous file with comments | « README.md ('k') | lib/src/ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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; 5 library glob;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
(...skipping 27 matching lines...) Expand all
38 /// The pattern used to create this glob. 38 /// The pattern used to create this glob.
39 final String pattern; 39 final String pattern;
40 40
41 /// The context in which paths matched against this glob are interpreted. 41 /// The context in which paths matched against this glob are interpreted.
42 final p.Context context; 42 final p.Context context;
43 43
44 /// If true, a path matches if it matches the glob itself or is recursively 44 /// If true, a path matches if it matches the glob itself or is recursively
45 /// contained within a directory that matches. 45 /// contained within a directory that matches.
46 final bool recursive; 46 final bool recursive;
47 47
48 /// Whether the glob matches paths case-sensitively.
49 bool get caseSensitive => _ast.caseSensitive;
50
48 /// The parsed AST of the glob. 51 /// The parsed AST of the glob.
49 final AstNode _ast; 52 final AstNode _ast;
50 53
51 ListTree _listTree; 54 ListTree _listTree;
52 55
53 /// Whether [context]'s current directory is absolute. 56 /// Whether [context]'s current directory is absolute.
54 bool get _contextIsAbsolute { 57 bool get _contextIsAbsolute {
55 if (_contextIsAbsoluteCache == null) { 58 if (_contextIsAbsoluteCache == null) {
56 _contextIsAbsoluteCache = context.isAbsolute(context.current); 59 _contextIsAbsoluteCache = context.isAbsolute(context.current);
57 } 60 }
(...skipping 22 matching lines...) Expand all
80 /// Returns [contents] with characters that are meaningful in globs 83 /// Returns [contents] with characters that are meaningful in globs
81 /// backslash-escaped. 84 /// backslash-escaped.
82 static String quote(String contents) => 85 static String quote(String contents) =>
83 contents.replaceAllMapped(_quoteRegExp, (match) => '\\${match[0]}'); 86 contents.replaceAllMapped(_quoteRegExp, (match) => '\\${match[0]}');
84 87
85 /// Creates a new glob with [pattern]. 88 /// Creates a new glob with [pattern].
86 /// 89 ///
87 /// Paths matched against the glob are interpreted according to [context]. It 90 /// Paths matched against the glob are interpreted according to [context]. It
88 /// defaults to the system context. 91 /// defaults to the system context.
89 /// 92 ///
90 /// If [recursive] is true, this glob will match and list not only the files 93 /// If [recursive] is true, this glob matches and lists not only the files and
91 /// and directories it explicitly lists, but anything beneath those as well. 94 /// directories it explicitly matches, but anything beneath those as well.
92 Glob(String pattern, {p.Context context, bool recursive: false}) 95 ///
93 : this._( 96 /// If [caseSensitive] is true, this glob matches and lists only files whose
94 pattern, 97 /// case matches that of the characters in the glob. Otherwise, it matches
95 context == null ? p.context : context, 98 /// regardless of case. This defaults to `false` when [context] is Windows and
96 recursive); 99 /// `true` otherwise.
100 factory Glob(String pattern, {p.Context context, bool recursive: false,
101 bool caseSensitive}) {
102 context ??= p.context;
103 caseSensitive ??= context.style == p.Style.windows ? false : true;
104 if (recursive) pattern += "{,/**}";
97 105
98 // Internal constructor used to fake local variables for [context] and [ast]. 106 var parser = new Parser(pattern, context, caseSensitive: caseSensitive);
99 Glob._(String pattern, p.Context context, bool recursive) 107 return new Glob._(pattern, context, parser.parse(), recursive);
100 : pattern = pattern, 108 }
101 context = context, 109
102 recursive = recursive, 110 Glob._(this.pattern, this.context, this._ast, this.recursive);
103 _ast = new Parser(pattern + (recursive ? "{,/**}" : ""), context)
104 .parse();
105 111
106 /// Lists all [FileSystemEntity]s beneath [root] that match the glob. 112 /// Lists all [FileSystemEntity]s beneath [root] that match the glob.
107 /// 113 ///
108 /// This works much like [Directory.list], but it only lists directories that 114 /// This works much like [Directory.list], but it only lists directories that
109 /// could contain entities that match the glob. It provides no guarantees 115 /// could contain entities that match the glob. It provides no guarantees
110 /// about the order of the returned entities, although it does guarantee that 116 /// about the order of the returned entities, although it does guarantee that
111 /// only one entity with a given path will be returned. 117 /// only one entity with a given path will be returned.
112 /// 118 ///
113 /// [root] defaults to the current working directory. 119 /// [root] defaults to the current working directory.
114 /// 120 ///
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return null; 176 return null;
171 } 177 }
172 178
173 Iterable<Match> allMatches(String path, [int start = 0]) { 179 Iterable<Match> allMatches(String path, [int start = 0]) {
174 var match = matchAsPrefix(path, start); 180 var match = matchAsPrefix(path, start);
175 return match == null ? [] : [match]; 181 return match == null ? [] : [match];
176 } 182 }
177 183
178 String toString() => pattern; 184 String toString() => pattern;
179 } 185 }
OLDNEW
« no previous file with comments | « README.md ('k') | lib/src/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698