demoji_rs/
lib.rs

1use once_cell::sync::Lazy;
2use std::collections::HashMap;
3use unicode_segmentation::UnicodeSegmentation;
4
5type EmojiMap = HashMap<&'static str, &'static str>;
6
7pub fn remove_emoji(text: &str) -> String {
8    text.graphemes(true)
9        .filter(|grapheme| !ONCE_CELL.contains_key(*grapheme))
10        .collect()
11}
12
13pub fn find_emoji(text: &str) -> EmojiMap {
14    text.graphemes(true)
15        .fold(HashMap::new(), |mut emojis, grapheme| {
16            if let Some((name, value)) = ONCE_CELL.get_key_value(grapheme) {
17                emojis.insert(*name, *value);
18            }
19            emojis
20        })
21}
22
23static ONCE_CELL: Lazy<EmojiMap> = include!("emoji_map.in");