diff options
author | networkException | 2024-01-23 03:23:12 +0100 |
---|---|---|
committer | networkException | 2024-01-23 03:23:12 +0100 |
commit | bbad68da2a4a67a2d3d04cd5dc48d848a210d16d (patch) | |
tree | 40e335186ffd4cde57139b635630972553f2dd54 /lib/src/lib.rs | |
parent | b6a2783918dc4fce469394a01b6c98ff80c52ed6 (diff) |
adfjafjsdhijdofjdesudhhikjujksjsdaljdffsdihjkdjidlrjdjlakahjkljedflsladjojjakhuslhdedjeilulsoksedlajolhekksjkjsskfkifjhwhkd
asdeeaasphkekiesljojokjjolpjfseefapjklwifdehkhhsdswidjsjkafjdfljkihsrojedlojdjfadhasljlsrlljfssikfhjksaurhaskjdjoajjkojjdlaakhhjkksedsdhkhaifsaidkhjdjjadhhjrwpskkhjfsjidldsdkfsdsjjkshakaasklaskjjeklkskjtsfsaskdawkuasfsledajjlatakaasdldskffjpiaadhaskjasddsjfjdskdisfwpekdejdthsdudjdsshdhhsoarjlkjhkahhpihhaokjdtfjfhkukhaelshsokusksiadahjrhfsdkaskhjslhdjdwssohfsfjhsdjjsfaksphfhkawjkufsdllikpkjljusdajjddsjkpdjkjsedswurahidkijdlkakaaslsaskkhidjiakhhsrdjjrfkjthaslssipshadaasoajjfhkjdsihkhhsofdskfleljhuduajfhwjkaijfhdjfeuwrhhskpfidsdhkhhsfsuidkhskjewkuaikhljkkhedhsslhdjdhssdufjfjhskjsjlwkjlhlhdhhsriusdsjsosrsdkjjkfkjksejdshawkdsdjkjkpfsfakhdhhidjisdlojkutskplskshjkkijopkjkethkfdahdr
Diffstat (limited to 'lib/src/lib.rs')
-rw-r--r-- | lib/src/lib.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/src/lib.rs b/lib/src/lib.rs index a8d48b6..b561f13 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -51,15 +51,23 @@ pub fn decode(buf: &[u8]) -> Vec<u8> { let mut out = Vec::new(); for pair in buf.chunks(4) { - out.push((decode_sym(pair[0]) << 6) - + (decode_sym(pair[1]) << 4) - + (decode_sym(pair[2]) << 2) - + decode_sym(pair[3])); + if pair.len() != 4 { + continue; + } + + match (decode_sym(pair[0]), decode_sym(pair[1]), decode_sym(pair[2]), decode_sym(pair[3])) { + (Some(zero), Some(one), Some(two), Some(three)) => out.push((zero << 6) + (one << 4) + (two << 2) + three), + (_, _, _, _) => { + // U+FFFD � REPLACEMENT CHARACTER + out.push(0xFF); + out.push(0xFD); + } + } } out } -pub fn decode_sym(sym: u8) -> u8 { +pub fn decode_sym(sym: u8) -> Option<u8> { let find = |d: &[u8; 4]| -> Option<u8> { d.iter().enumerate().find(|s| s.1 == &sym).map(|s| s.0 as u8) }; @@ -67,7 +75,6 @@ pub fn decode_sym(sym: u8) -> u8 { .or_else(|| find(&HOME_LEFT)) .or_else(|| find(&ABOVE_RIGHT)) .or_else(|| find(&ABOVE_LEFT)) - .unwrap() } |