pub fn read_digits_of_base(input: &Input<'_>, offset: usize, base: u8) -> usizeExpand description
Reads a sequence of bytes representing digits in a specific numerical base.
This utility function iterates through the input byte slice, consuming bytes
as long as they represent valid digits for the given base. It handles
decimal digits (‘0’-‘9’) and hexadecimal digits (‘a’-‘f’, ‘A’-‘F’).
It stops consuming at the first byte that is not a valid digit character,
or is a digit character whose value is greater than or equal to the specified base
(e.g., ‘8’ in base 8, or ‘A’ in base 10).
This function is primarily intended as a helper for lexer implementations when tokenizing the digit part of number literals (binary, octal, decimal, hexadecimal).
§Arguments
input- A byte slice starting at the potential first digit of the number.base- The numerical base (e.g., 2, 8, 10, 16) to use for validating digits. Must be between 2 and 36 (inclusive) for hex characters to be potentially valid.
§Returns
The number of bytes (usize) consumed from the beginning of the input slice
that constitute a valid sequence of digits for the specified base. Returns 0 if
the first byte is not a valid digit for the base.