Implement clippy suggestions

This commit is contained in:
Henry Schimke
2023-01-04 14:48:16 -06:00
parent c65eadf102
commit 48287631dd
196 changed files with 2465 additions and 2574 deletions

View File

@@ -33,8 +33,8 @@ impl BitMatrixParser {
*/
pub fn new(bitMatrix: &BitMatrix) -> Result<Self, Exceptions> {
let dimension = bitMatrix.getHeight();
if dimension < 8 || dimension > 144 || (dimension & 0x01) != 0 {
return Err(Exceptions::FormatException("".to_owned()));
if !(8..=144).contains(&dimension) || (dimension & 0x01) != 0 {
return Err(Exceptions::FormatException(None));
}
let version = Self::readVersion(bitMatrix)?;
@@ -50,7 +50,7 @@ impl BitMatrixParser {
}
pub fn getVersion(&self) -> &Version {
&self.version
self.version
}
/**
@@ -178,7 +178,7 @@ impl BitMatrixParser {
}
if resultOffset != self.version.getTotalCodewords() as usize {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
}
Ok(result)
@@ -257,7 +257,7 @@ impl BitMatrixParser {
if self.readModule(row, column, numRows, numColumns) {
currentByte |= 1;
}
return currentByte;
currentByte
}
/**
@@ -302,7 +302,7 @@ impl BitMatrixParser {
if self.readModule(3, numColumns - 1, numRows, numColumns) {
currentByte |= 1;
}
return currentByte;
currentByte
}
/**
@@ -347,7 +347,7 @@ impl BitMatrixParser {
if self.readModule(1, numColumns - 1, numRows, numColumns) {
currentByte |= 1;
}
return currentByte;
currentByte
}
/**
@@ -392,7 +392,7 @@ impl BitMatrixParser {
if self.readModule(1, numColumns - 1, numRows, numColumns) {
currentByte |= 1;
}
return currentByte;
currentByte
}
/**
@@ -437,7 +437,7 @@ impl BitMatrixParser {
if self.readModule(3, numColumns - 1, numRows, numColumns) {
currentByte |= 1;
}
return currentByte;
currentByte
}
/**
@@ -455,9 +455,9 @@ impl BitMatrixParser {
let symbolSizeColumns = version.getSymbolSizeColumns();
if bitMatrix.getHeight() != symbolSizeRows {
return Err(Exceptions::IllegalArgumentException(
return Err(Exceptions::IllegalArgumentException(Some(
"Dimension of bitMatrix must match the version size".to_owned(),
));
)));
}
let dataRegionSizeRows = version.getDataRegionSizeRows();

View File

@@ -93,9 +93,11 @@ impl DataBlock {
let mut rawCodewordsOffset = 0;
for i in 0..shorterBlocksNumDataCodewords {
// for (int i = 0; i < shorterBlocksNumDataCodewords; i++) {
for j in 0..numRXingResultBlocks {
for res in result.iter_mut().take(numRXingResultBlocks) {
// for j in 0..numRXingResultBlocks {
// for (int j = 0; j < numRXingResultBlocks; j++) {
result[j].codewords[i] = rawCodewords[rawCodewordsOffset];
res.codewords[i] = rawCodewords[rawCodewordsOffset];
rawCodewordsOffset += 1;
}
}
@@ -107,10 +109,10 @@ impl DataBlock {
} else {
numRXingResultBlocks
};
for j in 0..numLongerBlocks {
for res in result.iter_mut().take(numLongerBlocks) {
// for j in 0..numLongerBlocks {
// for (int j = 0; j < numLongerBlocks; j++) {
result[j].codewords[longerBlocksNumDataCodewords - 1] =
rawCodewords[rawCodewordsOffset];
res.codewords[longerBlocksNumDataCodewords - 1] = rawCodewords[rawCodewordsOffset];
rawCodewordsOffset += 1;
}
@@ -136,7 +138,7 @@ impl DataBlock {
}
if rawCodewordsOffset != rawCodewords.len() {
return Err(Exceptions::IllegalArgumentException("".to_owned()));
return Err(Exceptions::IllegalArgumentException(None));
}
Ok(result)

View File

@@ -137,7 +137,7 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
decodeECISegment(&mut bits, &mut result)?;
isECIencoded = true; // ECI detection only, atm continue decoding as ASCII
}
_ => return Err(Exceptions::FormatException("".to_owned())),
_ => return Err(Exceptions::FormatException(None)),
};
mode = Mode::ASCII_ENCODE;
}
@@ -145,7 +145,7 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
break;
}
} //while (mode != Mode.PAD_ENCODE && bits.available() > 0);
if resultTrailer.len() > 0 {
if !resultTrailer.is_empty() {
result.appendCharacters(&resultTrailer);
}
if isECIencoded {
@@ -158,14 +158,12 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
} else {
symbologyModifier = 4;
}
} else if fnc1Positions.contains(&0) || fnc1Positions.contains(&4) {
symbologyModifier = 2;
} else if fnc1Positions.contains(&1) || fnc1Positions.contains(&5) {
symbologyModifier = 3;
} else {
if fnc1Positions.contains(&0) || fnc1Positions.contains(&4) {
symbologyModifier = 2;
} else if fnc1Positions.contains(&1) || fnc1Positions.contains(&5) {
symbologyModifier = 3;
} else {
symbologyModifier = 1;
}
symbologyModifier = 1;
}
Ok(DecoderRXingResult::with_symbology(
@@ -196,7 +194,7 @@ fn decodeAsciiSegment(
loop {
let mut oneByte = bits.readBits(8)?;
if oneByte == 0 {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
} else if oneByte <= 128 {
// ASCII data (ASCII value + 1)
if upperShift {
@@ -256,11 +254,11 @@ fn decodeAsciiSegment(
// Not to be used in ASCII encodation
// but work around encoders that end with 254, latch back to ASCII
if oneByte != 254 || bits.available() != 0 {
return Err(Exceptions::FormatException("".to_owned()))
return Err(Exceptions::FormatException(None))
}},
}
}
if !(bits.available() > 0) {
if bits.available() == 0 {
break;
}
} //while (bits.available() > 0);
@@ -296,9 +294,10 @@ fn decodeC40Segment(
parseTwoBytes(firstByte, bits.readBits(8)?, &mut cValues);
for i in 0..3 {
for cValue in cValues {
// for i in 0..3 {
// for (int i = 0; i < 3; i++) {
let cValue = cValues[i];
// let cValue = cValues[i];
match shift {
0 => {
if cValue < 3 {
@@ -312,15 +311,15 @@ fn decodeC40Segment(
result.append_char(c40char);
}
} else {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
}
}
1 => {
if upperShift {
result.append_char(char::from_u32((cValue + 128) as u32).unwrap());
result.append_char(char::from_u32(cValue + 128).unwrap());
upperShift = false;
} else {
result.append_char(char::from_u32(cValue as u32).unwrap());
result.append_char(char::from_u32(cValue).unwrap());
}
shift = 0;
}
@@ -346,25 +345,25 @@ fn decodeC40Segment(
upperShift = true
}
_ => return Err(Exceptions::FormatException("".to_owned())),
_ => return Err(Exceptions::FormatException(None)),
}
}
shift = 0;
}
3 => {
if upperShift {
result.append_char(char::from_u32(cValue as u32 + 224).unwrap());
result.append_char(char::from_u32(cValue + 224).unwrap());
upperShift = false;
} else {
result.append_char(char::from_u32(cValue as u32 + 96).unwrap());
result.append_char(char::from_u32(cValue + 96).unwrap());
}
shift = 0;
}
_ => return Err(Exceptions::FormatException("".to_owned())),
_ => return Err(Exceptions::FormatException(None)),
}
}
if !(bits.available() > 0) {
if bits.available() == 0 {
break;
}
} //while (bits.available() > 0);
@@ -409,14 +408,13 @@ fn decodeTextSegment(
} else if cValue < TEXT_BASIC_SET_CHARS.len() as u32 {
let textChar = TEXT_BASIC_SET_CHARS[cValue as usize];
if upperShift {
result
.append_char(char::from_u32(textChar as u32 + 128 as u32).unwrap());
result.append_char(char::from_u32(textChar as u32 + 128_u32).unwrap());
upperShift = false;
} else {
result.append_char(textChar);
}
} else {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
}
}
1 => {
@@ -452,7 +450,7 @@ fn decodeTextSegment(
upperShift = true
}
_ => return Err(Exceptions::FormatException("".to_owned())),
_ => return Err(Exceptions::FormatException(None)),
}
}
shift = 0;
@@ -468,14 +466,14 @@ fn decodeTextSegment(
}
shift = 0;
} else {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
}
}
_ => return Err(Exceptions::FormatException("".to_owned())),
_ => return Err(Exceptions::FormatException(None)),
}
}
if !(bits.available() > 0) {
if bits.available() == 0 {
break;
}
} //while (bits.available() > 0);
@@ -543,12 +541,12 @@ fn decodeAnsiX12Segment(
// A - Z
result.append_char(char::from_u32(cValue + 51).unwrap());
} else {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
}
}
}
}
if !(bits.available() > 0) {
if bits.available() == 0 {
break;
}
} //while (bits.available() > 0);
@@ -601,7 +599,7 @@ fn decodeEdifactSegment(
result.append_char(char::from_u32(edifactValue).unwrap());
}
if !(bits.available() > 0) {
if bits.available() == 0 {
break;
}
}
@@ -635,18 +633,19 @@ fn decodeBase256Segment(
// We're seeing NegativeArraySizeException errors from users.
// but we shouldn't in rust because it's unsigned
// if count < 0 {
// return Err(Exceptions::FormatException("".to_owned()));
// return Err(Exceptions::FormatException(None));
// }
let mut bytes = vec![0u8; count as usize];
for i in 0..count as usize {
for byte in bytes.iter_mut().take(count as usize) {
// for i in 0..count as usize {
// for (int i = 0; i < count; i++) {
// Have seen this particular error in the wild, such as at
// http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
if bits.available() < 8 {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
}
bytes[i] = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8;
*byte = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8;
codewordPosition += 1;
}
result.append_string(
@@ -665,7 +664,7 @@ fn decodeBase256Segment(
*/
fn decodeECISegment(bits: &mut BitSource, result: &mut ECIStringBuilder) -> Result<(), Exceptions> {
if bits.available() < 8 {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
}
let c1 = bits.readBits(8)?;
if c1 <= 127 {

View File

@@ -50,7 +50,7 @@ impl Decoder {
* @throws ChecksumException if error correction fails
*/
pub fn decode_bools(&self, image: &Vec<Vec<bool>>) -> Result<DecoderRXingResult, Exceptions> {
self.decode(&BitMatrix::parse_bools(&image))
self.decode(&BitMatrix::parse_bools(image))
}
/**
@@ -72,7 +72,7 @@ impl Decoder {
let version = parser.getVersion();
// Separate into data blocks
let dataBlocks = DataBlock::getDataBlocks(&codewords, &version)?;
let dataBlocks = DataBlock::getDataBlocks(&codewords, version)?;
// Count total number of data bytes
let mut totalBytes = 0;
@@ -140,3 +140,9 @@ impl Decoder {
Ok(())
}
}
impl Default for Decoder {
fn default() -> Self {
Self::new()
}
}

View File

@@ -111,7 +111,7 @@ impl Version {
numColumns: u32,
) -> Result<&'static Version, Exceptions> {
if (numRows & 0x01) != 0 || (numColumns & 0x01) != 0 {
return Err(Exceptions::FormatException("".to_owned()));
return Err(Exceptions::FormatException(None));
}
for version in VERSIONS.iter() {
@@ -120,7 +120,7 @@ impl Version {
}
}
Err(Exceptions::FormatException("".to_owned()))
Err(Exceptions::FormatException(None))
}
/**