use ktrs_editorconfig::{EnumValue, PropertyValue};
pub fn safe_enum_value_parser<E: EnumValue>(_name: &str, value: Option<&str>) -> PropertyValue<E> {
match value {
None => PropertyValue::invalid(
None,
format!("Cannot make enum {} out of null", E::ENUM_TYPE_NAME),
),
Some(v) => match E::value_of(&v.trim().to_lowercase()) {
Some(e) => PropertyValue::valid(value, Some(e)),
None => PropertyValue::invalid(
value,
format!("Unexpected parsed \"{v}\" for enum {}", E::ENUM_TYPE_NAME),
),
},
}
}
pub fn comma_separated_list_value_parser(
_name: &str,
value: Option<&str>,
) -> PropertyValue<Vec<String>> {
if value == Some("unset") {
return PropertyValue::valid(value, Some(Vec::new()));
}
let mut set: Vec<String> = Vec::new();
for item in value.unwrap_or("").split(',').map(str::trim) {
if !set.iter().any(|s| s == item) {
set.push(item.to_owned());
}
}
PropertyValue::valid(value, Some(set))
}