1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::path::Path;
use std::str::FromStr;
use crate::common::{
parse_codepoint_association, CodepointIter, Codepoints, UcdFile,
UcdFileByCodepoint,
};
use crate::error::Error;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct DerivedJoiningGroup {
pub codepoints: Codepoints,
pub joining_group: String,
}
impl UcdFile for DerivedJoiningGroup {
fn relative_file_path() -> &'static Path {
Path::new("extracted/DerivedJoiningGroup.txt")
}
}
impl UcdFileByCodepoint for DerivedJoiningGroup {
fn codepoints(&self) -> CodepointIter {
self.codepoints.into_iter()
}
}
impl FromStr for DerivedJoiningGroup {
type Err = Error;
fn from_str(line: &str) -> Result<DerivedJoiningGroup, Error> {
let (codepoints, joining_group) = parse_codepoint_association(line)?;
Ok(DerivedJoiningGroup {
codepoints,
joining_group: joining_group.to_string(),
})
}
}
#[cfg(test)]
mod tests {
use super::DerivedJoiningGroup;
#[test]
fn parse_single() {
let line = "0710 ; Alaph # Lo SYRIAC LETTER ALAPH\n";
let row: DerivedJoiningGroup = line.parse().unwrap();
assert_eq!(row.codepoints, 0x0710);
assert_eq!(row.joining_group, "Alaph");
}
#[test]
fn parse_range() {
let line = "0633..0634 ; Seen # Lo [2] ARABIC LETTER SEEN..ARABIC LETTER SHEEN\n";
let row: DerivedJoiningGroup = line.parse().unwrap();
assert_eq!(row.codepoints, (0x0633, 0x0634));
assert_eq!(row.joining_group, "Seen");
}
}