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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use std::collections::HashMap;
use std::hash::Hash;
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum EmojiGroups {
Emojis,
Japanese,
Smile,
Moon,
Earth,
Plant,
Clock,
Shape,
Arrow,
All,
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum CharGroups<T: Hash + Eq> {
Standard(EmojiGroups),
Custom(T),
}
impl<T: Hash + Eq> From<EmojiGroups> for CharGroups<T> {
fn from(v: EmojiGroups) -> Self {Self::Standard(v)}
}
impl<T: Hash + Eq> CharGroups<T> {
pub fn custom(v: T) -> Self {Self::Custom(v)}
}
pub fn create_emoji_data<T: Hash + Eq>() -> HashMap<CharGroups<T>, Vec<u32>> {
let mut hash = HashMap::new();
hash.insert(EmojiGroups::Emojis.into(), create_emojis());
hash.insert(EmojiGroups::Smile.into(), create_smile());
hash.insert(EmojiGroups::Japanese.into(), create_jap());
hash.insert(EmojiGroups::Moon.into(), create_moon());
hash.insert(EmojiGroups::Earth.into(), create_earth());
hash.insert(EmojiGroups::Plant.into(), create_plant());
hash.insert(EmojiGroups::Clock.into(), create_clock());
hash.insert(EmojiGroups::Shape.into(), create_shape());
hash.insert(EmojiGroups::Arrow.into(), create_arrows());
hash.insert(EmojiGroups::All.into(), create_all());
hash
}
pub struct EZEmojis<T: Hash + Eq> {
list: HashMap<CharGroups<T>, Vec<u32>>,
}
impl<T: Hash + Eq> EZEmojis<T> {
pub fn new() -> Self {
Self { list: create_emoji_data() }
}
pub fn add(&mut self, key: CharGroups<T>, value: Vec<u32>) {
self.list.insert(key, value);
}
pub fn get_char(&self, key: &CharGroups<T>) -> Option<Vec<char>> {
self.list.get(key).map(
|n| n.iter().map(|num| std::char::from_u32(*num).unwrap_or(' ')).collect()
)
}
pub fn get_u32(&self, key: &CharGroups<T>) -> Option<&Vec<u32>> {
self.list.get(key)
}
}
fn create_emojis() -> Vec<u32> {
(129292..=129535).collect()
}
fn create_smile() -> Vec<u32> {
(128512..=128518).collect()
}
fn create_jap() -> Vec<u32> {
(65382..=65437).collect()
}
fn create_moon() -> Vec<u32> {
(127760..=127773).collect()
}
fn create_earth() -> Vec<u32> {
(127757..=127760).collect()
}
fn create_plant() -> Vec<u32> {
(127793..=127827).collect()
}
fn create_clock() -> Vec<u32> {
(128336..=128359).collect()
}
fn create_shape() -> Vec<u32> {
(128992..=129003).collect()
}
fn create_arrows() -> Vec<u32> {
let mut a: Vec<u32> = (129024..=129035).collect();
a.append(&mut (129040..=129095).collect());
a.append(&mut (129168..=129195).collect());
a.append(&mut (129168..=129195).collect());
a.append(&mut (129104..=129113).collect());
a
}
fn create_all() -> Vec<u32> {
let mut a = create_moon();
a.append(&mut create_earth());
a.append(&mut create_plant());
a.append(&mut create_clock());
a.append(&mut create_shape());
a.append(&mut create_arrows());
a
}