use super::funejson::Value; use super::validation_gs1_check_digit_gs1_check_digit::gs1_check_digit; /// Whether the last digit of `key` is the GS1 check digit of the digits before /// it. Only the arithmetic: the length, the prefix and an all-zero key are the /// caller's to judge. Validators answer rather than panic, so anything that is /// not two or more ASCII digits is false. pub fn is_gs1_check_digit_valid(key: &str) -> bool { if key.len() < 2 || !key.bytes().all(|b| b.is_ascii_digit()) { return false; } let last = (key.as_bytes()[key.len() - 1] - b'0') as i64; gs1_check_digit(&key[..key.len() - 1]) == last } pub fn fune_vector(args: &[Value]) -> Value { // A non-string argument arrives as an empty string: false, as in the other two. Value::Bool(is_gs1_check_digit_valid(args[0].as_str())) }