8000 Fix normalization of jamo by Manishearth · Pull Request #11 · unicode-rs/unicode-normalization · GitHub
[go: up one dir, main page]

Skip to content

Fix normalization of jamo #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
8000 Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ pub fn compose(a: char, b: char) -> Option<char> {
})
}

// Constants from Unicode 7.0.0 Section 3.12 Conjoining Jamo Behavior
// Constants from Unicode 9.0.0 Section 3.12 Conjoining Jamo Behavior
// http://www.unicode.org/versions/Unicode9.0.0/ch03.pdf#M9.32468.Heading.310.Combining.Jamo.Behavior
const S_BASE: u32 = 0xAC00;
const L_BASE: u32 = 0x1100;
const V_BASE: u32 = 0x1161;
Expand Down Expand Up @@ -145,12 +146,15 @@ fn compose_hangul(a: char, b: char) -> Option<char> {
let l = a as u32;
let v = b as u32;
// Compose an LPart and a VPart
if L_BASE <= l && l < (L_BASE + L_COUNT) && V_BASE <= v && v < (V_BASE + V_COUNT) {
if L_BASE <= l && l < (L_BASE + L_COUNT) // l should be an L choseong jamo
&& V_BASE <= v && v < (V_BASE + V_COUNT) { // v should be a V jungseong jamo
let r = S_BASE + (l - L_BASE) * N_COUNT + (v - V_BASE) * T_COUNT;
return unsafe { Some(transmute(r)) };
}
// Compose an LVPart and a TPart
if S_BASE <= l && l <= (S_BASE+S_COUNT-T_COUNT) && T_BASE <= v && v < (T_BASE+T_COUNT) {
if S_BASE <= l && l <= (S_BASE+S_COUNT-T_COUNT) // l should be a syllable block
&& T_BASE <= v && v < (T_BASE+T_COUNT) // v should be a T jongseong jamo
&& (l - S_BASE) % T_COUNT == 0 { // l should be an LV syllable block (not LVT)
let r = l + (v - T_BASE);
return unsafe { Some(transmute(r)) };
}
Expand Down
Loading
0