use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HyphenationOverride {
pub word: String,
pub hyphenated: String,
}
impl HyphenationOverride {
pub fn new(word: impl Into<String>, hyphenated: impl Into<String>) -> Self {
HyphenationOverride {
word: word.into(),
hyphenated: hyphenated.into(),
}
}
}
#[derive(Debug, Default, Clone)]
pub struct HyphenationExceptionsCollection {
exceptions: HashMap<String, String>,
}
impl HyphenationExceptionsCollection {
pub fn new() -> Self {
Self::default()
}
pub fn add(&mut self, exception: HyphenationOverride) {
self.exceptions.insert(exception.word, exception.hyphenated);
}
pub fn has(&self, word: &str) -> bool {
self.exceptions.contains_key(word)
}
pub fn get(&self, word: &str) -> Option<&str> {
self.exceptions.get(word).map(|s| s.as_str())
}
pub fn count(&self) -> usize {
self.exceptions.len()
}
pub fn is_empty(&self) -> bool {
self.exceptions.is_empty()
}
}