I have the following code
fn main() { let text = ".?;,!!!"; println!("{:?}", norm(text)); let text = ".?;,!!"; println!("{:?}", norm(text)); let text = ".?;,!"; println!("{:?}", norm(text)); } fn norm<'a>(splittersp: &'a str) -> (&'a str, bool) { let mut res = false; let splitters = if let Some(stripped) = splittersp.strip_suffix("!!") { if splittersp.len() > 2 { if splittersp.chars().nth_back(2).unwrap() != '!' { &splittersp[..splittersp.len() - 1] } else { res = true; stripped } } else { &splittersp[..splittersp.len() - 1] } } else if let Some(stripped) = splittersp.strip_suffix("!") { res = true; stripped } else { splittersp }; (splitters, res) } Specifically, I do not like the if splittersp.chars().nth_back(2).unwrap() != '!' {. Is there any way to express it shorter without unwrap?
1 post - 1 participant

