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