Crate wana_kana

source ·
Expand description

ワナカナ <–> WanaKana <–> わなかな

Utility library for checking and converting between Japanese characters - Hiragana, Katakana - and Romaji (Ported from https://github.com/WaniKani/WanaKana)

Conversions

We provide the ConvertJapanese Trait, which is implemented for &str, that allows the same conversions as mentioned above, by calling the corresponding method directly on the &str.

use wana_kana::ConvertJapanese;
// to kana
assert_eq!("o".to_kana(), "お");
assert_eq!("ona".to_kana(), "おな");
assert_eq!("onaji".to_kana(), "おなじ");
assert_eq!("onaji BUTTSUUJI".to_kana(), "おなじ ブッツウジ");
assert_eq!("ONAJI buttsuuji".to_kana(), "オナジ ぶっつうじ");
assert_eq!("座禅‘zazen’スタイル".to_kana(), "座禅「ざぜん」スタイル");
// to hiragana
assert_eq!("toukyou,オオサカ".to_hiragana(), "とうきょう、おおさか");
// to katakana
assert_eq!("toukyou,おおさか".to_katakana(), "トウキョウ、オオサカ");
// to romaji
assert_eq!("ひらがな カタカナ".to_romaji(), "hiragana katakana");

To check whether a string is Japanese, romaji, kana, etc, use the is_* functions in is_* modules, or equivalently use the IsJapaneseStr trait. There are also functions to check a single char available in the utils module, and the corresponding trait is IsJapaneseChar. Refer to the links for detailed information.

Re-exports

pub use traits::ConvertJapanese;
pub use traits::IsJapaneseChar;
pub use traits::IsJapaneseStr;

Modules

Test if all chars of input are Hiragana
Test if input only includes Kanji, Kana, zenkaku punctuation, japanese symbols and numbers.
Test if all chars of input are Kana (Katakana and/or Hiragana)
Test if all chars of input are Kanji (Japanese CJK ideographs)
Test if all chars of input are Katakana
Test if input contains a mix of Romaji and Kana, defaults to pass through Kanji
Test if every char in input is Romaji (allowing Hepburn romanisation)
Convert input to Hiragana
Convert Romaji to Kana, lowercase text will result in Hiragana and uppercase text will result in Katakana.
Convert input to Katakana
Convert kana to romaji
Splits input into array of strings separated by opinionated token types
Strips trailing Okurigana if input is a mix of Kanji and Kana

Macros

Structs