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

Handle clippy warnings #5

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/bin/to_kana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
extern crate wana_kana;
use std::env;

use std::io::prelude::*;
use std::io::{self, Read};

fn main() {
let args: String = env::args().skip(1).collect::<Vec<String>>().join(" ");
if args.len() > 0 {
if !args.is_empty() {
println!("{}", wana_kana::to_kana::to_kana(&args));
} else {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).unwrap();
if buffer.len() > 0 {
// println!("{}", wana_kana::to_kana::to_kana(&buffer));
io::stdout().write(wana_kana::to_kana::to_kana(&buffer).as_bytes()).unwrap();
if !buffer.is_empty() {
print!("{}", wana_kana::to_kana::to_kana(&buffer));
}
}
}
8 changes: 3 additions & 5 deletions src/bin/to_romaji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
extern crate wana_kana;
use std::env;

use std::io::prelude::*;
use std::io::{self, Read};

fn main() {
let args: String = env::args().skip(1).collect::<Vec<String>>().join(" ");
if args.len() > 0 {
if !args.is_empty() {
println!("{}", wana_kana::to_romaji::to_romaji(&args));
} else {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).unwrap();
if buffer.len() > 0 {
// println!("{}", wana_kana::to_romaji::to_romaji(&buffer));
io::stdout().write(wana_kana::to_romaji::to_romaji(&buffer).as_bytes()).unwrap();
if !buffer.is_empty() {
print!("{}", wana_kana::to_romaji::to_romaji(&buffer));
}
}
}
2 changes: 1 addition & 1 deletion src/is_hiragana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn is_hiragana(input: &str) -> bool {
if input.is_empty() {
return false;
}
return input.chars().all(is_char_hiragana);
input.chars().all(is_char_hiragana)
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/is_kana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ pub fn is_kana(input: &str) -> bool {
if input.is_empty() {
return false;
}
return input.chars().all(is_char_kana);
input.chars().all(is_char_kana)
}
4 changes: 2 additions & 2 deletions src/is_kanji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ pub fn is_kanji(input: &str) -> bool {
if input.is_empty() {
return false;
}
return input.chars().all(is_char_kanji);
input.chars().all(is_char_kanji)
}

pub fn contains_kanji(input: &str) -> bool {
if input.is_empty() {
return false;
}
return input.chars().any(is_char_kanji);
input.chars().any(is_char_kanji)
}
2 changes: 1 addition & 1 deletion src/is_katakana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ pub fn is_katakana(input: &str) -> bool {
if input.is_empty() {
return false;
}
return input.chars().all(is_char_katakana);
input.chars().all(is_char_katakana)
}
2 changes: 1 addition & 1 deletion src/is_mixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ pub fn is_mixed_pass_kanji(input: &str, pass_kanji: bool) -> bool {
if !pass_kanji {
has_kanji = input.chars().any(is_char_kanji);
}
return (input.chars().any(is_char_hiragana) || input.chars().any(is_char_katakana)) && input.chars().any(is_char_romaji) && !has_kanji;
(input.chars().any(is_char_hiragana) || input.chars().any(is_char_katakana)) && input.chars().any(is_char_romaji) && !has_kanji
}
2 changes: 1 addition & 1 deletion src/is_romaji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn is_romaji(input: &str) -> bool {
if input.is_empty() {
return false;
}
input.chars().all(|char| is_char_romaji(char))
input.chars().all(is_char_romaji)
}

#[cfg(feature = "enable_regex")]
Expand Down
2 changes: 1 addition & 1 deletion src/to_hiragana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn to_hiragana_with_opt(input: &str, options: Options) -> String {
} else if is_mixed(input) {
let romaji = katakana_to_hiragana(input);
romaji_to_hiragana(&romaji, config)
} else if is_romaji(input) || input.chars().next().map(|c| is_char_english_punctuation(c)).unwrap_or(false) {
} else if is_romaji(input) || input.chars().next().map(is_char_english_punctuation).unwrap_or(false) {
// TODO: is it correct to check only the first char (see src\utils\isCharEnglishPunctuation.js)
romaji_to_hiragana(input, config)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/to_kana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ impl Node {
}
}

pub fn find_transition_node<'a>(&self, char: char) -> Option<&Node> {
pub fn find_transition_node(&self, char: char) -> Option<&Node> {
self.transitions.iter().find(|&t| t.0 == char).map(|t| &t.1)
// self.transitions.binary_search_by_key(&char, |t| t.0).ok().map(|index|&self.transitions[index].1)
}

fn find_transition_mut<'a>(&mut self, char: char) -> Option<&mut (char, Node)> {
fn find_transition_mut(&mut self, char: char) -> Option<&mut (char, Node)> {
self.transitions.iter_mut().find(|t| t.0 == char)
}

Expand Down
2 changes: 1 addition & 1 deletion src/to_romaji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Node {
(curr_node.output, i)
}

pub fn find_transition_node<'a>(&self, char: char) -> Option<&Node> {
pub fn find_transition_node(&self, char: char) -> Option<&Node> {
if let Some(t) = &self.transitions {
t.binary_search_by_key(&char, |t| t.0).ok().map(|index| &t[index].1)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/trim_okurigana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::tokenize::*;
use crate::utils::is_char_kana::*;
use crate::utils::is_char_kanji::*;

pub fn trim_okurigana<'a>(input: &'a str) -> &'a str {
pub fn trim_okurigana(input: &str) -> &str {
trim_okurigana_with_opt(input, false, None)
}

Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn trim_okurigana_with_opt<'a>(input: &'a str, from_start: bool, match_kanji
};

if from_start {
input.trim_start_matches(tokens.iter().next().unwrap())
input.trim_start_matches(tokens.get(0).unwrap())
} else {
input.trim_end_matches(tokens.iter().last().unwrap())
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/get_chunk.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Returns a substring based on character position start/end values
pub fn get_chunk(text: &str, start: usize, end: usize) -> &str {
let start = text.char_indices().nth(start).map(|el| el.0).unwrap_or(0);
let end = text.char_indices().nth(end).map(|el| el.0).unwrap_or(text.len());
let end = text.char_indices().nth(end).map(|el| el.0).unwrap_or_else(|| text.len());
&text[start..end]
}

Expand Down
1 change: 0 additions & 1 deletion src/utils/hiragana_to_katakana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::constants::{HIRAGANA_START, KATAKANA_START};
use crate::utils::is_char_hiragana::*;
use crate::utils::is_char_long_dash::*;
use crate::utils::is_char_slash_dot::*;
use std;

/// Convert [Hiragana](https://en.wikipedia.org/wiki/Hiragana) to [Katakana](https://en.wikipedia.org/wiki/Katakana)
///
Expand Down
4 changes: 2 additions & 2 deletions src/utils/is_char_english_punctuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::constants::EN_PUNCTUATION_RANGES;
use crate::utils::is_char_in_range::*;

pub fn is_char_english_punctuation(char: char) -> bool {
return EN_PUNCTUATION_RANGES
EN_PUNCTUATION_RANGES
.iter()
.any(|el: &[u32; 2]| is_char_in_range(char, el[0], el[1]));
.any(|el: &[u32; 2]| is_char_in_range(char, el[0], el[1]))
}
2 changes: 1 addition & 1 deletion src/utils/is_char_hiragana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn is_char_hiragana(char: char) -> bool {
if is_char_long_dash(char) {
return true;
};
return is_char_in_range(char, HIRAGANA_START, HIRAGANA_END);
is_char_in_range(char, HIRAGANA_START, HIRAGANA_END)
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is_char_in_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#[inline]
pub fn is_char_in_range(char: char, start: u32, end: u32) -> bool {
return start <= char as u32 && char as u32 <= end;
start <= char as u32 && char as u32 <= end
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is_char_japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::constants::JAPANESE_RANGES;
use crate::utils::is_char_in_range::*;

pub fn is_char_japanese(char: char) -> bool {
return JAPANESE_RANGES.iter().any(|el: &[u32; 2]| is_char_in_range(char, el[0], el[1]));
JAPANESE_RANGES.iter().any(|el: &[u32; 2]| is_char_in_range(char, el[0], el[1]))
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/utils/is_char_japanese_punctuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::utils::is_char_in_range::*;
///

pub fn is_char_japanese_punctuation(char: char) -> bool {
return JA_PUNCTUATION_RANGES
JA_PUNCTUATION_RANGES
.iter()
.any(|el: &[u32; 2]| is_char_in_range(char, el[0], el[1]));
.any(|el: &[u32; 2]| is_char_in_range(char, el[0], el[1]))
}
2 changes: 1 addition & 1 deletion src/utils/is_char_kana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::utils::is_char_katakana::*;
///

pub fn is_char_kana(char: char) -> bool {
return is_char_hiragana(char) || is_char_katakana(char);
is_char_hiragana(char) || is_char_katakana(char)
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is_char_kanji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static KANJI_END: u32 = 0x9FAF;

/// Tests a character. Returns true if the character is a CJK ideograph (kanji).
pub fn is_char_kanji(char: char) -> bool {
return is_char_in_range(char, KANJI_START, KANJI_END);
is_char_in_range(char, KANJI_START, KANJI_END)
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is_char_katakana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::utils::is_char_in_range::*;
/// Tests a character. Returns true if the character is [Katakana](https://en.wikipedia.org/wiki/Katakana).

pub fn is_char_katakana(char: char) -> bool {
return is_char_in_range(char, KATAKANA_START, KATAKANA_END);
is_char_in_range(char, KATAKANA_START, KATAKANA_END)
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is_char_long_dash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::constants::PROLONGED_SOUND_MARK;
/// Returns true if char is 'ー'
///
pub fn is_char_long_dash(char: char) -> bool {
return char as u32 == PROLONGED_SOUND_MARK;
char as u32 == PROLONGED_SOUND_MARK
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is_char_punctuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ use crate::utils::is_char_japanese_punctuation::*;
/// Tests a character. Returns true if the character is considered Japanese or English punctuation.

pub fn is_char_punctuation(char: char) -> bool {
return is_char_english_punctuation(char) || is_char_japanese_punctuation(char);
is_char_english_punctuation(char) || is_char_japanese_punctuation(char)
}
2 changes: 1 addition & 1 deletion src/utils/is_char_romaji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::utils::is_char_in_range::*;

/// Tests a character. Returns true if the character is [Romaji](https://en.wikipedia.org/wiki/Romaji) (allowing [Hepburn romanisation](https://en.wikipedia.org/wiki/Hepburn_romanization))
pub fn is_char_romaji(char: char) -> bool {
return ROMAJI_RANGES.iter().any(|el: &[u32; 2]| is_char_in_range(char, el[0], el[1]));
ROMAJI_RANGES.iter().any(|el: &[u32; 2]| is_char_in_range(char, el[0], el[1]))
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is_char_slash_dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::constants::KANA_SLASH_DOT;

/// Tests if char is '・'
pub fn is_char_slash_dot(char: char) -> bool {
return char as u32 == KANA_SLASH_DOT;
char as u32 == KANA_SLASH_DOT
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is_char_upper_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::constants::{UPPERCASE_END, UPPERCASE_START};

/// Tests if char is in English unicode uppercase range
pub fn is_char_upper_case(char: char) -> bool {
return is_char_in_range(char, UPPERCASE_START, UPPERCASE_END);
is_char_in_range(char, UPPERCASE_START, UPPERCASE_END)
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion src/utils/katakana_to_hiragana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::utils::is_char_katakana::*;
use crate::utils::is_char_long_dash::*;
use crate::utils::is_char_slash_dot::*;
use fnv::FnvHashMap;
use std;

pub fn is_char_initial_long_dash(char: char, index: usize) -> bool {
is_char_long_dash(char) && index == 0
Expand Down