@@ -22,7 +22,6 @@ use std::panic;
22
22
use std:: path:: { Path , PathBuf } ;
23
23
24
24
pub use gimli;
25
- pub use glob;
26
25
pub use object;
27
26
pub use regex;
28
27
pub use wasmparser;
@@ -245,17 +244,18 @@ pub fn uname() -> String {
245
244
output. stdout_utf8 ( )
246
245
}
247
246
248
- /// Inside a glob pattern of files (paths), read their contents and count the
247
+ /// Search for all files in the current working directory with the extension `ext`,
248
+ /// read their contents and count the
249
249
/// number of regex matches with a given expression (re).
250
250
#[ track_caller]
251
- pub fn count_regex_matches_in_file_glob ( re : & str , paths : & str ) -> usize {
251
+ pub fn count_regex_matches_in_files_with_extension ( re : & str , ext : & str ) -> usize {
252
252
let re = regex:: Regex :: new ( re) . expect ( format ! ( "Regex expression {re} is not valid." ) . as_str ( ) ) ;
253
- let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
254
253
use io:: BufRead ;
255
- paths
254
+ fs_wrapper :: read_dir ( cwd ( ) )
256
255
. filter_map ( |entry| entry. ok ( ) )
257
- . filter ( |entry| entry. as_path ( ) . is_file ( ) )
258
- . filter_map ( |path| fs:: File :: open ( & path) . ok ( ) )
256
+ . filter ( |entry| entry. path ( ) . is_file ( ) )
257
+ . filter ( |entry| entry. path ( ) . extension ( ) . unwrap ( ) == ext)
258
+ . filter_map ( |entry| fs:: File :: open ( & entry. path ( ) ) . ok ( ) )
259
259
. map ( |file| io:: BufReader :: new ( file) )
260
260
. flat_map ( |reader| reader. lines ( ) . filter_map ( |entry| entry. ok ( ) ) )
261
261
. filter ( |line| re. is_match ( line) )
0 commit comments