123456789101112131415161718192021222324252627282930 |
- use std::env;
- use regex::Regex;
- use std::io::BufReader;
- use std::io::BufRead;
- //use std::io;
- use std::fs::File;
- struct Dictionary {
- words: Vec<String>,
- }
- fn main() {
- let args: Vec<String> = env::args().collect();
- let fname = &args[1];
- let regexp = &args[2];
- let w = vec![];
- let mut d = Dictionary{words: w};
- 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.
- d.words.push(line.to_string())
- }
- let re = Regex::new(regexp).unwrap();
- for w in &d.words {
- if re.is_match(w) {
- println!("{}", w)
- }
- }
- }
|