diff --git a/ainu-utils/src/kana/kana.rs b/ainu-utils/src/kana/kana.rs index 58e6809..e09978e 100644 --- a/ainu-utils/src/kana/kana.rs +++ b/ainu-utils/src/kana/kana.rs @@ -1,7 +1,7 @@ use super::constants::{CONSONANTS, SPECIAL_CONSONANTS, VOWELS}; use super::linking::link; use super::maps::{TABLE_1, TABLE_2}; -use super::symbols::symbols; +use super::symbols::map_symbols; use unicode_normalization::char::is_combining_mark; use unicode_normalization::UnicodeNormalization; @@ -20,7 +20,7 @@ pub fn to_kana(input: &str) -> String { input = normalize(input); input = link(input); - input = symbols(input); + input = map_symbols(input); let chars: Vec = input.chars().collect(); @@ -43,7 +43,7 @@ pub fn to_kana(input: &str) -> String { if CONSONANTS.contains(¤t) { if let Some(&next) = next { - if current == next && current != 'n' { + if current == next && !['n', 'y', 'w'].contains(¤t) { kana.push_str(TABLE_1.get("t").unwrap()); index += 1; continue; @@ -75,6 +75,11 @@ pub fn to_kana(input: &str) -> String { } } + if '\'' == current { + index += 1; + continue; + } + kana.push(current); index += 1; } diff --git a/ainu-utils/src/kana/kana_test.rs b/ainu-utils/src/kana/kana_test.rs index 571e76f..b580931 100644 --- a/ainu-utils/src/kana/kana_test.rs +++ b/ainu-utils/src/kana/kana_test.rs @@ -168,3 +168,14 @@ fn test_k_prefix() { fn test_diacritics() { assert_eq!(to_kana("kamúy"), "カムイ") } + +#[test] +fn test_yy_and_ww() { + assert_eq!(to_kana("kamuyyukar"), "カムイユカㇻ"); + assert_eq!(to_kana("eawwo"), "エアウウォ"); +} + +#[test] +fn test_glottal_stop() { + assert_eq!(to_kana("hioy'oy"), "ヒオイオイ"); +} diff --git a/ainu-utils/src/kana/symbols.rs b/ainu-utils/src/kana/symbols.rs index 995164d..5b909f2 100644 --- a/ainu-utils/src/kana/symbols.rs +++ b/ainu-utils/src/kana/symbols.rs @@ -1,4 +1,4 @@ -static SYMBOLS: [(&str, &str); 16] = [ +static SYMBOLS: [(&str, &str); 15] = [ ("-", ""), ("=", ""), (" ", " "), @@ -13,11 +13,10 @@ static SYMBOLS: [(&str, &str); 16] = [ (".", "。"), ("!", "!"), ("?", "?"), - ("'", ""), ("`", ""), ]; -pub fn symbols(input: String) -> String { +pub fn map_symbols(input: String) -> String { let mut input = input; for (from, to) in SYMBOLS.iter() {