File tree 3 files changed +21
-6
lines changed
3 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 1
1
use super :: constants:: { CONSONANTS , SPECIAL_CONSONANTS , VOWELS } ;
2
2
use super :: linking:: link;
3
3
use super :: maps:: { TABLE_1 , TABLE_2 } ;
4
- use super :: symbols:: symbols ;
4
+ use super :: symbols:: map_symbols ;
5
5
use unicode_normalization:: char:: is_combining_mark;
6
6
use unicode_normalization:: UnicodeNormalization ;
7
7
@@ -20,7 +20,7 @@ pub fn to_kana(input: &str) -> String {
20
20
21
21
input = normalize ( input) ;
22
22
input = link ( input) ;
23
- input = symbols ( input) ;
23
+ input = map_symbols ( input) ;
24
24
25
25
let chars: Vec < char > = input. chars ( ) . collect ( ) ;
26
26
@@ -43,7 +43,7 @@ pub fn to_kana(input: &str) -> String {
43
43
44
44
if CONSONANTS . contains ( & current) {
45
45
if let Some ( & next) = next {
46
- if current == next && current != 'n' {
46
+ if current == next && ! [ 'n' , 'y' , 'w' ] . contains ( & current ) {
47
47
kana. push_str ( TABLE_1 . get ( "t" ) . unwrap ( ) ) ;
48
48
index += 1 ;
49
49
continue ;
@@ -75,6 +75,11 @@ pub fn to_kana(input: &str) -> String {
75
75
}
76
76
}
77
77
78
+ if '\'' == current {
79
+ index += 1 ;
80
+ continue ;
81
+ }
82
+
78
83
kana. push ( current) ;
79
84
index += 1 ;
80
85
}
Original file line number Diff line number Diff line change @@ -168,3 +168,14 @@ fn test_k_prefix() {
168
168
fn test_diacritics ( ) {
169
169
assert_eq ! ( to_kana( "kamúy" ) , "カムイ" )
170
170
}
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
+ }
Original file line number Diff line number Diff line change 1
- static SYMBOLS : [ ( & str , & str ) ; 16 ] = [
1
+ static SYMBOLS : [ ( & str , & str ) ; 15 ] = [
2
2
( "-" , "" ) ,
3
3
( "=" , "" ) ,
4
4
( " " , " " ) ,
@@ -13,11 +13,10 @@ static SYMBOLS: [(&str, &str); 16] = [
13
13
( "." , "。" ) ,
14
14
( "!" , "!" ) ,
15
15
( "?" , "?" ) ,
16
- ( "'" , "" ) ,
17
16
( "`" , "" ) ,
18
17
] ;
19
18
20
- pub fn symbols ( input : String ) -> String {
19
+ pub fn map_symbols ( input : String ) -> String {
21
20
let mut input = input;
22
21
23
22
for ( from, to) in SYMBOLS . iter ( ) {
You can’t perform that action at this time.
0 commit comments