123456789101112131415161718192021222324252627282930313233343536373839 |
- use std::env;
- use unidecode::unidecode;
- use regex::Regex;
- use std::io::BufReader;
- use std::io::BufRead;
- //use std::io;
- use std::fs::File;
- struct Dictionary {
- words: Vec<String>,
- }
- fn line_to_word(l: String) -> String {
- let l = unidecode(&l);
- let l = l.to_lowercase();
- l
- }
- fn main() {
- let args: Vec<String> = env::args().collect();
- let fname = &args[1];
- let regexp = &args[2];
- let mut w = vec![];
- let f = File::open(fname).unwrap();
- let buf = BufReader::new(&f);
- for line in buf.lines() {
- let line = line.unwrap();
- // TODO: normalizza: lascia solo a-z, converti gli accenti, ecc.
- w.push(line_to_word(line))
- }
- let d = Dictionary{words: w};
- let re = Regex::new(regexp).unwrap();
- for w in &d.words {
- if re.is_match(w) {
- println!("{}", w)
- }
- }
- }
|