11using System . Diagnostics . CodeAnalysis ;
2+ using System . Security . Cryptography ;
23using System . Text . RegularExpressions ;
34
45namespace LineCount ;
56
67public class LineCountData
78{
8- public string ? Filter { get ; }
9+ public Regex ? Filter { get ; }
910 public Regex ? LineFilter { get ; }
10- public string ? ExcludeFilter { get ; }
11+ public Regex ? ExcludeFilter { get ; }
1112 public Regex ? ExcludeLineFilter { get ; }
1213
1314 public FilterType FilterType { get ; } = ( FilterType ) ( - 1 ) ;
@@ -17,17 +18,26 @@ public class LineCountData
1718
1819 public LineCountData ( string ? filter , string ? lineFilter , string ? filterNot , string ? lineFilterNot )
1920 {
20- Filter = filter ;
21- ExcludeFilter = filterNot ;
22-
21+ if ( filter is not null )
22+ {
23+ string filterPattern = Globbing . ToRegex ( filter ) ;
24+ Filter = new Regex ( filterPattern , RegexOptions . Singleline | RegexOptions . Compiled , TimeOut ) ;
25+ }
26+
27+ if ( filterNot is not null )
28+ {
29+ string filterNotPattern = Globbing . ToRegex ( filterNot ) ;
30+ ExcludeFilter = new Regex ( filterNotPattern , RegexOptions . Singleline | RegexOptions . Compiled , TimeOut ) ;
31+ }
32+
2333 if ( lineFilter is null )
2434 {
2535 FilterType = lineFilterNot is null ? FilterType . None : FilterType . FilteredExcept ;
2636 }
2737 else
2838 {
29- LineFilter = new Regex ( lineFilter , RegexOptions . Singleline | RegexOptions . Compiled , TimeOut ) ;
3039 FilterType = lineFilterNot is null ? FilterType . Filtered : FilterType . FilteredBoth ;
40+ LineFilter = new Regex ( lineFilter , RegexOptions . Singleline | RegexOptions . Compiled , TimeOut ) ;
3141 }
3242
3343 if ( lineFilterNot is not null )
0 commit comments