Advertisement
Guest User

twofuctions

a guest
Jul 24th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. fn search_and_add_to_vector() {
  2. let matcher = grep::regex::RegexMatcher::new_line_matcher("test").unwrap();
  3. let mut searcher = SearcherBuilder::new()
  4. .binary_detection(BinaryDetection::quit(b'\x00'))
  5. .line_number(false)
  6. .build();
  7.  
  8. for result in WalkDir::new("/home/melnibone/Documents/trst/") {
  9. let dent = match result {
  10. Ok(dent) => dent,
  11. Err(_) => {
  12. println!("no dir");
  13. continue;
  14. }
  15. };
  16. if !dent.file_type().is_file() {
  17. continue;
  18. }
  19. let result = searcher
  20. .search_path(
  21. &matcher,
  22. dent.path(),
  23. UTF8(|lnum, line| {
  24. let mym = matcher.find(line.as_bytes())?.unwrap();
  25. println!("pushed to vector {}", line[mym].to_string());
  26. Ok(true)
  27. }),
  28. )
  29. .unwrap();
  30. }
  31. }
  32. fn search_with_cool_sink() {
  33. let matcher = grep::regex::RegexMatcher::new_line_matcher("test").unwrap();
  34.  
  35. let mut searcher = SearcherBuilder::new()
  36. .binary_detection(BinaryDetection::quit(b'\x00'))
  37. .line_number(false)
  38. .build();
  39. let mut printer = StandardBuilder::new()
  40. .color_specs(ColorSpecs::default_with_color())
  41. .build(cli::stdout(if std::io::stdout().is_terminal() {
  42. ColorChoice::Auto
  43. } else {
  44. ColorChoice::Never
  45. }));
  46. for result in WalkDir::new("/home/melnibone/Documents/trst/") {
  47. let dent = match result {
  48. Ok(dent) => dent,
  49. Err(_) => {
  50. println!("no dir");
  51. continue;
  52. }
  53. };
  54. if !dent.file_type().is_file() {
  55. continue;
  56. }
  57. let result = searcher
  58. .search_path(
  59. &matcher,
  60. dent.path(),
  61. printer.sink_with_path(&matcher, dent.path()),
  62. )
  63. .unwrap();
  64. }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement