#![no_std] use core::char; use core::slice; pub mod tables; use tables::Search; pub use tables::{ BidiClass, BidiPairedBracketType, DecompositionType, EastAsianWidth, GraphemeClusterBreak, HangulSyllableType, IndicPositionalCategory, IndicSyllabicCategory, JoiningGroup, JoiningType, LinebreakClass, NumericType, Script, SentenceBreak, Trilean, UnicodeBlock, UnicodeCategory, WordBreak }; // for use with numeric_value #[derive(Clone,Copy,Eq,PartialEq,Debug,Ord,PartialOrd)] pub enum Number { Integer(i64), Rational(i32,u32) } fn cp_decode((c1,c2,c3): (u8,u8,u8)) -> char { let c = (c1 as u32)*65536 + (c2 as u32)*256 + (c3 as u32); unsafe { char::from_u32_unchecked(c) } } enum CharIterInternal { Iterator(slice::Iter<'static, (u8,u8,u8)>), Double(char, char), Single(char), Exhausted } pub struct CharIter(CharIterInternal); impl CharIter { pub fn new(osl: Option<&'static [(u8,u8,u8)]>, cp: char) -> CharIter { CharIter(match osl { Some(sl) => CharIterInternal::Iterator(sl.iter()), None => CharIterInternal::Single(cp) }) } pub fn hangul(a: char, b: char) -> CharIter { CharIter(CharIterInternal::Double(a, b)) } } impl Iterator for CharIter { type Item = char; fn next(&mut self) -> Option { match self.0 { CharIterInternal::Iterator(ref mut it) => it.next().map(|c| cp_decode(*c)), CharIterInternal::Double(a, b) => { self.0 = CharIterInternal::Single(b); Some(a) }, CharIterInternal::Single(c) => { self.0 = CharIterInternal::Exhausted; Some(c) }, CharIterInternal::Exhausted => None } } fn size_hint(&self) -> (usize, Option) { match self.0 { CharIterInternal::Iterator(ref it) => it.size_hint(), CharIterInternal::Double(_, _) => (2, Some(2)), CharIterInternal::Single(_) => (1, Some(1)), CharIterInternal::Exhausted => (0, Some(0)) } } } pub trait Codepoint where Self: core::marker::Sized { // general fn age(self) -> Option<(u8,u8)>; fn block(self) -> Option; fn category(self) -> UnicodeCategory; fn codepoint(self) -> char; fn iso_comment(self) -> &'static str; // function and appearance fn is_alphabetic(self) -> bool; fn is_alphabetic_other(self) -> bool; fn is_dash(self) -> bool; fn is_default_ignorable(self) -> bool; fn is_default_ignorable_other(self) -> bool; fn is_deprecated(self) -> bool; fn is_diacritic(self) -> bool; fn is_extender(self) -> bool; fn is_hex_digit(self) -> bool; fn is_hex_digit_ascii(self) -> bool; fn is_hyphen(self) -> bool; fn is_logical_order_exception(self) -> bool; fn is_math(self) -> bool; fn is_math_other(self) -> bool; fn is_noncharacter(self) -> bool; fn is_preprended_concatenation_mark(self) -> bool; fn is_quotation_mark(self) -> bool; fn is_sentence_terminal(self) -> bool; fn is_soft_dotted(self) -> bool; fn is_terminal_punctuation(self) -> bool; fn is_variation_selector(self) -> bool; fn is_whitespace(self) -> bool; // numeric fn numeric_type(self) -> Option; fn numeric_value(self) -> Option; // identifiers and syntax fn is_id_continue(self) -> bool; fn is_id_continue_nfkc(self) -> bool; fn is_id_continue_other(self) -> bool; fn is_id_start(self) -> bool; fn is_id_start_nfkc(self) -> bool; fn is_id_start_other(self) -> bool; fn is_pattern_syntax(self) -> bool; fn is_pattern_whitespace(self) -> bool; // scripts fn east_asian_width(self) -> EastAsianWidth; fn hangul_syllable_type(self) -> Option; fn jamo_short_name(self) -> Option<&'static str>; fn indic_positional_category(self) -> Option; fn indic_syllabic_category(self) -> IndicSyllabicCategory; fn is_ideograph(self) -> bool; fn is_ideograph_description_sequence_binary_operator(self) -> bool; fn is_ideograph_description_sequence_radical(self) -> bool; fn is_ideograph_description_sequence_trinary_operator(self) -> bool; fn is_ideograph_unified(self) -> bool; fn join_control(self) -> bool; fn joining_group(self) -> JoiningGroup; fn joining_type(self) -> JoiningType; fn script(self) -> Option