Skip to content

Commit 1dbc58e

Browse files
authored
Merge pull request #8 from aynumosir/fix-edge-cases
fix: Fix edge cases for kana converter
2 parents 419917a + a6a09d8 commit 1dbc58e

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

ainu-utils/src/kana/kana.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::constants::{CONSONANTS, SPECIAL_CONSONANTS, VOWELS};
22
use super::linking::link;
33
use super::maps::{TABLE_1, TABLE_2};
4-
use super::symbols::symbols;
4+
use super::symbols::map_symbols;
55
use unicode_normalization::char::is_combining_mark;
66
use unicode_normalization::UnicodeNormalization;
77

@@ -20,7 +20,7 @@ pub fn to_kana(input: &str) -> String {
2020

2121
input = normalize(input);
2222
input = link(input);
23-
input = symbols(input);
23+
input = map_symbols(input);
2424

2525
let chars: Vec<char> = input.chars().collect();
2626

@@ -43,7 +43,7 @@ pub fn to_kana(input: &str) -> String {
4343

4444
if CONSONANTS.contains(&current) {
4545
if let Some(&next) = next {
46-
if current == next && current != 'n' {
46+
if current == next && !['n', 'y', 'w'].contains(&current) {
4747
kana.push_str(TABLE_1.get("t").unwrap());
4848
index += 1;
4949
continue;
@@ -75,6 +75,11 @@ pub fn to_kana(input: &str) -> String {
7575
}
7676
}
7777

78+
if '\'' == current {
79+
index += 1;
80+
continue;
81+
}
82+
7883
kana.push(current);
7984
index += 1;
8085
}

ainu-utils/src/kana/kana_test.rs

+11
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,14 @@ fn test_k_prefix() {
168168
fn test_diacritics() {
169169
assert_eq!(to_kana("kamúy"), "カムイ")
170170
}
171+
172+
#[test]
173+
fn test_yy_and_ww() {
174+
assert_eq!(to_kana("kamuyyukar"), "カムイユカㇻ");
175+
assert_eq!(to_kana("eawwo"), "エアウウォ");
176+
}
177+
178+
#[test]
179+
fn test_glottal_stop() {
180+
assert_eq!(to_kana("hioy'oy"), "ヒオイオイ");
181+
}

ainu-utils/src/kana/symbols.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static SYMBOLS: [(&str, &str); 16] = [
1+
static SYMBOLS: [(&str, &str); 15] = [
22
("-", ""),
33
("=", ""),
44
(" ", " "),
@@ -13,11 +13,10 @@ static SYMBOLS: [(&str, &str); 16] = [
1313
(".", "。"),
1414
("!", "!"),
1515
("?", "?"),
16-
("'", ""),
1716
("`", ""),
1817
];
1918

20-
pub fn symbols(input: String) -> String {
19+
pub fn map_symbols(input: String) -> String {
2120
let mut input = input;
2221

2322
for (from, to) in SYMBOLS.iter() {

0 commit comments

Comments
 (0)