From 57d917b14820f73f2d64d4794df51525ae56bb6c Mon Sep 17 00:00:00 2001 From: Aslam Ahammed Date: Tue, 10 Mar 2020 22:51:22 +0530 Subject: [PATCH] =?UTF-8?q?Fix=20lint=20errors,=20make=20clippy=20happy=20?= =?UTF-8?q?=F0=9F=98=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/convert.rs | 33 +++++++++++++-------------------- src/lib.rs | 4 +--- src/map_parser.rs | 12 ++++++------ 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/convert.rs b/src/convert.rs index 4cf5d39..249778a 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -42,14 +42,12 @@ pub fn convert_to_mltt( let mut temp_map: HashMap = HashMap::new(); if text_to_convert.len() >= 9 { for (index, ch) in text_to_convert.char_indices() { - if ch == '്' { - if index >= 3 && index + 3 < text_to_convert.len() { - let left_char = get_prev_char(&text_to_convert, index); - let right_char = get_next_char(&text_to_convert, index); - let key = format!("{}്{}", left_char, right_char); - if let Some(value) = map.get(&key) { - temp_map.insert(key, value.to_string()); - } + if index >= 3 && index + 3 < text_to_convert.len() && ch == '്' { + let left_char = get_prev_char(&text_to_convert, index); + let right_char = get_next_char(&text_to_convert, index); + let key = format!("{}്{}", left_char, right_char); + if let Some(value) = map.get(&key) { + temp_map.insert(key, value.to_string()); } } } @@ -77,25 +75,20 @@ pub fn convert_to_mltt( for key in left_combinators { if let Some(value) = map.get(&key) { while let Some(index) = text_to_convert.find(&key) { - let right_char = get_prev_char(&text_to_convert, index); + let right_char = get_prev_char(&text_to_convert, index).to_string(); if "്ര" == format!("്{}", right_char) { let prev_right_char = format!("്{}", right_char); let right_char = get_nth_char_from(&text_to_convert, index, -3); - let prev_right_val = map.get(&format!("{}", prev_right_char)).unwrap(); - let right_val = map.get(&format!("{}", right_char)).unwrap(); + let prev_right_val = map.get(&prev_right_char.to_string()).unwrap(); + let right_val = map.get(&right_char.to_string()).unwrap(); let new_key = format!("{}{}{}", right_char, prev_right_char, key); let new_val = format!("{}{}{}", value, prev_right_val, right_val); text_to_convert = text_to_convert.replace(&new_key, &new_val); } - if let Some(right_val) = map.get(&format!("{}", right_char)) { - let new_key = format!("{}{}", right_char, key); - let new_val = format!("{}{}", value, right_val); - text_to_convert = text_to_convert.replace(&new_key, &new_val); - } else { - let new_key = format!("{}{}", right_char, key); - let new_val = format!("{}{}", value, right_char); - text_to_convert = text_to_convert.replace(&new_key, &new_val); - } + let right_val = map.get(&right_char).unwrap_or(&right_char); + let new_key = format!("{}{}", right_char, key); + let new_val = format!("{}{}", value, right_val); + text_to_convert = text_to_convert.replace(&new_key, &new_val); } } else { eprintln!("{:#?} not found in the map!", key); diff --git a/src/lib.rs b/src/lib.rs index 4235426..c4b97f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,9 +24,7 @@ extern "C" { #[wasm_bindgen] pub fn convert(text_to_convert: &str, map_content: &str) -> String { set_panic_hook(); - let converted_text = - convert_text(text_to_convert, map_content).unwrap_or_else(|_| String::from("")); - converted_text + convert_text(text_to_convert, map_content).unwrap_or_else(|_| String::from("")) } pub fn convert_text(text_to_convert: &str, map_content: &str) -> Result> { diff --git a/src/map_parser.rs b/src/map_parser.rs index 1c3acd7..6ebe306 100644 --- a/src/map_parser.rs +++ b/src/map_parser.rs @@ -3,24 +3,24 @@ use std::error::Error; pub fn parse_content(content: &str) -> Result>, Box> { let content = content - .split("\n") - .filter(|x| x.len() >= 1 && x.chars().nth(0) != Some('#') && x.contains("=")) + .split('\n') + .filter(|x| !x.is_empty() && x.chars().nth(0) != Some('#') && x.contains('=')) .map(|x| { - x.split("=") + x.split('=') .map(|s| s.trim()) .map(String::from) .collect::>() }) - .filter(|x| x[1].len() >= 1 && x[0].len() >= 1) + .filter(|x| !x[1].is_empty() && !x[0].is_empty()) .collect::>(); Ok(content) } pub fn create_unicode_to_mltt_map( - content: &Vec>, + content: &[Vec], ) -> Result, Box> { let map = content - .into_iter() + .iter() .map(|s| (s[1].to_owned(), s[0].to_owned())) .collect::>(); Ok(map)