This commit is contained in:
boyska 2020-05-18 12:52:26 +02:00
commit 30d1d94a68
4 changed files with 98 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
**/*.rs.bk

58
Cargo.lock generated Normal file
View file

@ -0,0 +1,58 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memchr"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex"
version = "1.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "sciarada"
version = "0.1.0"
dependencies = [
"regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
"checksum regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692"
"checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "sciarada"
version = "0.1.0"
authors = ["boyska <piuttosto@logorroici.org>"]
edition = "2018"
[dependencies]
regex = "1"

30
src/main.rs Normal file
View file

@ -0,0 +1,30 @@
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)
}
}
}