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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use unic_char_property::{tables::CharDataTableIter, PartialCharProperty};
use unic_char_range::CharRange;
#[derive(Clone, Copy, Debug)]
pub struct Block {
pub range: CharRange,
pub name: &'static str,
_priv: (),
}
impl Block {
pub fn of(ch: char) -> Option<Block> {
match data::BLOCKS.find_with_range(ch) {
None => None,
Some((range, name)) => Some(Block {
range,
name,
_priv: (),
}),
}
}
}
impl PartialCharProperty for Block {
fn of(ch: char) -> Option<Self> {
Self::of(ch)
}
}
#[derive(Debug)]
pub struct BlockIter<'a> {
iter: CharDataTableIter<'a, &'static str>,
}
impl<'a> BlockIter<'a> {
pub fn new() -> BlockIter<'a> {
BlockIter {
iter: data::BLOCKS.iter(),
}
}
}
impl<'a> Default for BlockIter<'a> {
fn default() -> Self {
BlockIter::new()
}
}
impl<'a> Iterator for BlockIter<'a> {
type Item = Block;
fn next(&mut self) -> Option<Block> {
match self.iter.next() {
None => None,
Some((range, name)) => Some(Block {
range,
name,
_priv: (),
}),
}
}
}
mod data {
use unic_char_property::tables::CharDataTable;
pub const BLOCKS: CharDataTable<&str> = include!("../tables/blocks.rsv");
}