Skip to content

Commit 2c85558

Browse files
committed
[ucd/unihan] Expose kDefinition and kMandarin
1 parent acd4f12 commit 2c85558

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

unic/ucd/unihan/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ exclude = []
1313

1414
[dependencies]
1515
unic-ucd-version = { path = "../version/", version = "0.7.0" }
16+
unic-char-property = { path = "../../char/property/", version = "0.7.0" }
1617

1718
[badges]
1819
maintenance = { status = "actively-developed" }

unic/ucd/unihan/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#![deny(bad_style, unsafe_code, unused)]
1515

1616
extern crate unic_ucd_version;
17+
extern crate unic_char_property;
18+
19+
mod readings;
20+
pub use readings::{definition_of, mandarin_of};
21+
1722
use unic_ucd_version::UnicodeVersion;
1823

1924
mod pkg_info;

unic/ucd/unihan/src/readings.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2012-2015 The Rust Project Developers.
2+
// Copyright 2017 The UNIC Project Developers.
3+
//
4+
// See the COPYRIGHT file at the top-level directory of this distribution.
5+
//
6+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9+
// option. This file may not be copied, modified, or distributed
10+
// except according to those terms.
11+
12+
pub fn definition_of(ch: char) -> Option<&'static str> {
13+
data::DEFINITIONS.find(ch)
14+
}
15+
16+
pub fn mandarin_of(ch: char) -> Option<&'static str> {
17+
// TODO: When there are two values, then the first is preferred for
18+
// zh-Hans (CN) and the second is preferred for zh-Hant (TW).
19+
data::MANDARINS.find(ch)
20+
}
21+
22+
mod data {
23+
use unic_char_property::tables::CharDataTable;
24+
pub const DEFINITIONS: CharDataTable<&str> = include!("../tables/definition_map.rsv");
25+
pub const MANDARINS: CharDataTable<&str> = include!("../tables/mandarin_map.rsv");
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 The UNIC Project Developers.
2+
//
3+
// See the COPYRIGHT file at the top-level directory of this distribution.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern crate unic_ucd_unihan;
12+
13+
use unic_ucd_unihan::{definition_of, mandarin_of};
14+
15+
#[test]
16+
fn test_definition() {
17+
assert_eq!(definition_of('\u{0001}'), None);
18+
assert_eq!(definition_of('\u{340c}'), Some("a tribe of savages in South China"));
19+
}
20+
21+
#[test]
22+
fn test_mandarin() {
23+
assert_eq!(mandarin_of('\u{0001}'), None);
24+
assert_eq!(mandarin_of('\u{340c}'), Some("yí"));
25+
}

0 commit comments

Comments
 (0)