use std::collections::BTreeMap;
#[derive(Clone, Debug)]
pub struct Property {
pub name: String,
pub params: BTreeMap<String, String>,
pub raw_value: String,
pub prop_group: Option<String>
}
impl Property {
pub fn new<N, V>(name: N, value: V) -> Property
where N: Into<String>,
V: AsRef<str>
{
Property {
name: name.into(),
params: BTreeMap::new(),
raw_value: escape_chars(value.as_ref()),
prop_group: None
}
}
pub fn value_as_string(&self) -> String {
unescape_chars(&self.raw_value)
}
}
pub fn escape_chars(s: &str) -> String {
s
.replace("\\N", "\n")
.replace("\\", "\\\\")
.replace(";", "\\;")
.replace(",", "\\,")
.replace("\r\n", "\\n")
.replace("\n", "\\n")
}
pub fn unescape_chars(s: &str) -> String {
s
.replace("\\N", "\\n")
.replace("\r\n", "\n")
.replace("\\n", "\n")
.replace("\\,", ",")
.replace("\\;", ";")
.replace("\\\\", "\\")
}