pkstrings: convert HEXTOSTR to Vec

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2020-06-30 18:30:15 +02:00
parent 681813f53a
commit 93d9994859
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -114,7 +114,8 @@ lazy_static! {
} }
map map
}; };
static ref HEXTOSTR: HashMap<u8, char> = {
static ref HEXTOSTR: Vec<Option<char>> = {
let tmp = [ let tmp = [
(0x80, 'A'), (0x80, 'A'),
(0x81, 'B'), (0x81, 'B'),
@ -202,11 +203,11 @@ lazy_static! {
(0x50, '@'), (0x50, '@'),
]; ];
let mut map = HashMap::new(); let mut vec: Vec<Option<char>> = [None; 255].to_vec();
for (k, v) in tmp.iter() { for (k, v) in tmp.iter() {
map.insert(*k, *v); vec[*k] = Some(*v);
} }
map vec
}; };
} }
@ -240,8 +241,9 @@ impl TryFrom<&[u8]> for PKString {
let placeholder = '_'; let placeholder = '_';
for ord in data { for ord in data {
if let Some(chr) = HEXTOSTR.get(&ord) { let ord = *ord as usize;
buf.push(*chr); if let Some(chr) = HEXTOSTR[ord] {
buf.push(chr.clone());
} else { } else {
buf.push(placeholder); buf.push(placeholder);
} }