rust-side done

This commit is contained in:
mehbark 2024-11-18 22:00:22 -05:00
commit 1461382de8
4 changed files with 135277 additions and 0 deletions

54
Cargo.lock generated Normal file
View file

@ -0,0 +1,54 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "pretense"
version = "0.1.0"
dependencies = [
"regex",
]
[[package]]
name = "regex"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"

7
Cargo.toml Normal file
View file

@ -0,0 +1,7 @@
[package]
name = "pretense"
version = "0.1.0"
edition = "2021"
[dependencies]
regex = "1.11.1"

135167
src/cmudict.dict Normal file

File diff suppressed because it is too large Load diff

49
src/main.rs Normal file
View file

@ -0,0 +1,49 @@
use std::{
collections::HashSet,
env,
io::{self, Read},
process,
};
use regex::Regex;
const DICT: &str = include_str!("cmudict.dict");
fn main() {
let mut args = env::args();
args.next().unwrap();
let min_syllables: usize = args.next().expect("one arg").parse().expect("a number");
let mut message = String::with_capacity(128);
io::stdin()
.read_to_string(&mut message)
.expect("i want a message");
let word_regex = Regex::new("(\\w|-|')+").unwrap();
let mut disallowed_words: HashSet<_> = word_regex
.find_iter(&message)
.map(|m| m.as_str().to_ascii_lowercase())
.collect();
if disallowed_words.is_empty() {
// no words is lame!
process::exit(2);
}
for line in DICT.lines() {
let Some((word, syllables)) = line.split_once(' ') else {
continue;
};
let syllables = syllables
.split_ascii_whitespace()
.filter(|s| s.ends_with(|c: char| c.is_ascii_digit()));
if syllables.count() >= min_syllables {
disallowed_words.remove(word);
}
}
process::exit(i32::from(!disallowed_words.is_empty()));
}