Simplified some local numeric variable types in Rust code.
This commit is contained in:
parent
cdd1d0150d
commit
ddc29b89d7
|
@ -641,10 +641,10 @@ impl QrCode {
|
||||||
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
|
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
|
||||||
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
|
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
|
||||||
fn get_num_raw_data_modules(ver: Version) -> usize {
|
fn get_num_raw_data_modules(ver: Version) -> usize {
|
||||||
let ver = ver.value();
|
let ver = ver.value() as usize;
|
||||||
let mut result: usize = (16 * (ver as usize) + 128) * (ver as usize) + 64;
|
let mut result: usize = (16 * ver + 128) * ver + 64;
|
||||||
if ver >= 2 {
|
if ver >= 2 {
|
||||||
let numalign: usize = (ver as usize) / 7 + 2;
|
let numalign: usize = ver / 7 + 2;
|
||||||
result -= (25 * numalign - 10) * numalign - 55;
|
result -= (25 * numalign - 10) * numalign - 55;
|
||||||
if ver >= 7 {
|
if ver >= 7 {
|
||||||
result -= 36;
|
result -= 36;
|
||||||
|
@ -858,7 +858,7 @@ impl QrSegment {
|
||||||
pub fn make_numeric(text: &[char]) -> Self {
|
pub fn make_numeric(text: &[char]) -> Self {
|
||||||
let mut bb = BitBuffer(Vec::with_capacity(text.len() * 3 + (text.len() + 2) / 3));
|
let mut bb = BitBuffer(Vec::with_capacity(text.len() * 3 + (text.len() + 2) / 3));
|
||||||
let mut accumdata: u32 = 0;
|
let mut accumdata: u32 = 0;
|
||||||
let mut accumcount: u32 = 0;
|
let mut accumcount: u8 = 0;
|
||||||
for c in text {
|
for c in text {
|
||||||
assert!('0' <= *c && *c <= '9', "String contains non-numeric characters");
|
assert!('0' <= *c && *c <= '9', "String contains non-numeric characters");
|
||||||
accumdata = accumdata * 10 + ((*c as u32) - ('0' as u32));
|
accumdata = accumdata * 10 + ((*c as u32) - ('0' as u32));
|
||||||
|
@ -870,7 +870,7 @@ impl QrSegment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if accumcount > 0 { // 1 or 2 digits remaining
|
if accumcount > 0 { // 1 or 2 digits remaining
|
||||||
bb.append_bits(accumdata, (accumcount as u8) * 3 + 1);
|
bb.append_bits(accumdata, accumcount * 3 + 1);
|
||||||
}
|
}
|
||||||
QrSegment::new(QrSegmentMode::Numeric, text.len(), bb.0)
|
QrSegment::new(QrSegmentMode::Numeric, text.len(), bb.0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue