Skip to content

Commit 95446b4

Browse files
committed
[ucd/unihan] Implement simplified and traditional variant
1 parent 2c85558 commit 95446b4

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

unic/ucd/unihan/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ extern crate unic_char_property;
1919
mod readings;
2020
pub use readings::{definition_of, mandarin_of};
2121

22+
mod variants;
23+
pub use variants::{simplified_variant_of, traditional_variant_of};
24+
2225
use unic_ucd_version::UnicodeVersion;
2326

2427
mod pkg_info;

unic/ucd/unihan/src/variants.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 simplified_variant_of(ch: char) -> Option<char> {
13+
data::SIMPLIFIED_VARIANT.find(ch)
14+
}
15+
16+
pub fn traditional_variant_of(ch: char) -> Option<char> {
17+
data::TRADITIONAL_VARIANT.find(ch)
18+
}
19+
20+
mod data {
21+
use unic_char_property::tables::CharDataTable;
22+
pub const SIMPLIFIED_VARIANT: CharDataTable<char> =
23+
include!("../tables/simplified_variant_map.rsv");
24+
pub const TRADITIONAL_VARIANT: CharDataTable<char> =
25+
include!("../tables/traditional_variant_map.rsv");
26+
}

unic/ucd/unihan/tests/basic_tests.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
extern crate unic_ucd_unihan;
1212

13-
use unic_ucd_unihan::{definition_of, mandarin_of};
13+
use unic_ucd_unihan::{
14+
definition_of,
15+
mandarin_of,
16+
simplified_variant_of,
17+
traditional_variant_of,
18+
};
1419

1520
#[test]
1621
fn test_definition() {
@@ -23,3 +28,15 @@ fn test_mandarin() {
2328
assert_eq!(mandarin_of('\u{0001}'), None);
2429
assert_eq!(mandarin_of('\u{340c}'), Some("yí"));
2530
}
31+
32+
#[test]
33+
fn test_simplified_variant() {
34+
assert_eq!(simplified_variant_of('\u{0001}'), None);
35+
assert_eq!(simplified_variant_of('\u{380f}'), Some('\u{37c6}'));
36+
}
37+
38+
#[test]
39+
fn test_traditional_variant() {
40+
assert_eq!(traditional_variant_of('\u{0001}'), None);
41+
assert_eq!(traditional_variant_of('\u{37c6}'), Some('\u{380f}'));
42+
}

0 commit comments

Comments
 (0)