|
|
|
@ -20,7 +20,15 @@ pub struct UnicodeData<'a> {
|
|
|
|
string_table: StringTable<'a>,
|
|
|
|
string_table: StringTable<'a>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const UNICODE_DATA_BYTES: &[u8] = include_bytes!(
|
|
|
|
|
|
|
|
concat!(env!("OUT_DIR"), "/unicode_data_encoded")
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> UnicodeData<'a> {
|
|
|
|
impl<'a> UnicodeData<'a> {
|
|
|
|
|
|
|
|
pub fn new() -> Result<Self, UnicodeDataError> {
|
|
|
|
|
|
|
|
Self::from_bytes(UNICODE_DATA_BYTES)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn from_bytes(bs: &'a [u8]) -> Result<Self, UnicodeDataError> {
|
|
|
|
pub(crate) fn from_bytes(bs: &'a [u8]) -> Result<Self, UnicodeDataError> {
|
|
|
|
let mut bs = ByteStream(bs);
|
|
|
|
let mut bs = ByteStream(bs);
|
|
|
|
|
|
|
|
|
|
|
|
@ -436,3 +444,35 @@ impl fmt::Display for UnicodeDataError {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::UnicodeData;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
|
|
fn test_data_decode() {
|
|
|
|
|
|
|
|
let data = UnicodeData::new().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x0).unwrap().name(), "<control>");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x0).unwrap().unicode_1_name(), Some("NULL"));
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x1).unwrap().name(), "<control>");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x1).unwrap().unicode_1_name(), Some("START OF HEADING"));
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x2).unwrap().name(), "<control>");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x2).unwrap().unicode_1_name(), Some("START OF TEXT"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x377).unwrap().name(), "GREEK SMALL LETTER PAMPHYLIAN DIGAMMA");
|
|
|
|
|
|
|
|
assert!(data.get(0x378).is_none());
|
|
|
|
|
|
|
|
assert!(data.get(0x379).is_none());
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x37a).unwrap().name(), "GREEK YPOGEGRAMMENI");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x33ff).unwrap().name(), "SQUARE GAL");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x3400).unwrap().name(), "CJK Ideograph Extension A");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x3401).unwrap().name(), "CJK Ideograph Extension A");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x3402).unwrap().name(), "CJK Ideograph Extension A");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x4dbe).unwrap().name(), "CJK Ideograph Extension A");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x4dbf).unwrap().name(), "CJK Ideograph Extension A");
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x4dc0).unwrap().name(), "HEXAGRAM FOR THE CREATIVE HEAVEN");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(data.get(0x1039f).unwrap().name(), "UGARITIC WORD DIVIDER");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|