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/DerivedCombiningClass.txt` file.
12///
13/// This file gives the derived values of the Decomposition_Type
14/// property.
15#[derive(Clone, Debug, Default, Eq, PartialEq)]
16pub struct DerivedDecompositionType {
17 /// The codepoint or codepoint range for this entry.
18 pub codepoints: Codepoints,
19 /// The derived Decomposition_Type of the codepoints in this entry.
20 pub decomposition_type: String,
21}
22
23impl UcdFile for DerivedDecompositionType {
24 fn relative_file_path() -> &'static Path {
25 Path::new("extracted/DerivedDecompositionType.txt")
26 }
27}
28
29impl UcdFileByCodepoint for DerivedDecompositionType {
30 fn codepoints(&self) -> CodepointIter {
31 self.codepoints.into_iter()
32 }
33}
34
35impl std::str::FromStr for DerivedDecompositionType {
36 type Err = Error;
37
38 fn from_str(line: &str) -> Result<DerivedDecompositionType, Error> {
39 let (codepoints: Codepoints, decomposition_type: &str) =
40 parse_codepoint_association(line)?;
41 Ok(DerivedDecompositionType {
42 codepoints,
43 decomposition_type: decomposition_type.to_string(),
44 })
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::DerivedDecompositionType;
51
52 #[test]
53 fn parse_single() {
54 let line = "00A0 ; Nobreak # Zs NO-BREAK SPACE\n";
55 let row: DerivedDecompositionType = line.parse().unwrap();
56 assert_eq!(row.codepoints, 0x00A0);
57 assert_eq!(row.decomposition_type, "Nobreak");
58 }
59
60 #[test]
61 fn parse_range() {
62 let line = "3070..3071 ; Canonical # Lo [2] HIRAGANA LETTER BA..HIRAGANA LETTER PA\n";
63 let row: DerivedDecompositionType = line.parse().unwrap();
64 assert_eq!(row.codepoints, (0x3070, 0x3071));
65 assert_eq!(row.decomposition_type, "Canonical");
66 }
67}
68

Provided by KDAB

Privacy Policy
Learn Rust with the experts
Find out more