Skip to content

Commit

Permalink
Merge pull request #12 from WeDontPanic/master
Browse files Browse the repository at this point in the history
fix #11
  • Loading branch information
PSeitz authored Jan 16, 2023
2 parents 855b83d + 4983406 commit 44e686c
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ version = "2.1.0"
include = ["src/**/*", "LICENSE", "README.md"]

[dependencies]
fnv = "1.0.6"
itertools = "0.8.1"
fnv = "1.0.7"
itertools = {version = "0.10.5", optional = true}
lazy_static = "1.4.0"
regex = { version = "1.3.1", optional = true }
regex = { version = "1.7.0", optional = true }

[dev-dependencies]
speculate = "0.1.2"

[features]
enable_regex = ["regex"]
tokenize = ["itertools"]
default = []

[[bin]]
Expand Down
1 change: 1 addition & 0 deletions src/is_mixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::utils::is_char_kanji::is_char_kanji;
use crate::utils::is_char_katakana::is_char_katakana;
use crate::utils::is_char_romaji::is_char_romaji;

#[inline]
pub fn is_mixed(input: &str) -> bool {
is_mixed_pass_kanji(input, true)
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! # ワナカナ <--> WanaKana <--> わなかな
//!
//! Utility library for checking and converting between Japanese characters -
//! Utility library for checking and converting between Japanese characters -
//! Hiragana, Katakana - and Romaji (Ported from <https://github.com/WaniKani/WanaKana>)
//!
//! # Conversions
Expand Down Expand Up @@ -66,7 +66,9 @@ pub mod to_kana;
pub mod to_katakana;
pub mod to_romaji;

#[cfg(feature = "tokenize")]
pub mod tokenize;
#[cfg(feature = "tokenize")]
pub mod trim_okurigana;

pub mod constants;
Expand Down
2 changes: 2 additions & 0 deletions src/to_hiragana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use crate::utils::is_char_english_punctuation::is_char_english_punctuation;
use crate::utils::katakana_to_hiragana::*;
use crate::utils::romaji_to_hiragana::romaji_to_hiragana;

#[inline]
pub fn to_hiragana(input: &str) -> String {
to_hiragana_with_opt(input, Options::default())
}

pub fn to_hiragana_with_opt(input: &str, options: Options) -> String {
let config = options;
if config.pass_romaji {
Expand Down
1 change: 1 addition & 0 deletions src/to_kana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use crate::options::Options;
use crate::utils::hiragana_to_katakana::*;

#[inline]
pub fn to_kana(input: &str) -> String {
to_kana_with_opt(input, Options::default())
}
Expand Down
7 changes: 7 additions & 0 deletions src/to_romaji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,13 @@ lazy_static! {
output: "ro",
},
),
(
'ゎ',
Node {
transitions: None,
output: "wa",
},
),
(
'わ',
Node {
Expand Down
37 changes: 37 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,32 @@ pub trait ConvertJapanese {
}

impl ConvertJapanese for &str {
#[inline]
fn to_kana(self) -> String {
crate::to_kana::to_kana(self)
}

#[inline]
fn to_kana_with_opt(self, options: Options) -> String {
crate::to_kana::to_kana_with_opt(self, options)
}

#[inline]
fn to_hiragana(self) -> String {
crate::to_hiragana::to_hiragana(self)
}

#[inline]
fn to_katakana(self) -> String {
crate::to_katakana::to_katakana(self)
}

#[inline]
fn to_romaji(self) -> String {
crate::to_romaji::to_romaji(self)
}

#[inline]
fn to_romaji_with_opt(self, options: Options) -> String {
crate::to_romaji::to_romaji_with_opt(self, options)
}
Expand Down Expand Up @@ -187,24 +198,37 @@ pub trait IsJapaneseStr {
}

impl IsJapaneseStr for &str {
#[inline]
fn is_hiragana(self) -> bool {
crate::is_hiragana::is_hiragana(self)
}

#[inline]
fn is_katakana(self) -> bool {
crate::is_katakana::is_katakana(self)
}

#[inline]
fn is_kana(self) -> bool {
crate::is_kana::is_kana(self)
}

#[inline]
fn is_kanji(self) -> bool {
crate::is_kanji::is_kanji(self)
}

#[inline]
fn is_japanese(self) -> bool {
crate::is_japanese::is_japanese(self)
}

#[inline]
fn is_romaji(self) -> bool {
crate::is_romaji::is_romaji(self)
}

#[inline]
fn is_mixed(self) -> bool {
crate::is_mixed::is_mixed(self)
}
Expand All @@ -230,24 +254,37 @@ pub trait IsJapaneseChar {
}

impl IsJapaneseChar for char {
#[inline]
fn is_hiragana(self) -> bool {
crate::utils::is_char_hiragana(self)
}

#[inline]
fn is_katakana(self) -> bool {
crate::utils::is_char_katakana(self)
}

#[inline]
fn is_kana(self) -> bool {
crate::utils::is_char_kana(self)
}

#[inline]
fn is_kanji(self) -> bool {
crate::utils::is_char_kanji(self)
}

#[inline]
fn is_japanese(self) -> bool {
crate::utils::is_char_japanese(self)
}

#[inline]
fn is_japanese_number(self) -> bool {
crate::utils::is_char_japanese_number(self)
}

#[inline]
fn is_japanese_punctuation(self) -> bool {
crate::utils::is_char_japanese_punctuation(self)
}
Expand Down
3 changes: 3 additions & 0 deletions src/trim_okurigana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ use crate::tokenize::*;
use crate::utils::is_char_kana::*;
use crate::utils::is_char_kanji::*;

#[inline]
pub fn trim_okurigana(input: &str) -> &str {
trim_okurigana_with_opt(input, false, None)
}

pub fn is_leading_without_initial_kana(input: &str, from_start: bool) -> bool {
from_start && !is_char_kana(input.chars().next().unwrap())
}

#[inline]
pub fn is_trailing_without_final_kana(input: &str, from_start: bool) -> bool {
!from_start && !is_char_kana(input.chars().last().unwrap())
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/is_char_consonant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// * `include_Y` include y as a consonant in test
///
#[inline]
pub fn is_char_consonant(char: char, include_y: bool) -> bool {
match char {
'b' | 'c' | 'd' | 'f' | 'g' | 'h' | 'j' | 'k' | 'l' | 'm' | 'n' | 'p' | 'q' | 'r' | 's' | 't' | 'v' | 'w' | 'x' | 'z' => true,
Expand Down
1 change: 1 addition & 0 deletions src/utils/is_char_slash_dot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::constants::KANA_SLASH_DOT;

/// Tests if char is '・'
#[inline]
pub fn is_char_slash_dot(char: char) -> bool {
char as u32 == KANA_SLASH_DOT
}
Expand Down
8 changes: 5 additions & 3 deletions src/utils/is_char_upper_case.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::utils::is_char_in_range::*;

use crate::constants::{UPPERCASE_END, UPPERCASE_START};
use crate::{
constants::{UPPERCASE_END, UPPERCASE_START},
utils::is_char_in_range::*,
};

/// Tests if char is in English unicode uppercase range
#[inline]
pub fn is_char_upper_case(char: char) -> bool {
is_char_in_range(char, UPPERCASE_START, UPPERCASE_END)
}
Expand Down
2 changes: 2 additions & 0 deletions tests/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ extern crate speculate;
#[cfg(test)]
use speculate::speculate;

#[cfg(feature = "tokenize")]
use wana_kana::tokenize::*;

#[cfg(feature = "tokenize")]
speculate! {

it "tokenize() with no input" {
Expand Down
2 changes: 2 additions & 0 deletions tests/trim_okurigana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ extern crate speculate;
#[cfg(test)]
use speculate::speculate;

#[cfg(feature = "tokenize")]
use wana_kana::trim_okurigana::*;

#[cfg(feature = "tokenize")]
speculate! {
it "trim_okurigana() with no input" {
assert_eq!(trim_okurigana(""), "");
Expand Down

0 comments on commit 44e686c

Please sign in to comment.