pkstrings: convert HEXTOSTR to Vec
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
681813f53a
commit
93d9994859
1 changed files with 8 additions and 6 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue