From 3fea69f9ed226f38dd7533c60ee6b13f833b8b65 Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Mon, 26 Jul 2021 14:03:47 +0800 Subject: [PATCH] inline some code Signed-off-by: Hanif Bin Ariffin --- src/uu/tr/src/operation.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index 2d9e24080..595dcc529 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -47,18 +47,6 @@ pub enum Sequence { } impl Sequence { - // TODO: Can we do better? - pub fn convert_octal_to_char(input: &str) -> char { - if input.starts_with("\\") && input.len() > 1 { - u32::from_str_radix(&input[1..], 8) - .map(|u| char::from_u32(u)) - .unwrap() - .unwrap() - } else { - input.chars().next().unwrap() - } - } - pub fn flatten(&self) -> Box> { match self { Sequence::Char(c) => Box::new(std::iter::once(*c)), @@ -243,7 +231,16 @@ impl Sequence { preceded(tag("\\"), recognize(many_m_n(1, 3, one_of("01234567")))), recognize(anychar), )))(input) - .map(|(l, a)| (l, Sequence::convert_octal_to_char(a))) + .map(|(l, a)| { + ( + l, + if let Some(input) = a.strip_prefix('\\') { + char::from_u32(u32::from_str_radix(&input, 8).unwrap()).unwrap() + } else { + input.chars().next().unwrap() + }, + ) + }) } fn parse_char(input: &str) -> IResult<&str, Sequence> {