diff --git a/brado/src/certidao.rs b/brado/src/certidao.rs index 14061fc..aad5fbe 100644 --- a/brado/src/certidao.rs +++ b/brado/src/certidao.rs @@ -73,10 +73,9 @@ fn generate_digit(doc_slice: &[u16]) -> u16 { let rest: u16 = d % 11; - if rest > 9 { - 1 - } else { - rest + match rest > 9 { + true => 1, + false => rest, } } diff --git a/brado/src/cnh.rs b/brado/src/cnh.rs index 5743219..b276d48 100644 --- a/brado/src/cnh.rs +++ b/brado/src/cnh.rs @@ -67,10 +67,9 @@ fn generate_first_digit(doc_slice: &[u16]) -> (u16, u16) { let rest: u16 = sum % 11; - if rest >= 10 { - (0, 2) - } else { - (rest, 0) + match rest >= 10 { + true => (0, 2), + false => (rest, 0), } } @@ -85,16 +84,14 @@ fn generate_second_digit( } let rest: u16 = sum % 11; - let second: u16 = if rest >= dsc { - rest - dsc - } else { - 11 + rest - dsc + let second: u16 = match rest >= dsc { + true => rest - dsc, + false => 11 + rest - dsc, }; - if second >= 10 { - 0 - } else { - second + match second >= 10 { + true => 0, + false => second, } } diff --git a/brado/src/cnpj.rs b/brado/src/cnpj.rs index 7b80109..8d85521 100644 --- a/brado/src/cnpj.rs +++ b/brado/src/cnpj.rs @@ -4,6 +4,15 @@ use crate::common::{get_digits, get_symbols, random_digit_vector, to_decimal}; const CNPJ_SIZE: usize = 14; +/// Converte um caractere em um dígito válido de CNPJ. +/// +/// CNPJ Alfanumérico: SS.SSS.SSS/SSSS-NN, +/// onde N: Número; S: Letra ou Número. +/// +/// A validação permanece igual, porém, é necessário +/// substituir os caracteres pelos valores respectivos +/// da tabela ASCII e dele subtrair 48. Assim, '0'=0, +/// '1'=1, ..., 'A'=17, 'B'=18, ... fn to_cnpj_digit( i: usize, c: char, diff --git a/brado/src/eleitoral.rs b/brado/src/eleitoral.rs index e1ff526..571d705 100644 --- a/brado/src/eleitoral.rs +++ b/brado/src/eleitoral.rs @@ -68,10 +68,9 @@ fn generate_first_digit(doc_slice: &[u16]) -> u16 { let rest: u16 = sum % 11; - if rest == 10 { - 0 - } else { - rest + match rest { + 10 => 0, + _ => rest, } } @@ -92,10 +91,9 @@ fn generate_second_digit( let rest: u16 = sum % 11; - if rest == 10 { - 0 - } else { - rest + match rest { + 10 => 0, + _ => rest, } } diff --git a/brado/src/nis.rs b/brado/src/nis.rs index 3e8b548..03f8841 100644 --- a/brado/src/nis.rs +++ b/brado/src/nis.rs @@ -67,10 +67,9 @@ fn generate_digit(doc_slice: &[u16]) -> u16 { let rest: u16 = sum % 11; - if rest >= 2 { - 11 - rest - } else { - 0 + match rest >= 2 { + true => 11 - rest, + false => 0, } } diff --git a/brado/src/renavam.rs b/brado/src/renavam.rs index 9a3241e..4eb9dd1 100644 --- a/brado/src/renavam.rs +++ b/brado/src/renavam.rs @@ -61,10 +61,9 @@ fn generate_digit(doc_slice: &[u16]) -> u16 { let rest: u16 = (sum * 10) % 11; - if rest == 10 { - 0 - } else { - rest + match rest { + 10 => 0, + _ => rest, } }