mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Implement clippy suggestions
This commit is contained in:
@@ -169,14 +169,16 @@ impl BitMatrixParser {
|
||||
let mut result = [0u8; 144];
|
||||
let height = self.0.getHeight() as usize;
|
||||
let width = self.0.getWidth() as usize;
|
||||
for y in 0..height {
|
||||
for (y, bitnrRow) in BITNR.iter().enumerate().take(height) {
|
||||
// for y in 0..height {
|
||||
// for (int y = 0; y < height; y++) {
|
||||
let bitnrRow = BITNR[y];
|
||||
for x in 0..width {
|
||||
// let bitnrRow = BITNR[y];
|
||||
for (x, bit) in bitnrRow.iter().enumerate().take(width) {
|
||||
// for x in 0..width {
|
||||
// for (int x = 0; x < width; x++) {
|
||||
let bit = bitnrRow[x];
|
||||
if bit >= 0 && self.0.get(x as u32, y as u32) {
|
||||
result[bit as usize / 6] |= 1 << (5 - (bit % 6));
|
||||
// let bit = bitnrRow[x];
|
||||
if *bit >= 0 && self.0.get(x as u32, y as u32) {
|
||||
result[*bit as usize / 6] |= 1 << (5 - (bit % 6));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,19 +85,18 @@ pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions>
|
||||
let mut result = String::with_capacity(144);
|
||||
match mode {
|
||||
2 | 3 => {
|
||||
let postcode;
|
||||
if mode == 2 {
|
||||
let postcode = if mode == 2 {
|
||||
let pc = getPostCode2(bytes);
|
||||
let ps2Length = getPostCode2Length(bytes) as usize;
|
||||
if ps2Length > 10 {
|
||||
return Err(Exceptions::FormatException("".to_owned()));
|
||||
return Err(Exceptions::FormatException(None));
|
||||
}
|
||||
// NumberFormat df = new DecimalFormat("0000000000".substring(0, ps2Length));
|
||||
// postcode = df.format(pc);
|
||||
postcode = format!("{:0>ps2Length$}", pc)
|
||||
format!("{:0>ps2Length$}", pc)
|
||||
} else {
|
||||
postcode = getPostCode3(bytes);
|
||||
}
|
||||
getPostCode3(bytes)
|
||||
};
|
||||
// NumberFormat threeDigits = new DecimalFormat("000");
|
||||
// let country = threeDigits.format(getCountry(bytes));
|
||||
// let service = threeDigits.format(getServiceClass(bytes));
|
||||
@@ -134,11 +133,12 @@ pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions>
|
||||
|
||||
fn getBit(bit: u8, bytes: &[u8]) -> u8 {
|
||||
let bit = bit - 1;
|
||||
if (bytes[bit as usize / 6] & (1 << (5 - (bit % 6)))) == 0 {
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
u8::from((bytes[bit as usize / 6] & (1 << (5 - (bit % 6)))) != 0)
|
||||
// if (bytes[bit as usize / 6] & (1 << (5 - (bit % 6)))) == 0 {
|
||||
// 0
|
||||
// } else {
|
||||
// 1
|
||||
// }
|
||||
}
|
||||
|
||||
fn getInt(bytes: &[u8], x: &[u8]) -> u32 {
|
||||
@@ -259,5 +259,5 @@ fn subtract_two_single_char_strings(str1: &str, str2: &str) -> usize {
|
||||
let str2_u16 =
|
||||
((str2_bytes[0] as usize) << 4) + ((str2_bytes[1] as usize) << 2) + str2_bytes[2] as usize;
|
||||
|
||||
(str1_u16 - str2_u16) as usize
|
||||
str1_u16 - str2_u16
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ pub fn decode_with_hints(
|
||||
correctErrors(&mut codewords, 20, 68, 56, ODD)?;
|
||||
datawords = vec![0u8; 78];
|
||||
}
|
||||
_ => return Err(Exceptions::NotFoundException("".to_owned())),
|
||||
_ => return Err(Exceptions::NotFoundException(None)),
|
||||
}
|
||||
|
||||
datawords[0..10].clone_from_slice(&codewords[0..10]);
|
||||
@@ -79,7 +79,7 @@ pub fn decode_with_hints(
|
||||
datawords[10..datawords_len].clone_from_slice(&codewords[20..datawords_len + 10]);
|
||||
// System.arraycopy(codewords, 20, datawords, 10, datawords.length - 10);
|
||||
|
||||
return decoded_bit_stream_parser::decode(&datawords, mode);
|
||||
decoded_bit_stream_parser::decode(&datawords, mode)
|
||||
}
|
||||
|
||||
fn correctErrors(
|
||||
|
||||
@@ -62,7 +62,7 @@ impl Reader for MaxiCodeReader {
|
||||
// Note that MaxiCode reader effectively always assumes PURE_BARCODE mode
|
||||
// and can't detect it in an image
|
||||
let bits = Self::extractPureBits(image.getBlackMatrix())?;
|
||||
let decoderRXingResult = decoder::decode_with_hints(bits, &hints)?;
|
||||
let decoderRXingResult = decoder::decode_with_hints(bits, hints)?;
|
||||
let mut result = RXingResult::new(
|
||||
decoderRXingResult.getText(),
|
||||
decoderRXingResult.getRawBytes().clone(),
|
||||
@@ -97,7 +97,7 @@ impl MaxiCodeReader {
|
||||
fn extractPureBits(image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
||||
let enclosingRectangleOption = image.getEnclosingRectangle();
|
||||
if enclosingRectangleOption.is_none() {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let enclosingRectangle = enclosingRectangleOption.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user