From bacfb8c9f4733adc651c400abeb71dd24f06dbd3 Mon Sep 17 00:00:00 2001 From: NSoiffer Date: Wed, 20 Dec 2023 06:11:44 +0000 Subject: [PATCH] fix clippy warnings --- src/braille.rs | 4 ++-- src/interface.rs | 4 ++-- src/main.rs | 28 ++++++++++++++++++++-------- src/prefs.rs | 8 +++----- src/speech.rs | 10 +++++----- src/xpath_functions.rs | 2 +- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/braille.rs b/src/braille.rs index 6d60a8bb..a52ea7d2 100644 --- a/src/braille.rs +++ b/src/braille.rs @@ -638,7 +638,7 @@ fn ueb_cleanup(pref_manager: Ref, raw_braille: String) -> Str } fn convert_to_cap_passage_mode(braille: &str) -> String { - return "⠠⠠⠠".to_string() + &braille.replace(&['C', '𝐶'], "") + "⠠⠄"; + return "⠠⠠⠠".to_string() + &braille.replace(['C', '𝐶'], "") + "⠠⠄"; } /// Return true if the BANA or ICEB guidelines say it is ok to start with grade 2 @@ -2177,7 +2177,7 @@ impl NeedsToBeGrouped { let text = as_text(mathml); let parent = mathml.parent().unwrap().element().unwrap(); // there is always a "math" node let parent_name = name(&parent); // there is always a "math" node - if is_base && (parent_name == "msub" || parent_name == "msup" || parent_name == "msubsup") && !text.contains(&[' ', '\u{00A0}']) { + if is_base && (parent_name == "msub" || parent_name == "msup" || parent_name == "msubsup") && !text.contains([' ', '\u{00A0}']) { return false; } let mut chars = text.chars(); diff --git a/src/interface.rs b/src/interface.rs index 73b4defa..58bd7a6d 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -451,7 +451,7 @@ pub fn trim_element(e: &Element) { } if e.children().is_empty() && !single_text.is_empty() { // debug!("Combining text in {}: '{}' -> '{}'", e.name().local_part(), single_text, trimmed_text); - e.set_text(&trimmed_text); + e.set_text(trimmed_text); } fn make_leaf_element(mathml_leaf: Element) { @@ -493,7 +493,7 @@ pub fn trim_element(e: &Element) { if !text.is_empty() { text += space; } - text += &child_text.trim_matches(WHITESPACE).to_string(); + text += child_text.trim_matches(WHITESPACE); } } diff --git a/src/main.rs b/src/main.rs index eea0537f..3ba4f727 100644 --- a/src/main.rs +++ b/src/main.rs @@ -170,9 +170,21 @@ fn main() { // // "; let expr=r#" - this is a testxa - f(x)=1 - "#; + + + + ( + + 2 + + x + + ) + + 2 + + + "#; // let expr = " // @@ -214,11 +226,11 @@ fn main() { panic!("Error: exiting -- {}", errors_to_string(&e)); }; - // match get_spoken_text() { - // Ok(speech) => info!("Computed speech string:\n '{}'", speech), - // Err(e) => panic!("{}", errors_to_string(&e)), - // } - // info!("SpeechStyle: {:?}", get_preference("SpeechStyle".to_string()).unwrap()); + match get_spoken_text() { + Ok(speech) => info!("Computed speech string:\n '{}'", speech), + Err(e) => panic!("{}", errors_to_string(&e)), + } + info!("SpeechStyle: {:?}", get_preference("SpeechStyle".to_string()).unwrap()); set_preference("BrailleCode".to_string(), "UEB".to_string()).unwrap(); diff --git a/src/prefs.rs b/src/prefs.rs index f73d569d..9945d8cb 100644 --- a/src/prefs.rs +++ b/src/prefs.rs @@ -641,11 +641,9 @@ impl PreferenceManager { Err(_) => return None, // I don't think this is possible Ok(os_path) => os_path, }; - for dir_entry in entries { - if let Ok(entry) = dir_entry { - if entry.file_name().to_str().unwrap_or("").ends_with("_Rules.yaml") { - return Some(entry.file_name().to_str().unwrap().to_string()); - } + for dir_entry in entries.flatten() { + if dir_entry.file_name().to_str().unwrap_or("").ends_with("_Rules.yaml") { + return Some(dir_entry.file_name().to_str().unwrap().to_string()); } } } diff --git a/src/speech.rs b/src/speech.rs index 43080fb0..a1e9db77 100644 --- a/src/speech.rs +++ b/src/speech.rs @@ -44,7 +44,7 @@ pub fn is_quoted_string(str: &str) -> bool { return false; } let bytes = str.as_bytes(); - return &bytes[bytes.len()-N_BYTES_NO_EVAL_QUOTE_CHAR..] == NO_EVAL_QUOTE_CHAR_AS_BYTES; + return bytes[bytes.len()-N_BYTES_NO_EVAL_QUOTE_CHAR..] == NO_EVAL_QUOTE_CHAR_AS_BYTES; } /// Converts 'string' into a "quoted" string -- use is_quoted_string and unquote_string @@ -1746,8 +1746,8 @@ impl UnicodeDef { } else if first_ch != '0' { // exclude 0xDDDD for ch in str.chars() { // restart the iterator let ch_as_str = ch.to_string(); - if let Some(_) = unicode_table.insert(ch as u32, ReplacementArray::build(&substitute_ch(replacements, &ch_as_str)) - .chain_err(|| format!("In definition of char: '{}'", str))?.replacements) { + if unicode_table.insert(ch as u32, ReplacementArray::build(&substitute_ch(replacements, &ch_as_str)) + .chain_err(|| format!("In definition of char: '{}'", str))?.replacements).is_some() { error!("*** Character '{}' (0x{:X}) is repeated", ch, ch as u32); } } @@ -1757,9 +1757,9 @@ impl UnicodeDef { } let ch = UnicodeDef::get_unicode_char(ch)?; - if let Some(_) = unicode_table.insert(ch, ReplacementArray::build(replacements) + if unicode_table.insert(ch, ReplacementArray::build(replacements) .chain_err(|| format!("In definition of char: '{}' (0x{})", - char::from_u32(ch).unwrap(), ch))?.replacements) { + char::from_u32(ch).unwrap(), ch))?.replacements).is_some() { error!("*** Character '{}' (0x{:X}) is repeated", char::from_u32(ch).unwrap(), ch); } return Ok( () ); diff --git a/src/xpath_functions.rs b/src/xpath_functions.rs index 45602f13..13990193 100644 --- a/src/xpath_functions.rs +++ b/src/xpath_functions.rs @@ -1060,7 +1060,7 @@ impl FontSizeGuess { // match one or more digits followed by a unit -- there are many more units, but they tend to be large and rarer(?) static ref FONT_VALUE: Regex = Regex::new(r"(-?[0-9]*\.?[0-9]*)(px|cm|mm|Q|in|ppc|pt|ex|em|rem)").unwrap(); } - let cap = FONT_VALUE.captures(&value_with_unit); + let cap = FONT_VALUE.captures(value_with_unit); if let Some(cap) = cap { if cap.len() == 3 { let multiplier = match &cap[2] { // guess based on 12pt font to convert to ems