From 0dcff8ed80bb6a227f16451224c0fef3260cff7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 19 Nov 2021 21:00:52 +0100 Subject: [PATCH] pkstrings: clippy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- pkstrings/src/pkstring.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pkstrings/src/pkstring.rs b/pkstrings/src/pkstring.rs index 8c79768..ac86d51 100644 --- a/pkstrings/src/pkstring.rs +++ b/pkstrings/src/pkstring.rs @@ -26,27 +26,24 @@ use std::error::Error as StdError; use std::ops::Deref; const fn in_range(ord: u8) -> bool { - match ord { - 0x00 | + matches!(ord, 0x00 | 0x49..=0x4c | 0x4e..=0x5f | // Control characters 0x60..=0x78 | // Holdover from the japanese game 0x79..=0x7f | // Text box borders 0x80..=0xbf | - 0xe0..=0xff => true, - _ => false, - } + 0xe0..=0xff) } const fn chrtohex(chr: &char) -> Option { Some(match chr { - cap @ 'A'..='Z' => 0x80 - ('A' as u8) + (*cap as u8), + cap @ 'A'..='Z' => 0x80 - b'A' + (*cap as u8), '(' => 0x9a, ')' => 0x9b, ':' => 0x9c, ';' => 0x9d, '[' => 0x9e, ']' => 0x9f, - low @ 'a'..='z' => 0xa0 - ('a' as u8) + (*low as u8), + low @ 'a'..='z' => 0xa0 - b'a' + (*low as u8), '\'' => 0xe0, '-' => 0xe3, '?' => 0xe6, @@ -68,7 +65,7 @@ const fn chrtohex(chr: &char) -> Option { '/' => 0xf3, ',' => 0xf4, '♀' => 0xf5, - num @ '0'..='9' => 0xf6 - ('0' as u8) + (*num as u8), + num @ '0'..='9' => 0xf6 - b'0' + (*num as u8), ' ' => 0x7f, '@' => 0x50, _ => return None, @@ -77,14 +74,14 @@ const fn chrtohex(chr: &char) -> Option { const fn hextochr(hex: u8) -> Option { Some(match hex { - cap @ 0x80..=0x99 => (('A' as u8) + (cap - 0x80)) as char, + cap @ 0x80..=0x99 => (b'A' + (cap - 0x80)) as char, 0x9a => '(', 0x9b => ')', 0x9c => ':', 0x9d => ';', 0x9e => '[', 0x9f => ']', - low @ 0xa0..=0xb9 => (('a' as u8) + (low - 0xa0)) as char, + low @ 0xa0..=0xb9 => (b'a' + (low - 0xa0)) as char, 0xe0 => '\'', 0xe3 => '-', 0xe6 => '?', @@ -99,7 +96,7 @@ const fn hextochr(hex: u8) -> Option { 0xf3 => '/', 0xf4 => ',', 0xf5 => '♀', - num @ 0xf6..=0xff => (('0' as u8) + (num - 0xf6)) as char, + num @ 0xf6..=0xff => (b'0' + (num - 0xf6)) as char, 0x7f => ' ', 0x50 => '@', _ => return None, @@ -204,7 +201,7 @@ impl From<&PKString> for String { for ord in &pkstr.0 { match hextochr(*ord) { Some(chr) => buf.push(chr), - None => buf.push(placeholder.clone()), + None => buf.push(placeholder), } }