1
//! Unicode utilities and character properties.
2

            
3
use std::convert::TryFrom;
4

            
5
pub mod codepoint;
6
mod emoji_data;
7
pub mod mcc;
8

            
9
/// A Unicode variation selector.
10
///
11
/// VS04-VS14 are omitted as they aren't currently used.
12
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
13
pub enum VariationSelector {
14
    /// VARIATION SELECTOR-1
15
    VS01 = 1,
16
    /// VARIATION SELECTOR-2
17
    VS02 = 2,
18
    /// VARIATION SELECTOR-3
19
    VS03 = 3,
20
    /// Text presentation
21
    VS15 = 15,
22
    /// Emoji presentation
23
    VS16 = 16,
24
}
25

            
26
impl TryFrom<char> for VariationSelector {
27
    type Error = ();
28

            
29
    fn try_from(ch: char) -> Result<Self, Self::Error> {
30
        match ch {
31
            '\u{FE00}' => Ok(VariationSelector::VS01),
32
            '\u{FE01}' => Ok(VariationSelector::VS02),
33
            '\u{FE02}' => Ok(VariationSelector::VS03),
34
            '\u{FE0E}' => Ok(VariationSelector::VS15),
35
            '\u{FE0F}' => Ok(VariationSelector::VS16),
36
            _ => Err(()),
37
        }
38
    }
39
}
40

            
41
/// Returns the `Emoji_Presentation` Unicode property for a character.
42
///
43
/// ```
44
/// use allsorts::unicode::bool_prop_emoji_presentation;
45
///
46
/// assert_eq!(bool_prop_emoji_presentation('🦀'), true);
47
/// assert_eq!(bool_prop_emoji_presentation('&'), false);
48
pub fn bool_prop_emoji_presentation(ch: char) -> bool {
49
    emoji_data::EMOJI_PRESENTATION.contains_u32(ch as u32)
50
}