1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

extern crate phf;

include!(concat!(env!("OUT_DIR"), "/codegen.rs"));

pub fn get_name(c: u32) -> &'static str {
    match UNICODE.get(&c) {
        Some(s) => s,
        // TODO: Make this automatic?
        None => match c {
            0x3400...0x4DB5 => "CJK Ideograph Extension A",
            0x4E00...0x9FEF => "CJK Ideograph",
            0xAC00...0xD7A3 => "Hangul Syllable",
            0xD800...0xDB7F => "Non Private Use High Surrogate",
            0xDB80...0xDBFF => "Private Use High Surrogate",
            0xDC00...0xDFFF => "Low Surrogate",
            0xE000...0xF8FF => "Private Use",
            0x17000...0x187F7 => "Tangut Ideograph",
            0x20000...0x2A6D6 => "CJK Ideograph Extension B",
            0x2A700...0x2B734 => "CJK Ideograph Extension C",
            0x2B740...0x2B81D => "CJK Ideograph Extension D",
            0x2B820...0x2CEA1 => "CJK Ideograph Extension E",
            0x2CEB0...0x2EBE0 => "CJK Ideograph Extension F",
            0xF0000...0xFFFFD => "Plane 15 Private Use",
            0x100000...0x10FFFD => "Plane 16 Private Use",
            _ => "UNKNOWN CHARACTER",
        },
    }
}

#[cfg(test)]
mod tests {
    use get_name;

    #[test]
    fn normal() {
        assert_eq!(get_name(0), "NULL");
    }

    #[test]
    fn range() {
        assert_eq!(get_name(0x3401), "CJK Ideograph Extension A");
    }
}