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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « README.md ('k') | lib/src/ast.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/glob.dart
diff --git a/lib/glob.dart b/lib/glob.dart
index 2d2a83f6a9b3a0d4e0b5034d18c19f476e7b2e55..41f1a778cb777e2e75424923a56d421d7e93f0db 100644
--- a/lib/glob.dart
+++ b/lib/glob.dart
@@ -45,6 +45,9 @@ class Glob implements Pattern {
/// contained within a directory that matches.
final bool recursive;
+ /// Whether the glob matches paths case-sensitively.
+ bool get caseSensitive => _ast.caseSensitive;
+
/// The parsed AST of the glob.
final AstNode _ast;
@@ -87,21 +90,24 @@ class Glob implements Pattern {
/// Paths matched against the glob are interpreted according to [context]. It
/// defaults to the system context.
///
- /// If [recursive] is true, this glob will match and list not only the files
- /// and directories it explicitly lists, but anything beneath those as well.
- Glob(String pattern, {p.Context context, bool recursive: false})
- : this._(
- pattern,
- context == null ? p.context : context,
- recursive);
-
- // Internal constructor used to fake local variables for [context] and [ast].
- Glob._(String pattern, p.Context context, bool recursive)
- : pattern = pattern,
- context = context,
- recursive = recursive,
- _ast = new Parser(pattern + (recursive ? "{,/**}" : ""), context)
- .parse();
+ /// If [recursive] is true, this glob matches and lists not only the files and
+ /// directories it explicitly matches, but anything beneath those as well.
+ ///
+ /// If [caseSensitive] is true, this glob matches and lists only files whose
+ /// case matches that of the characters in the glob. Otherwise, it matches
+ /// regardless of case. This defaults to `false` when [context] is Windows and
+ /// `true` otherwise.
+ factory Glob(String pattern, {p.Context context, bool recursive: false,
+ bool caseSensitive}) {
+ context ??= p.context;
+ caseSensitive ??= context.style == p.Style.windows ? false : true;
+ if (recursive) pattern += "{,/**}";
+
+ var parser = new Parser(pattern, context, caseSensitive: caseSensitive);
+ return new Glob._(pattern, context, parser.parse(), recursive);
+ }
+
+ Glob._(this.pattern, this.context, this._ast, this.recursive);
/// Lists all [FileSystemEntity]s beneath [root] that match the glob.
///
« 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