1use std::path::Path;
2use std::str::FromStr;
3
4use crate::common::{
5 parse_codepoint_association, CodepointIter, Codepoints, UcdFile,
6 UcdFileByCodepoint,
7};
8use crate::error::Error;
9
10/// A single row in the `extracted/DerivedJoiningType.txt` file.
11///
12/// This file gives the derived values of the Joining_Type property.
13#[derive(Clone, Debug, Default, Eq, PartialEq)]
14pub struct DerivedJoiningType {
15 /// The codepoint or codepoint range for this entry.
16 pub codepoints: Codepoints,
17 /// The derived Joining_Type of the codepoints in this entry.
18 pub joining_type: String,
19}
20
21impl UcdFile for DerivedJoiningType {
22 fn relative_file_path() -> &'static Path {
23 Path::new("extracted/DerivedJoiningType.txt")
24 }
25}
26
27impl UcdFileByCodepoint for DerivedJoiningType {
28 fn codepoints(&self) -> CodepointIter {
29 self.codepoints.into_iter()
30 }
31}
32
33impl FromStr for DerivedJoiningType {
34 type Err = Error;
35
36 fn from_str(line: &str) -> Result<DerivedJoiningType, Error> {
37 let (codepoints: Codepoints, joining_type: &str) = parse_codepoint_association(line)?;
38 Ok(DerivedJoiningType {
39 codepoints,
40 joining_type: joining_type.to_string(),
41 })
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::DerivedJoiningType;
48
49 #[test]
50 fn parse_single() {
51 let line = "0628 ; D # Lo ARABIC LETTER BEH\n";
52 let row: DerivedJoiningType = line.parse().unwrap();
53 assert_eq!(row.codepoints, 0x0628);
54 assert_eq!(row.joining_type, "D");
55 }
56
57 #[test]
58 fn parse_range() {
59 let line = "1133B..1133C ; T # Mn [2] COMBINING BINDU BELOW..GRANTHA SIGN NUKTA\n";
60 let row: DerivedJoiningType = line.parse().unwrap();
61 assert_eq!(row.codepoints, (0x1133B, 0x1133C));
62 assert_eq!(row.joining_type, "T");
63 }
64}
65