Skip to main content

hex_digit

Function hex_digit 

Source
pub const fn hex_digit(byte: u8) -> Option<u8>
Expand description

The value of one ASCII hexadecimal digit, either case, and None for any other byte.

A caller that wants the permissive reading — a bad digit counts as zero — spells it as hex_digit(b).unwrap_or(0), so the permissiveness is visible at the one place it is meant.

use pdfrum_common::hex_digit;

assert_eq!(hex_digit(b'7'), Some(7));
assert_eq!(hex_digit(b'a'), Some(10));
assert_eq!(hex_digit(b'F'), Some(15));
assert_eq!(hex_digit(b'g'), None);
assert_eq!(hex_digit(b' '), None);