main.rs 861 B

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