ucd_parse/extracted/
derived_joining_group.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/DerivedJoiningGroup.txt` file.
12///
13/// This file gives the derived values of the Joining_Group property.
14#[derive(Clone, Debug, Default, Eq, PartialEq)]
15pub struct DerivedJoiningGroup {
16    /// The codepoint or codepoint range for this entry.
17    pub codepoints: Codepoints,
18    /// The derived Joining_Group of the codepoints in this entry.
19    pub joining_group: String,
20}
21
22impl UcdFile for DerivedJoiningGroup {
23    fn relative_file_path() -> &'static Path {
24        Path::new("extracted/DerivedJoiningGroup.txt")
25    }
26}
27
28impl UcdFileByCodepoint for DerivedJoiningGroup {
29    fn codepoints(&self) -> CodepointIter {
30        self.codepoints.into_iter()
31    }
32}
33
34impl std::str::FromStr for DerivedJoiningGroup {
35    type Err = Error;
36
37    fn from_str(line: &str) -> Result<DerivedJoiningGroup, Error> {
38        let (codepoints, joining_group) = parse_codepoint_association(line)?;
39        Ok(DerivedJoiningGroup {
40            codepoints,
41            joining_group: joining_group.to_string(),
42        })
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::DerivedJoiningGroup;
49
50    #[test]
51    fn parse_single() {
52        let line = "0710          ; Alaph # Lo       SYRIAC LETTER ALAPH\n";
53        let row: DerivedJoiningGroup = line.parse().unwrap();
54        assert_eq!(row.codepoints, 0x0710);
55        assert_eq!(row.joining_group, "Alaph");
56    }
57
58    #[test]
59    fn parse_range() {
60        let line =  "0633..0634    ; Seen # Lo   [2] ARABIC LETTER SEEN..ARABIC LETTER SHEEN\n";
61        let row: DerivedJoiningGroup = line.parse().unwrap();
62        assert_eq!(row.codepoints, (0x0633, 0x0634));
63        assert_eq!(row.joining_group, "Seen");
64    }
65}