1use crate::emoji_variation::VARIATION_MAP;
2#[cfg(feature = "use_serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Copy, Clone, Debug, Eq, PartialEq)]
6#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
7pub enum Presentation {
8 Text,
9 Emoji,
10}
11
12impl Presentation {
13 pub fn for_grapheme(s: &str) -> (Self, Option<Self>) {
17 if let Some((a, b)) = VARIATION_MAP.get(s) {
18 return (*a, Some(*b));
19 }
20 let mut presentation = Self::Text;
21 for c in s.chars() {
22 if Self::for_char(c) == Self::Emoji {
23 presentation = Self::Emoji;
24 break;
25 }
26 }
32 (presentation, None)
33 }
34
35 pub fn for_char(c: char) -> Self {
36 if crate::emoji_presentation::EMOJI_PRESENTATION.contains_u32(c as u32) {
37 Self::Emoji
38 } else {
39 Self::Text
40 }
41 }
42}