Created
November 19, 2015 18:56
-
-
Save pindamonhangaba/3d1bea64a63e2aa2f607 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| func main() { | |
| fmt.Println(kanaSwitch("あ ダ チ ヂ ぃ ok い ぅ hip hip う ぇ え ぉ お か ")) | |
| } | |
| func kanaSwitch(kana string) (out string) { | |
| hr := rune('\u3040') | |
| he := rune('\u3095') | |
| kr := rune('\u30a0') | |
| ke := rune('\u30f5') | |
| diff := int(kr) - int(hr) | |
| runes := []rune(kana) | |
| for _, k := range runes { | |
| if int(k) > int(kr) && int(k) <= int(ke) { | |
| // is katakana | |
| out = out + string(rune(int(k)-diff)) | |
| } else if int(k) > int(hr) && int(k) <= int(he) { | |
| // is hiragana | |
| out = out + string(rune(int(k)+diff)) | |
| } else { | |
| out = out + string(k) | |
| } | |
| } | |
| return out | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment