use std::fmt::{self, Display};
use crate::format;
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
pub struct Keywords(Vec<String>);
impl Keywords {
pub fn parse_user_input(string: &str) -> Option<Self> {
Self::parse(string, ",")
}
pub fn parse_schemed_string(string: &str) -> Option<Self> {
Self::parse(string, "_")
}
fn parse(string: &str, separator: &str) -> Option<Self> {
let keywords: Vec<_> = string
.split(separator)
.map(|s| format::format(s, ""))
.filter(|s| !s.is_empty())
.collect();
(!keywords.is_empty()).then_some(keywords).map(Self)
}
}
impl Display for Keywords {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "__{}", self.0.join("_"))
}
}