@@ -4617,7 +4617,8 @@ enum SpanMode
4617
4617
[" animals" , " plants" ]));
4618
4618
}
4619
4619
4620
- private struct DirIteratorImpl
4620
+ private struct DirIteratorImpl (alias pred = (const scope ref DirEntry entry) => true)
4621
+ // TODO: if (is(typeof(pred(DirEntry.init)) : bool))
4621
4622
{
4622
4623
@safe :
4623
4624
SpanMode _mode;
@@ -4721,6 +4722,8 @@ private struct DirIteratorImpl
4721
4722
4722
4723
bool mayStepIn ()
4723
4724
{
4725
+ if (pred(_cur))
4726
+ return false ;
4724
4727
return _followSymlink ? _cur.isDir : _cur.isDir && ! _cur.isSymlink;
4725
4728
}
4726
4729
}
@@ -4864,16 +4867,17 @@ private struct DirIteratorImpl
4864
4867
}
4865
4868
}
4866
4869
4870
+ struct _DirIterator (bool useDIP1000, alias pred = (const scope ref DirEntry entry) => true)
4871
+ // TODO: if (is(typeof(pred(DirEntry.init)) : bool))
4867
4872
// Must be a template, because the destructor is unsafe or safe depending on
4868
4873
// whether `-preview=dip1000` is in use. Otherwise, linking errors would
4869
4874
// result.
4870
- struct _DirIterator (bool useDIP1000)
4871
4875
{
4872
4876
static assert (useDIP1000 == dip1000Enabled,
4873
4877
" Please don't override useDIP1000 to disagree with compiler switch." );
4874
4878
4875
4879
private :
4876
- SafeRefCounted! (DirIteratorImpl, RefCountedAutoInitialize.no) impl;
4880
+ SafeRefCounted! (DirIteratorImpl! (pred) , RefCountedAutoInitialize.no) impl;
4877
4881
4878
4882
this (string pathname, SpanMode mode, bool followSymlink) @trusted
4879
4883
{
@@ -4975,10 +4979,11 @@ foreach (d; dFiles)
4975
4979
4976
4980
// For some reason, doing the same alias-to-a-template trick as with DirIterator
4977
4981
// does not work here.
4978
- auto dirEntries (bool useDIP1000 = dip1000Enabled)
4982
+ auto dirEntries (bool useDIP1000 = dip1000Enabled, alias pred = ( const scope ref DirEntry entry) => true )
4979
4983
(string path, SpanMode mode, bool followSymlink = true )
4984
+ // TODO: if (is(typeof(pred(DirEntry.init)) : bool))
4980
4985
{
4981
- return _DirIterator! useDIP1000(path, mode, followSymlink);
4986
+ return _DirIterator! ( useDIP1000, pred) (path, mode, followSymlink);
4982
4987
}
4983
4988
4984
4989
// / Duplicate functionality of D1's `std.file.listdir()`:
@@ -5087,7 +5092,7 @@ auto dirEntries(bool useDIP1000 = dip1000Enabled)
5087
5092
import std.path : globMatch, baseName;
5088
5093
5089
5094
bool f (DirEntry de) { return globMatch(baseName(de.name), pattern); }
5090
- return filter! f(_DirIterator! useDIP1000(path, mode, followSymlink));
5095
+ return filter! f(_DirIterator! ( useDIP1000) (path, mode, followSymlink));
5091
5096
}
5092
5097
5093
5098
@safe unittest
0 commit comments