main.rs 732 B

123456789101112131415161718192021222324252627282930
  1. use std::env;
  2. use regex::Regex;
  3. use std::io::BufReader;
  4. use std::io::BufRead;
  5. //use std::io;
  6. use std::fs::File;
  7. struct Dictionary {
  8. words: Vec<String>,
  9. }
  10. fn main() {
  11. let args: Vec<String> = env::args().collect();
  12. let fname = &args[1];
  13. let regexp = &args[2];
  14. let w = vec![];
  15. let mut d = Dictionary{words: w};
  16. let f = File::open(fname).unwrap();
  17. let buf = BufReader::new(&f);
  18. for line in buf.lines() {
  19. let line = line.unwrap();
  20. // TODO: normalizza: lascia solo a-z, converti gli accenti, ecc.
  21. d.words.push(line.to_string())
  22. }
  23. let re = Regex::new(regexp).unwrap();
  24. for w in &d.words {
  25. if re.is_match(w) {
  26. println!("{}", w)
  27. }
  28. }
  29. }