use std::path::Path;
use crate::{
common::{
parse_codepoint_association, CodepointIter, Codepoints, UcdFile,
UcdFileByCodepoint,
},
error::Error,
};
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Property {
pub codepoints: Codepoints,
pub property: String,
}
impl UcdFile for Property {
fn relative_file_path() -> &'static Path {
Path::new("PropList.txt")
}
}
impl UcdFileByCodepoint for Property {
fn codepoints(&self) -> CodepointIter {
self.codepoints.into_iter()
}
}
impl std::str::FromStr for Property {
type Err = Error;
fn from_str(line: &str) -> Result<Property, Error> {
let (codepoints, property) = parse_codepoint_association(line)?;
Ok(Property { codepoints, property: property.to_string() })
}
}
#[cfg(test)]
mod tests {
use super::Property;
#[test]
fn parse_single() {
let line =
"061C ; Bidi_Control # Cf ARABIC LETTER MARK\n";
let row: Property = line.parse().unwrap();
assert_eq!(row.codepoints, 0x061C);
assert_eq!(row.property, "Bidi_Control");
}
#[test]
fn parse_range() {
let line = "0009..000D ; White_Space # Cc [5] <control-0009>..<control-000D>\n";
let row: Property = line.parse().unwrap();
assert_eq!(row.codepoints, (0x0009, 0x000D));
assert_eq!(row.property, "White_Space");
}
}