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
96
97
98
99
100
101
102
103
#![cfg_attr(not(feature = "with_std"), no_std)]
#[rustfmt::skip]
mod tables;
pub use tables::{Script, ScriptExtension, UNICODE_VERSION};
use tables::{get_script, get_script_extension};
impl Script {
pub fn full_name(self) -> &'static str {
self.inner_full_name()
}
pub fn short_name(self) -> &'static str {
self.inner_short_name()
}
pub fn is_recommended(self) -> bool {
use Script::*;
match self {
Common | Inherited | Arabic | Armenian | Bengali | Bopomofo | Cyrillic | Devanagari
| Ethiopic | Georgian | Greek | Gujarati | Gurmukhi | Han | Hangul | Hebrew
| Hiragana | Kannada | Katakana | Khmer | Lao | Latin | Malayalam | Myanmar | Oriya
| Sinhala | Tamil | Telugu | Thaana | Thai | Tibetan => true,
_ => false,
}
}
}
impl From<char> for Script {
fn from(o: char) -> Self {
o.script()
}
}
impl ScriptExtension {
#[cfg(feature = "with_std")]
pub fn scripts(self) -> Vec<Script> {
self.inner_scripts()
}
pub fn contains_script(self, script: Script) -> bool {
self.inner_contains_script(script)
}
pub fn intersection(&mut self, other: Self) -> Self {
self.inner_intersect(other)
}
pub fn intersect_with(&mut self, other: Self) {
*self = self.inner_intersect(other)
}
pub fn is_empty(self) -> bool {
self == ScriptExtension::Single(Script::Unknown)
}
}
impl From<char> for ScriptExtension {
fn from(o: char) -> Self {
o.script_extension()
}
}
pub trait UnicodeScript {
fn script(&self) -> Script;
fn script_extension(&self) -> ScriptExtension;
}
impl UnicodeScript for char {
fn script(&self) -> Script {
get_script(*self).unwrap_or(Script::Unknown)
}
fn script_extension(&self) -> ScriptExtension {
get_script_extension(*self).unwrap_or_else(|| ScriptExtension::Single(self.script()))
}
}