| 1 | /// A set of ranges that corresponds to the set of all ideograph codepoints. |
| 2 | /// |
| 3 | /// These ranges are defined in Unicode 4.8 Table 4-13. |
| 4 | pub const RANGE_IDEOGRAPHrust-analyzer cargo ucd-util 0.2.2 ideograph/RANGE_IDEOGRAPH.: &'static [(u32, u32)] = &[ |
| 5 | (0x3400, 0x4DB5), |
| 6 | (0x4E00, 0x9FD5), |
| 7 | (0x4E00, 0x9FD5), |
| 8 | (0x20000, 0x2A6D6), |
| 9 | (0x2A700, 0x2B734), |
| 10 | (0x2B740, 0x2B81D), |
| 11 | (0x2B820, 0x2CEA1), |
| 12 | (0x17000, 0x187EC), |
| 13 | (0xF900, 0xFA6D), |
| 14 | (0xFA70, 0xFAD9), |
| 15 | (0x2F800, 0x2FA1D), |
| 16 | ]; |
| 17 | |
| 18 | /// Return the character name of the given ideograph codepoint. |
| 19 | /// |
| 20 | /// This operation is only defined on ideographic codepoints. This includes |
| 21 | /// precisely the following inclusive ranges: |
| 22 | /// |
| 23 | /// * `3400..4DB5` |
| 24 | /// * `4E00..9FD5` |
| 25 | /// * `20000..2A6D6` |
| 26 | /// * `2A700..2B734` |
| 27 | /// * `2B740..2B81D` |
| 28 | /// * `2B820..2CEA1` |
| 29 | /// * `17000..187EC` |
| 30 | /// * `F900..FA6D` |
| 31 | /// * `FA70..FAD9` |
| 32 | /// * `2F800..2FA1D` |
| 33 | /// |
| 34 | /// If the given codepoint is not in any of the above ranges, then `None` is |
| 35 | /// returned. |
| 36 | /// |
| 37 | /// This implements the algorithm described in Unicode 4.8. |
| 38 | pub fn ideograph_namerust-analyzer cargo ucd-util 0.2.2 ideograph/ideograph_name().(cp: u32) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 39 | // This match should be in sync with the `RANGE_IDEOGRAPH` constant. |
| 40 | match cp { |
| 41 | 0x3400..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x4DB5 |
| 42 | | 0x4E00..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x9FD5 |
| 43 | | 0x20000..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x2A6D6 |
| 44 | | 0x2A700..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x2B734 |
| 45 | | 0x2B740..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x2B81D |
| 46 | | 0x2B820..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x2CEA1 => { |
| 47 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("CJK UNIFIED IDEOGRAPH-{:04X}", cp)) |
| 48 | } |
| 49 | 0x17000..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x187EC => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("TANGUT IDEOGRAPH-{:04X}", cp)), |
| 50 | 0xF900..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0xFA6D | 0xFA70..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0xFAD9 | 0x2F800..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x2FA1D => { |
| 51 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("CJK COMPATIBILITY IDEOGRAPH-{:04X}", cp)) |
| 52 | } |
| 53 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | #[cfg(test)] |
| 58 | mod testsrust-analyzer cargo ucd-util 0.2.2 ideograph/tests/ { |
| 59 | use superrust-analyzer cargo ucd-util 0.2.2 ideograph/::ideograph_namerust-analyzer cargo ucd-util 0.2.2 ideograph/ideograph_name().; |
| 60 | |
| 61 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 62 | fn namerust-analyzer cargo ucd-util 0.2.2 ideograph/tests/name().() { |
| 63 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 64 | ideograph_namerust-analyzer cargo ucd-util 0.2.2 ideograph/ideograph_name().(0x4E00).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 65 | "CJK UNIFIED IDEOGRAPH-4E00" |
| 66 | ); |
| 67 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 68 | ideograph_namerust-analyzer cargo ucd-util 0.2.2 ideograph/ideograph_name().(0x9FD5).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 69 | "CJK UNIFIED IDEOGRAPH-9FD5" |
| 70 | ); |
| 71 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ideograph_namerust-analyzer cargo ucd-util 0.2.2 ideograph/ideograph_name().(0x17000).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "TANGUT IDEOGRAPH-17000"); |
| 72 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 73 | ideograph_namerust-analyzer cargo ucd-util 0.2.2 ideograph/ideograph_name().(0xF900).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 74 | "CJK COMPATIBILITY IDEOGRAPH-F900" |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 79 | fn invalidrust-analyzer cargo ucd-util 0.2.2 ideograph/tests/invalid().() { |
| 80 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ideograph_namerust-analyzer cargo ucd-util 0.2.2 ideograph/ideograph_name().(0).is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 81 | } |
| 82 | } |