refactor to use exception helper factories

This commit is contained in:
Vukašin Stepanović
2023-02-15 10:46:13 +00:00
parent 3e27279dc8
commit 722ce78fd0
132 changed files with 966 additions and 1132 deletions

View File

@@ -50,7 +50,7 @@ impl OneDReader for Code128Reader {
CODE_START_A => CODE_CODE_A,
CODE_START_B => CODE_CODE_B,
CODE_START_C => CODE_CODE_C,
_ => return Err(Exceptions::FormatException(None)),
_ => return Err(Exceptions::formatEmpty()),
};
let mut done = false;
@@ -100,9 +100,7 @@ impl OneDReader for Code128Reader {
// Take care of illegal start codes
match code {
CODE_START_A | CODE_START_B | CODE_START_C => {
return Err(Exceptions::FormatException(None))
}
CODE_START_A | CODE_START_B | CODE_START_C => return Err(Exceptions::formatEmpty()),
_ => {}
}
@@ -296,21 +294,21 @@ impl OneDReader for Code128Reader {
row.getSize().min(nextStart + (nextStart - lastStart) / 2),
false,
)? {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFoundEmpty());
}
// Pull out from sum the value of the penultimate check code
checksumTotal -= multiplier as usize * lastCode as usize;
// lastCode is the checksum then:
if (checksumTotal % 103) as u8 != lastCode {
return Err(Exceptions::ChecksumException(None));
return Err(Exceptions::checksumEmpty());
}
// Need to pull out the check digits from string
let resultLength = result.chars().count();
if resultLength == 0 {
// false positive
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFoundEmpty());
}
// Only bother if the result had at least one character, and if the checksum digit happened to
@@ -331,9 +329,7 @@ impl OneDReader for Code128Reader {
let rawCodesSize = rawCodes.len();
let mut rawBytes = vec![0u8; rawCodesSize];
for (i, rawByte) in rawBytes.iter_mut().enumerate().take(rawCodesSize) {
*rawByte = *rawCodes
.get(i)
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
*rawByte = *rawCodes.get(i).ok_or(Exceptions::indexOutOfBoundsEmpty())?;
}
let mut resultObject = RXingResult::new(
&result,
@@ -407,7 +403,7 @@ impl Code128Reader {
}
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFoundEmpty())
}
fn decodeCode(
@@ -432,7 +428,7 @@ impl Code128Reader {
if bestMatch >= 0 {
Ok(bestMatch as u8)
} else {
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFoundEmpty())
}
}
}