const VARIATION_SEQUENCES: &str = include_str!("../../data/emoji-variation-sequences.txt"); /// Parses emoji-variation-sequences.txt, which is part of the UCD download /// for a given version of the Unicode spec. /// It defines which sequences can have explicit presentation selectors. fn main() { let mut map = phf_codegen::Map::new(); 'next_line: for line in VARIATION_SEQUENCES.lines() { if let Some(lhs) = line.split('#').next() { if let Some(seq) = lhs.split(';').next() { let mut s = String::new(); let mut last = None; for hex in seq.split_whitespace() { match u32::from_str_radix(hex, 16) { Ok(n) => { let c = char::from_u32(n).unwrap(); s.push(c); last.replace(c); } Err(_) => { continue 'next_line; } } } if let Some(last) = last { map.entry( s, match last { '\u{FE0F}' => "Presentation::Emoji", '\u{FE0E}' => "Presentation::Text", _ => unreachable!(), }, ); } } } } println!("//! This file was generated by running:"); println!("//! cd ../codegen ; cargo run > ../emoji_variation.rs"); println!(); println!("use crate::emoji::Presentation;"); println!(); println!( "pub static VARIATION_MAP: phf::Map<&'static str, Presentation> = \n{};\n", map.build(), ); }