ucd_parse/extracted/
derived_line_break.rs

1use std::path::Path;
2
3use crate::{
4    common::{
5        parse_codepoint_association, CodepointIter, Codepoints, UcdFile,
6        UcdFileByCodepoint,
7    },
8    error::Error,
9};
10
11/// A single row in the `extracted/DerivedLineBreak.txt` file.
12///
13/// This file gives the derived values of the Line_Break property.
14#[derive(Clone, Debug, Default, Eq, PartialEq)]
15pub struct DerivedLineBreak {
16    /// The codepoint or codepoint range for this entry.
17    pub codepoints: Codepoints,
18    /// The derived Line_Break of the codepoints in this entry.
19    pub line_break: String,
20}
21
22impl UcdFile for DerivedLineBreak {
23    fn relative_file_path() -> &'static Path {
24        Path::new("extracted/DerivedLineBreak.txt")
25    }
26}
27
28impl UcdFileByCodepoint for DerivedLineBreak {
29    fn codepoints(&self) -> CodepointIter {
30        self.codepoints.into_iter()
31    }
32}
33
34impl std::str::FromStr for DerivedLineBreak {
35    type Err = Error;
36
37    fn from_str(line: &str) -> Result<DerivedLineBreak, Error> {
38        let (codepoints, line_break) = parse_codepoint_association(line)?;
39        Ok(DerivedLineBreak { codepoints, line_break: line_break.to_string() })
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::DerivedLineBreak;
46
47    #[test]
48    fn parse_single() {
49        let line = "0028          ; OP # Ps       LEFT PARENTHESIS\n";
50        let row: DerivedLineBreak = line.parse().unwrap();
51        assert_eq!(row.codepoints, 0x0028);
52        assert_eq!(row.line_break, "OP");
53    }
54
55    #[test]
56    fn parse_range() {
57        let line = "0030..0039    ; NU # Nd  [10] DIGIT ZERO..DIGIT NINE\n";
58        let row: DerivedLineBreak = line.parse().unwrap();
59        assert_eq!(row.codepoints, (0x0030, 0x0039));
60        assert_eq!(row.line_break, "NU");
61    }
62}