pkstrings: clippy

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-11-19 21:00:52 +01:00
parent b824fe6512
commit 0dcff8ed80
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -26,27 +26,24 @@ use std::error::Error as StdError;
use std::ops::Deref; use std::ops::Deref;
const fn in_range(ord: u8) -> bool { const fn in_range(ord: u8) -> bool {
match ord { matches!(ord, 0x00 |
0x00 |
0x49..=0x4c | 0x4e..=0x5f | // Control characters 0x49..=0x4c | 0x4e..=0x5f | // Control characters
0x60..=0x78 | // Holdover from the japanese game 0x60..=0x78 | // Holdover from the japanese game
0x79..=0x7f | // Text box borders 0x79..=0x7f | // Text box borders
0x80..=0xbf | 0x80..=0xbf |
0xe0..=0xff => true, 0xe0..=0xff)
_ => false,
}
} }
const fn chrtohex(chr: &char) -> Option<u8> { const fn chrtohex(chr: &char) -> Option<u8> {
Some(match chr { Some(match chr {
cap @ 'A'..='Z' => 0x80 - ('A' as u8) + (*cap as u8), cap @ 'A'..='Z' => 0x80 - b'A' + (*cap as u8),
'(' => 0x9a, '(' => 0x9a,
')' => 0x9b, ')' => 0x9b,
':' => 0x9c, ':' => 0x9c,
';' => 0x9d, ';' => 0x9d,
'[' => 0x9e, '[' => 0x9e,
']' => 0x9f, ']' => 0x9f,
low @ 'a'..='z' => 0xa0 - ('a' as u8) + (*low as u8), low @ 'a'..='z' => 0xa0 - b'a' + (*low as u8),
'\'' => 0xe0, '\'' => 0xe0,
'-' => 0xe3, '-' => 0xe3,
'?' => 0xe6, '?' => 0xe6,
@ -68,7 +65,7 @@ const fn chrtohex(chr: &char) -> Option<u8> {
'/' => 0xf3, '/' => 0xf3,
',' => 0xf4, ',' => 0xf4,
'♀' => 0xf5, '♀' => 0xf5,
num @ '0'..='9' => 0xf6 - ('0' as u8) + (*num as u8), num @ '0'..='9' => 0xf6 - b'0' + (*num as u8),
' ' => 0x7f, ' ' => 0x7f,
'@' => 0x50, '@' => 0x50,
_ => return None, _ => return None,
@ -77,14 +74,14 @@ const fn chrtohex(chr: &char) -> Option<u8> {
const fn hextochr(hex: u8) -> Option<char> { const fn hextochr(hex: u8) -> Option<char> {
Some(match hex { Some(match hex {
cap @ 0x80..=0x99 => (('A' as u8) + (cap - 0x80)) as char, cap @ 0x80..=0x99 => (b'A' + (cap - 0x80)) as char,
0x9a => '(', 0x9a => '(',
0x9b => ')', 0x9b => ')',
0x9c => ':', 0x9c => ':',
0x9d => ';', 0x9d => ';',
0x9e => '[', 0x9e => '[',
0x9f => ']', 0x9f => ']',
low @ 0xa0..=0xb9 => (('a' as u8) + (low - 0xa0)) as char, low @ 0xa0..=0xb9 => (b'a' + (low - 0xa0)) as char,
0xe0 => '\'', 0xe0 => '\'',
0xe3 => '-', 0xe3 => '-',
0xe6 => '?', 0xe6 => '?',
@ -99,7 +96,7 @@ const fn hextochr(hex: u8) -> Option<char> {
0xf3 => '/', 0xf3 => '/',
0xf4 => ',', 0xf4 => ',',
0xf5 => '♀', 0xf5 => '♀',
num @ 0xf6..=0xff => (('0' as u8) + (num - 0xf6)) as char, num @ 0xf6..=0xff => (b'0' + (num - 0xf6)) as char,
0x7f => ' ', 0x7f => ' ',
0x50 => '@', 0x50 => '@',
_ => return None, _ => return None,
@ -204,7 +201,7 @@ impl From<&PKString> for String {
for ord in &pkstr.0 { for ord in &pkstr.0 {
match hextochr(*ord) { match hextochr(*ord) {
Some(chr) => buf.push(chr), Some(chr) => buf.push(chr),
None => buf.push(placeholder.clone()), None => buf.push(placeholder),
} }
} }