Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement some syntax sugar traits #8

Merged
merged 5 commits into from
Dec 19, 2021
Merged

Conversation

TianyiShi2001
Copy link
Contributor

@TianyiShi2001 TianyiShi2001 commented Jun 18, 2021

This PR addresses issue #7 . Three traits are being implemented, which allows ergonomic conversion between kana and romaji; checking whether a &str is Japanese; and checking whether a char is Japanese, using default options (although additional methods with a _with_opt suffix can be added to these traits, which can fully replace the current API). Should we deprecate the old functions and fully migrate to the new API in the next major version, or should both sets of API be kept?

Examples:

use wana_kana::Convert;
// or use wana_kana::traits::*
// 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");
use wana_kana::IsJapaneseStr;
// or `use wana_kana::traits::*`
assert_eq!("げーむ".is_hiragana(), true);
assert_eq!("A".is_hiragana(), false);
assert_eq!("あア".is_hiragana(), false);

assert_eq!("ゲーム".is_katakana(), true);
assert_eq!("あ".is_katakana(), false);
assert_eq!("A".is_katakana(), false);
assert_eq!("あア".is_katakana(), false);

assert_eq!("あ".is_kana(), true);
assert_eq!("ア".is_kana(), true);
assert_eq!("あーア".is_kana(), true);
assert_eq!("A".is_kana(), false);
assert_eq!("あAア".is_kana(), false);

assert_eq!("A".is_romaji(), true);
assert_eq!("xYz".is_romaji(), true);
assert_eq!("Tōkyō and Ōsaka".is_romaji(), true);
assert_eq!("あアA".is_romaji(), false);
assert_eq!("お願い".is_romaji(), false);
assert_eq!("熟成".is_romaji(), false);
assert_eq!("a*b&c-d".is_romaji(), true);
assert_eq!("0123456789".is_romaji(), true);
assert_eq!("a!b&cーd".is_romaji(), false);
assert_eq!("hello".is_romaji(), false);

assert_eq!("刀".is_kanji(), true);
assert_eq!("切腹".is_kanji(), true);
assert_eq!("勢い".is_kanji(), false);
assert_eq!("あAア".is_kanji(), false);
assert_eq!("🐸".is_kanji(), false);

assert_eq!("泣き虫".is_japanese(), true);
assert_eq!("あア".is_japanese(), true);
assert_eq!("2月".is_japanese(), true); // Zenkaku numbers allowed
assert_eq!("泣き虫。!〜$".is_japanese(), true); // Zenkaku/JA punctuation
assert_eq!("泣き虫.!~$".is_japanese(), false); // Latin punctuation fails
assert_eq!("A".is_japanese(), false);

assert_eq!("Aア".is_mixed(), true);
assert_eq!("Aあ".is_mixed(), true);
assert_eq!("Aあア".is_mixed(), true);
assert_eq!("2あア".is_mixed(), false);
assert_eq!("お腹A".is_mixed(), true);

@TianyiShi2001 TianyiShi2001 marked this pull request as draft June 18, 2021 18:09
src/traits.rs Outdated Show resolved Hide resolved
@PSeitz
Copy link
Owner

PSeitz commented Jun 20, 2021

Looks good except minor comment regarding naming.

I think it would be good to keep the API, to avoid break if it is not necessary, but the docs should be updated to use the traits as the preferred way.

@TianyiShi2001 TianyiShi2001 marked this pull request as ready for review June 27, 2021 00:52
@magnus-ISU
Copy link

Any reason this isn't merged? I'm considering using this library for a project, and it seems like work is done.

@PSeitz
Copy link
Owner

PSeitz commented Dec 18, 2021

Sorry completely forgot about that, I will look at it tomorrow

@PSeitz PSeitz merged commit 1f5e7d7 into PSeitz:master Dec 19, 2021
@PSeitz
Copy link
Owner

PSeitz commented Dec 19, 2021

Looks good, thank you!

@PSeitz
Copy link
Owner

PSeitz commented Dec 19, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants