mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Merge branch 'main' into pr/point_refactor
This commit is contained in:
@@ -65,13 +65,13 @@ impl OneDReader for CodaBarReader {
|
||||
loop {
|
||||
let charOffset = self.toNarrowWidePattern(nextStart);
|
||||
if charOffset == -1 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
// Hack: We store the position in the alphabet table into a
|
||||
// StringBuilder, so that we can access the decoded patterns in
|
||||
// validatePattern. We'll translate to the actual characters later.
|
||||
self.decodeRowRXingResult
|
||||
.push(char::from_u32(charOffset as u32).ok_or(Exceptions::ParseException(None))?);
|
||||
.push(char::from_u32(charOffset as u32).ok_or(Exceptions::parse)?);
|
||||
nextStart += 8;
|
||||
// Stop as soon as we see the end character.
|
||||
if self.decodeRowRXingResult.chars().count() > 1
|
||||
@@ -99,7 +99,7 @@ impl OneDReader for CodaBarReader {
|
||||
// otherwise this is probably a false positive. The exception is if we are
|
||||
// at the end of the row. (I.e. the barcode barely fits.)
|
||||
if nextStart < self.counterLength && trailingWhitespace < lastPatternSize / 2 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
self.validatePattern(startOffset)?;
|
||||
@@ -113,8 +113,7 @@ impl OneDReader for CodaBarReader {
|
||||
.decodeRowRXingResult
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
as usize]
|
||||
.ok_or(Exceptions::indexOutOfBounds)? as usize]
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
@@ -123,23 +122,23 @@ impl OneDReader for CodaBarReader {
|
||||
.decodeRowRXingResult
|
||||
.chars()
|
||||
.next()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
if !Self::arrayContains(&Self::STARTEND_ENCODING, startchar) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
let endchar = self
|
||||
.decodeRowRXingResult
|
||||
.chars()
|
||||
.nth(self.decodeRowRXingResult.chars().count() - 1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
if !Self::arrayContains(&Self::STARTEND_ENCODING, endchar) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
// remove stop/start characters character and check if a long enough string is contained
|
||||
if (self.decodeRowRXingResult.chars().count()) <= Self::MIN_CHARACTER_LENGTH as usize {
|
||||
// Almost surely a false positive ( start + stop + at least 1 character)
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
if !matches!(
|
||||
@@ -243,7 +242,7 @@ impl CodaBarReader {
|
||||
.decodeRowRXingResult
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
as usize];
|
||||
for j in (0_usize..=6).rev() {
|
||||
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
|
||||
@@ -282,7 +281,7 @@ impl CodaBarReader {
|
||||
.decodeRowRXingResult
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
as usize];
|
||||
for j in (0usize..=6).rev() {
|
||||
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
|
||||
@@ -290,7 +289,7 @@ impl CodaBarReader {
|
||||
let category = (j & 1) + ((pattern as usize) & 1) * 2;
|
||||
let size = self.counters[(pos + j)];
|
||||
if (size as f32) < mins[category] || (size as f32) > maxes[category] {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
pattern >>= 1;
|
||||
}
|
||||
@@ -311,7 +310,7 @@ impl CodaBarReader {
|
||||
let mut i = row.getNextUnset(0);
|
||||
let end = row.getSize();
|
||||
if i >= end {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
let mut isWhite = true;
|
||||
let mut count = 0;
|
||||
@@ -363,7 +362,7 @@ impl CodaBarReader {
|
||||
|
||||
i += 2;
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
pub fn arrayContains(array: &[char], key: char) -> bool {
|
||||
|
||||
@@ -44,12 +44,12 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
let firstChar = contents
|
||||
.chars()
|
||||
.next()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_ascii_uppercase();
|
||||
let lastChar = contents
|
||||
.chars()
|
||||
.nth(contents.chars().count() - 1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_ascii_uppercase();
|
||||
let startsNormal = CodaBarReader::arrayContains(&START_END_CHARS, firstChar);
|
||||
let endsNormal = CodaBarReader::arrayContains(&START_END_CHARS, lastChar);
|
||||
@@ -57,26 +57,26 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
let endsAlt = CodaBarReader::arrayContains(&ALT_START_END_CHARS, lastChar);
|
||||
if startsNormal {
|
||||
if !endsNormal {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Invalid start/end guards: {contents}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
// else already has valid start/end
|
||||
contents.to_owned()
|
||||
} else if startsAlt {
|
||||
if !endsAlt {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Invalid start/end guards: {contents}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
// else already has valid start/end
|
||||
contents.to_owned()
|
||||
} else {
|
||||
// Doesn't start with a guard
|
||||
if endsNormal || endsAlt {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Invalid start/end guards: {contents}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
// else doesn't end with guard either, so add a default
|
||||
format!("{DEFAULT_GUARD}{contents}{DEFAULT_GUARD}")
|
||||
@@ -94,9 +94,9 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
) {
|
||||
resultLength += 10;
|
||||
} else {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Cannot encode : '{ch}'"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
// A blank is placed between each character.
|
||||
@@ -109,7 +109,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
let mut c = contents
|
||||
.chars()
|
||||
.nth(index)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_ascii_uppercase();
|
||||
if index == 0 || index == contents.chars().count() - 1 {
|
||||
// The start/end chars are not in the CodaBarReader.ALPHABET.
|
||||
|
||||
@@ -53,7 +53,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::format),
|
||||
};
|
||||
|
||||
let mut done = false;
|
||||
@@ -103,9 +103,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::format),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -299,21 +297,21 @@ impl OneDReader for Code128Reader {
|
||||
row.getSize().min(nextStart + (nextStart - lastStart) / 2),
|
||||
false,
|
||||
)? {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
// 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::checksum);
|
||||
}
|
||||
|
||||
// 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::notFound);
|
||||
}
|
||||
|
||||
// Only bother if the result had at least one character, and if the checksum digit happened to
|
||||
@@ -334,9 +332,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::indexOutOfBounds)?;
|
||||
}
|
||||
let mut resultObject = RXingResult::new(
|
||||
&result,
|
||||
@@ -410,7 +406,7 @@ impl Code128Reader {
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn decodeCode(&self, row: &BitArray, counters: &mut [u32; 6], rowOffset: usize) -> Result<u8> {
|
||||
@@ -430,7 +426,7 @@ impl Code128Reader {
|
||||
if bestMatch >= 0 {
|
||||
Ok(bestMatch as u8)
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,23 +100,23 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32> {
|
||||
let length = contents.chars().count();
|
||||
// Check length
|
||||
if !(1..=80).contains(&length) {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Contents length should be between 1 and 80 characters, but got {length}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
|
||||
// Check for forced code set hint.
|
||||
let mut forcedCodeSet = -1_i32;
|
||||
if hints.contains_key(&EncodeHintType::FORCE_CODE_SET) {
|
||||
let Some(EncodeHintValue::ForceCodeSet(codeSetHint)) = hints.get(&EncodeHintType::FORCE_CODE_SET) else { return Err(Exceptions::IllegalStateException(None)) };
|
||||
let Some(EncodeHintValue::ForceCodeSet(codeSetHint)) = hints.get(&EncodeHintType::FORCE_CODE_SET) else { return Err(Exceptions::illegalState) };
|
||||
match codeSetHint.as_str() {
|
||||
"A" => forcedCodeSet = CODE_CODE_A as i32,
|
||||
"B" => forcedCodeSet = CODE_CODE_B as i32,
|
||||
"C" => forcedCodeSet = CODE_CODE_C as i32,
|
||||
_ => {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Unsupported code set hint: {codeSetHint}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,9 +135,9 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32> {
|
||||
if c > 127 {
|
||||
// no full Latin-1 character set available at the moment
|
||||
// shift and manual code change are not supported
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Bad character in input: ASCII value={c}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,18 +150,18 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32> {
|
||||
// allows no ascii above 95 (no lower caps, no special symbols)
|
||||
{
|
||||
if c > 95 && c <= 127 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Bad character in input for forced code set A: ASCII value={c}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
CODE_CODE_B_I32 =>
|
||||
// allows no ascii below 32 (terminal symbols)
|
||||
{
|
||||
if c <= 32 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Bad character in input for forced code set B: ASCII value={c}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
CODE_CODE_C_I32 =>
|
||||
@@ -173,9 +173,9 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32> {
|
||||
|| ch == ESCAPE_FNC_3
|
||||
|| ch == ESCAPE_FNC_4
|
||||
{
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Bad character in input for forced code set C: ASCII value={c}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -196,8 +196,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>> {
|
||||
while position < length {
|
||||
//Select code to use
|
||||
let newCodeSet = if forcedCodeSet == -1 {
|
||||
chooseCode(contents, position, codeSet)
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
chooseCode(contents, position, codeSet).ok_or(Exceptions::illegalState)?
|
||||
} else {
|
||||
forcedCodeSet as usize // THIS IS RISKY
|
||||
};
|
||||
@@ -210,7 +209,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>> {
|
||||
match contents
|
||||
.chars()
|
||||
.nth(position)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
{
|
||||
ESCAPE_FNC_1 => patternIndex = CODE_FNC_1 as isize,
|
||||
ESCAPE_FNC_2 => patternIndex = CODE_FNC_2 as isize,
|
||||
@@ -230,7 +229,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>> {
|
||||
patternIndex = contents
|
||||
.chars()
|
||||
.nth(position)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
as isize
|
||||
- ' ' as isize;
|
||||
if patternIndex < 0 {
|
||||
@@ -242,7 +241,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>> {
|
||||
patternIndex = contents
|
||||
.chars()
|
||||
.nth(position)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
as isize
|
||||
- ' ' as isize
|
||||
}
|
||||
@@ -250,9 +249,9 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>> {
|
||||
// CODE_CODE_C
|
||||
if position + 1 == length {
|
||||
// this is the last character, but the encoding is C, which always encodes two characers
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
"Bad number of characters for digit only encoding.".to_owned(),
|
||||
)));
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"Bad number of characters for digit only encoding.",
|
||||
));
|
||||
}
|
||||
let s: String = contents
|
||||
.char_indices()
|
||||
@@ -261,7 +260,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>> {
|
||||
.map(|(_u, c)| c)
|
||||
.collect();
|
||||
patternIndex = s.parse::<isize>().map_err(|e| {
|
||||
Exceptions::ParseException(Some(format!("issue parsing {s}: {e}")))
|
||||
Exceptions::parseWith(format!("issue parsing {s}: {e}"))
|
||||
})?;
|
||||
position += 1;
|
||||
} // Also incremented below
|
||||
@@ -537,7 +536,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
if contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
== ESCAPE_FNC_1
|
||||
{
|
||||
addPattern(
|
||||
@@ -557,7 +556,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
addPattern(
|
||||
&mut patterns,
|
||||
s.parse::<usize>().map_err(|e| {
|
||||
Exceptions::ParseException(Some(format!("unable to parse {s} {e}")))
|
||||
Exceptions::parseWith(format!("unable to parse {s} {e}"))
|
||||
})?,
|
||||
&mut checkSum,
|
||||
&mut checkWeight,
|
||||
@@ -573,7 +572,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
let mut patternIndex = match contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
{
|
||||
ESCAPE_FNC_1 => CODE_FNC_1 as isize,
|
||||
ESCAPE_FNC_2 => CODE_FNC_2 as isize,
|
||||
@@ -591,8 +590,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
as isize
|
||||
.ok_or(Exceptions::indexOutOfBounds)? as isize
|
||||
- ' ' as isize
|
||||
}
|
||||
};
|
||||
@@ -683,7 +681,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
minPath: &mut Vec<Vec<Latch>>,
|
||||
) -> Result<u32> {
|
||||
if position >= contents.chars().count() {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
return Err(Exceptions::illegalState);
|
||||
}
|
||||
let mCost = memoizedCost[charset.ordinal()][position];
|
||||
if mCost > 0 {
|
||||
@@ -764,10 +762,10 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
}
|
||||
}
|
||||
if minCost == u32::MAX {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Bad character in input: ASCII value={}",
|
||||
contents.chars().nth(position).unwrap_or('x')
|
||||
))));
|
||||
)));
|
||||
// throw new IllegalArgumentException("Bad character in input: ASCII value=" + (int) contents.charAt(position));
|
||||
}
|
||||
memoizedCost[charset.ordinal()][position] = minCost;
|
||||
|
||||
@@ -60,7 +60,7 @@ impl OneDReader for Code39Reader {
|
||||
one_d_reader::recordPattern(row, nextStart, &mut counters)?;
|
||||
let pattern = Self::toNarrowWidePattern(&counters);
|
||||
if pattern < 0 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
decodedChar = Self::patternToChar(pattern as u32)?;
|
||||
self.decodeRowRXingResult.push(decodedChar);
|
||||
@@ -85,7 +85,7 @@ impl OneDReader for Code39Reader {
|
||||
// If 50% of last pattern size, following last pattern, is not whitespace, fail
|
||||
// (but if it's whitespace to the very end of the image, that's OK)
|
||||
if nextStart != end && (whiteSpaceAfterEnd * 2) < lastPatternSize as usize {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
if self.usingCheckDigit {
|
||||
@@ -96,7 +96,7 @@ impl OneDReader for Code39Reader {
|
||||
self.decodeRowRXingResult
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBounds)?,
|
||||
) {
|
||||
total += pos;
|
||||
}
|
||||
@@ -105,20 +105,20 @@ impl OneDReader for Code39Reader {
|
||||
.decodeRowRXingResult
|
||||
.chars()
|
||||
.nth(max)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
!= Self::ALPHABET_STRING
|
||||
.chars()
|
||||
.nth(total % 43)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
{
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
self.decodeRowRXingResult.truncate(max);
|
||||
}
|
||||
|
||||
if self.decodeRowRXingResult.chars().count() == 0 {
|
||||
// false positive
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let resultString = if self.extendedMode {
|
||||
@@ -246,7 +246,7 @@ impl Code39Reader {
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
// For efficiency, returns -1 on failure. Not throwing here saved as many as 700 exceptions
|
||||
@@ -306,13 +306,13 @@ impl Code39Reader {
|
||||
return Self::ALPHABET_STRING
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None));
|
||||
.ok_or(Exceptions::indexOutOfBounds);
|
||||
}
|
||||
}
|
||||
if pattern == Self::ASTERISK_ENCODING {
|
||||
return Ok('*');
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn decodeExtended(encoded: &str) -> Result<String> {
|
||||
@@ -322,49 +322,46 @@ impl Code39Reader {
|
||||
while i < length {
|
||||
// for i in 0..length {
|
||||
// for (int i = 0; i < length; i++) {
|
||||
let c = encoded
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
let c = encoded.chars().nth(i).ok_or(Exceptions::indexOutOfBounds)?;
|
||||
if c == '+' || c == '$' || c == '%' || c == '/' {
|
||||
let next = encoded
|
||||
.chars()
|
||||
.nth(i + 1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
let mut decodedChar = '\0';
|
||||
match c {
|
||||
'+' => {
|
||||
// +A to +Z map to a to z
|
||||
if ('A'..='Z').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 + 32)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
}
|
||||
'$' => {
|
||||
// $A to $Z map to control codes SH to SB
|
||||
if ('A'..='Z').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 - 64)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
}
|
||||
'%' => {
|
||||
// %A to %E map to control codes ESC to US
|
||||
if ('A'..='E').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 - 38)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
} else if ('F'..='J').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 - 11)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
} else if ('K'..='O').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 + 16)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
} else if ('P'..='T').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 + 43)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
} else if next == 'U' {
|
||||
decodedChar = 0 as char;
|
||||
} else if next == 'V' {
|
||||
@@ -374,18 +371,18 @@ impl Code39Reader {
|
||||
} else if next == 'X' || next == 'Y' || next == 'Z' {
|
||||
decodedChar = 127 as char;
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
}
|
||||
'/' => {
|
||||
// /A to /O map to ! to , and /Z maps to :
|
||||
if ('A'..='O').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 - 32)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
} else if next == 'Z' {
|
||||
decodedChar = ':';
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -34,9 +34,9 @@ impl OneDimensionalCodeWriter for Code39Writer {
|
||||
let mut contents = contents.to_owned();
|
||||
let mut length = contents.chars().count();
|
||||
if length > 80 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Requested contents should be less than 80 digits long, but got {length}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
|
||||
let mut i = 0;
|
||||
@@ -48,14 +48,14 @@ impl OneDimensionalCodeWriter for Code39Writer {
|
||||
contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBounds)?,
|
||||
)
|
||||
.is_none()
|
||||
{
|
||||
contents = Self::tryToConvertToExtendedMode(&contents)?;
|
||||
length = contents.chars().count();
|
||||
if length > 80 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!("Requested contents should be less than 80 digits long, but got {length} (extended full ASCII mode)"))));
|
||||
return Err(Exceptions::illegalArgumentWith(format!("Requested contents should be less than 80 digits long, but got {length} (extended full ASCII mode)")));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ impl OneDimensionalCodeWriter for Code39Writer {
|
||||
pos += Self::appendPattern(&mut result, pos as usize, &narrowWhite, false);
|
||||
//append next character to byte matrix
|
||||
for i in 0..length {
|
||||
let Some(indexInString) = Code39Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::IndexOutOfBoundsException(None))?) else {
|
||||
let Some(indexInString) = Code39Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::indexOutOfBounds)?) else {
|
||||
continue;
|
||||
};
|
||||
Self::toIntArray(
|
||||
@@ -118,58 +118,58 @@ impl Code39Writer {
|
||||
extendedContent.push('$');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + (character as u32 - 1))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character < ' ' {
|
||||
extendedContent.push('%');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + (character as u32 - 27))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character <= ',' || character == '/' || character == ':' {
|
||||
extendedContent.push('/');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + (character as u32 - 33))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character <= '9' {
|
||||
extendedContent.push(
|
||||
char::from_u32('0' as u32 + (character as u32 - 48))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character <= '?' {
|
||||
extendedContent.push('%');
|
||||
extendedContent.push(
|
||||
char::from_u32('F' as u32 + (character as u32 - 59))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character <= 'Z' {
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + (character as u32 - 65))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character <= '_' {
|
||||
extendedContent.push('%');
|
||||
extendedContent.push(
|
||||
char::from_u32('K' as u32 + (character as u32 - 91))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character <= 'z' {
|
||||
extendedContent.push('+');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + (character as u32 - 97))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character as u32 <= 127 {
|
||||
extendedContent.push('%');
|
||||
extendedContent.push(
|
||||
char::from_u32('P' as u32 + (character as u32 - 123))
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Requested content contains a non-encodable character: '{character}'"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ impl OneDReader for Code93Reader {
|
||||
one_d_reader::recordPattern(row, nextStart, &mut theCounters)?;
|
||||
let pattern = Self::toPattern(&theCounters);
|
||||
if pattern < 0 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
decodedChar = Self::patternToChar(pattern as u32)?;
|
||||
self.decodeRowRXingResult.push(decodedChar);
|
||||
@@ -95,12 +95,12 @@ impl OneDReader for Code93Reader {
|
||||
|
||||
// Should be at least one more black module
|
||||
if nextStart == end || !row.get(nextStart) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
if self.decodeRowRXingResult.chars().count() < 2 {
|
||||
// false positive -- need at least 2 checksum digits
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
Self::checkChecksums(&self.decodeRowRXingResult)?;
|
||||
@@ -194,7 +194,7 @@ impl Code93Reader {
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn toPattern(counters: &[u32; 6]) -> i32 {
|
||||
@@ -224,7 +224,7 @@ impl Code93Reader {
|
||||
return Ok(Self::ALPHABET[i]);
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn decodeExtended(encoded: &str) -> Result<String> {
|
||||
@@ -234,55 +234,52 @@ impl Code93Reader {
|
||||
while i < length {
|
||||
// for i in 0..length {
|
||||
// for (int i = 0; i < length; i++) {
|
||||
let c = encoded
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
let c = encoded.chars().nth(i).ok_or(Exceptions::indexOutOfBounds)?;
|
||||
if ('a'..='d').contains(&c) {
|
||||
if i >= length - 1 {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
let next = encoded
|
||||
.chars()
|
||||
.nth(i + 1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
let mut decodedChar = '\0';
|
||||
match c {
|
||||
'd' => {
|
||||
// +A to +Z map to a to z
|
||||
if ('A'..='Z').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 + 32)
|
||||
.ok_or(Exceptions::ParseException(None))?;
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 + 32).ok_or(Exceptions::parse)?;
|
||||
} else {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
'a' => {
|
||||
// $A to $Z map to control codes SH to SB
|
||||
if ('A'..='Z').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 - 64)
|
||||
.ok_or(Exceptions::ParseException(None))?;
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 - 64).ok_or(Exceptions::parse)?;
|
||||
} else {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
'b' => {
|
||||
if ('A'..='E').contains(&next) {
|
||||
// %A to %E map to control codes ESC to USep
|
||||
decodedChar = char::from_u32(next as u32 - 38)
|
||||
.ok_or(Exceptions::ParseException(None))?;
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 - 38).ok_or(Exceptions::parse)?;
|
||||
} else if ('F'..='J').contains(&next) {
|
||||
// %F to %J map to ; < = > ?
|
||||
decodedChar = char::from_u32(next as u32 - 11)
|
||||
.ok_or(Exceptions::ParseException(None))?;
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 - 11).ok_or(Exceptions::parse)?;
|
||||
} else if ('K'..='O').contains(&next) {
|
||||
// %K to %O map to [ \ ] ^ _
|
||||
decodedChar = char::from_u32(next as u32 + 16)
|
||||
.ok_or(Exceptions::ParseException(None))?;
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 + 16).ok_or(Exceptions::parse)?;
|
||||
} else if ('P'..='T').contains(&next) {
|
||||
// %P to %T map to { | } ~ DEL
|
||||
decodedChar = char::from_u32(next as u32 + 43)
|
||||
.ok_or(Exceptions::ParseException(None))?;
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 + 43).ok_or(Exceptions::parse)?;
|
||||
} else if next == 'U' {
|
||||
// %U map to NUL
|
||||
decodedChar = '\0';
|
||||
@@ -296,18 +293,18 @@ impl Code93Reader {
|
||||
// %X to %Z all map to DEL (127)
|
||||
decodedChar = 127 as char;
|
||||
} else {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
'c' => {
|
||||
// /A to /O map to ! to , and /Z maps to :
|
||||
if ('A'..='O').contains(&next) {
|
||||
decodedChar = char::from_u32(next as u32 - 32)
|
||||
.ok_or(Exceptions::ParseException(None))?;
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 - 32).ok_or(Exceptions::parse)?;
|
||||
} else if next == 'Z' {
|
||||
decodedChar = ':';
|
||||
} else {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -337,12 +334,7 @@ impl Code93Reader {
|
||||
for i in (0..checkPosition).rev() {
|
||||
total += weight
|
||||
* Self::ALPHABET_STRING
|
||||
.find(
|
||||
result
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
)
|
||||
.find(result.chars().nth(i).ok_or(Exceptions::indexOutOfBounds)?)
|
||||
.map_or_else(|| -1_i32, |v| v as i32);
|
||||
weight += 1;
|
||||
if weight > weightMax as i32 {
|
||||
@@ -352,10 +344,10 @@ impl Code93Reader {
|
||||
if result
|
||||
.chars()
|
||||
.nth(checkPosition)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
!= Self::ALPHABET[(total as usize) % 47]
|
||||
{
|
||||
Err(Exceptions::ChecksumException(None))
|
||||
Err(Exceptions::checksum)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
||||
let mut contents = Self::convertToExtended(contents)?;
|
||||
let length = contents.chars().count();
|
||||
if length > 80 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!("Requested contents should be less than 80 digits long after converting to extended encoding, but got {length}" ))));
|
||||
return Err(Exceptions::illegalArgumentWith(format!("Requested contents should be less than 80 digits long after converting to extended encoding, but got {length}" )));
|
||||
}
|
||||
|
||||
//length of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar
|
||||
@@ -49,7 +49,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
||||
|
||||
for i in 0..length {
|
||||
// for (int i = 0; i < length; i++) {
|
||||
let Some(indexInString) = Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::IndexOutOfBoundsException(None))?) else {panic!("alphabet")};
|
||||
let Some(indexInString) = Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::indexOutOfBounds)?) else {panic!("alphabet")};
|
||||
pos += Self::appendPattern(
|
||||
&mut result,
|
||||
pos,
|
||||
@@ -66,7 +66,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
||||
Code93Reader::ALPHABET_STRING
|
||||
.chars()
|
||||
.nth(check1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBounds)?,
|
||||
);
|
||||
|
||||
let check2 = Self::computeChecksumIndex(&contents, 15);
|
||||
@@ -157,15 +157,13 @@ impl Code93Writer {
|
||||
// SOH - SUB: ($)A - ($)Z
|
||||
extendedContent.push('a');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + character as u32 - 1)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32('A' as u32 + character as u32 - 1).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character as u32 <= 31 {
|
||||
// ESC - US: (%)A - (%)E
|
||||
extendedContent.push('b');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + character as u32 - 27)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32('A' as u32 + character as u32 - 27).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character == ' ' || character == '$' || character == '%' || character == '+' {
|
||||
// space $ % +
|
||||
@@ -175,7 +173,7 @@ impl Code93Writer {
|
||||
extendedContent.push('c');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + character as u32 - '!' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character <= '9' {
|
||||
extendedContent.push(character);
|
||||
@@ -187,7 +185,7 @@ impl Code93Writer {
|
||||
extendedContent.push('b');
|
||||
extendedContent.push(
|
||||
char::from_u32('F' as u32 + character as u32 - ';' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character == '@' {
|
||||
// @: (%)V
|
||||
@@ -200,7 +198,7 @@ impl Code93Writer {
|
||||
extendedContent.push('b');
|
||||
extendedContent.push(
|
||||
char::from_u32('K' as u32 + character as u32 - '[' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character == '`' {
|
||||
// `: (%)W
|
||||
@@ -210,19 +208,19 @@ impl Code93Writer {
|
||||
extendedContent.push('d');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + character as u32 - 'a' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else if character as u32 <= 127 {
|
||||
// { - DEL: (%)P - (%)T
|
||||
extendedContent.push('b');
|
||||
extendedContent.push(
|
||||
char::from_u32('P' as u32 + character as u32 - '{' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parse)?,
|
||||
);
|
||||
} else {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Requested content contains a non-encodable character: '{character}'"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,8 @@ impl UPCEANReader for EAN13Reader {
|
||||
rowOffset,
|
||||
&upc_ean_reader::L_AND_G_PATTERNS,
|
||||
)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString
|
||||
.push(char::from_u32('0' as u32 + bestMatch as u32 % 10).ok_or(Exceptions::parse)?);
|
||||
|
||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||
|
||||
@@ -90,10 +88,8 @@ impl UPCEANReader for EAN13Reader {
|
||||
while x < 6 && rowOffset < end {
|
||||
let bestMatch =
|
||||
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString
|
||||
.push(char::from_u32('0' as u32 + bestMatch as u32).ok_or(Exceptions::parse)?);
|
||||
|
||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||
|
||||
@@ -152,12 +148,11 @@ impl EAN13Reader {
|
||||
if lgPatternFound == Self::FIRST_DIGIT_ENCODINGS[d] {
|
||||
resultString.insert(
|
||||
0,
|
||||
char::from_u32('0' as u32 + d as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32('0' as u32 + d as u32).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,15 +46,15 @@ impl OneDimensionalCodeWriter for EAN13Writer {
|
||||
}
|
||||
13 => {
|
||||
if !reader.checkStandardUPCEANChecksum(&contents)? {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
"Contents do not pass checksum".to_owned(),
|
||||
)));
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"Contents do not pass checksum",
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Requested contents should be 12 or 13 digits long, but got {length}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,9 @@ impl OneDimensionalCodeWriter for EAN13Writer {
|
||||
let firstDigit = contents
|
||||
.chars()
|
||||
.next()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
||||
.ok_or(Exceptions::parse)? as usize;
|
||||
let parities = EAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit];
|
||||
let mut result = [false; CODE_WIDTH];
|
||||
let mut pos = 0;
|
||||
@@ -80,9 +80,9 @@ impl OneDimensionalCodeWriter for EAN13Writer {
|
||||
let mut digit = contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
||||
.ok_or(Exceptions::parse)? as usize;
|
||||
if (parities >> (6 - i) & 1) == 1 {
|
||||
digit += 10;
|
||||
}
|
||||
@@ -101,9 +101,9 @@ impl OneDimensionalCodeWriter for EAN13Writer {
|
||||
let digit = contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
||||
.ok_or(Exceptions::parse)? as usize;
|
||||
|
||||
pos += EAN13Writer::appendPattern(
|
||||
&mut result,
|
||||
|
||||
@@ -53,10 +53,8 @@ impl UPCEANReader for EAN8Reader {
|
||||
while x < 4 && rowOffset < end {
|
||||
let bestMatch =
|
||||
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString
|
||||
.push(char::from_u32('0' as u32 + bestMatch as u32).ok_or(Exceptions::parse)?);
|
||||
|
||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||
|
||||
@@ -71,10 +69,8 @@ impl UPCEANReader for EAN8Reader {
|
||||
while x < 4 && rowOffset < end {
|
||||
let bestMatch =
|
||||
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString
|
||||
.push(char::from_u32('0' as u32 + bestMatch as u32).ok_or(Exceptions::parse)?);
|
||||
|
||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||
x += 1;
|
||||
|
||||
@@ -56,15 +56,15 @@ impl OneDimensionalCodeWriter for EAN8Writer {
|
||||
}
|
||||
8 => {
|
||||
if !EAN8Reader.checkStandardUPCEANChecksum(&contents)? {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
"Contents do not pass checksum".to_owned(),
|
||||
)));
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"Contents do not pass checksum",
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Requested contents should be 7 or 8 digits long, but got {length}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,10 +81,9 @@ impl OneDimensionalCodeWriter for EAN8Writer {
|
||||
let digit = contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
as usize;
|
||||
.ok_or(Exceptions::indexOutOfBounds)? as usize;
|
||||
pos += Self::appendPattern(&mut result, pos, &upc_ean_reader::L_PATTERNS[digit], false)
|
||||
as usize;
|
||||
}
|
||||
@@ -97,10 +96,9 @@ impl OneDimensionalCodeWriter for EAN8Writer {
|
||||
let digit = contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
as usize;
|
||||
.ok_or(Exceptions::indexOutOfBounds)? as usize;
|
||||
pos += Self::appendPattern(&mut result, pos, &upc_ean_reader::L_PATTERNS[digit], true)
|
||||
as usize;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ impl OneDReader for ITFReader {
|
||||
lengthOK = true;
|
||||
}
|
||||
if !lengthOK {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
|
||||
let mut resultObject = RXingResult::new(
|
||||
@@ -198,13 +198,9 @@ impl ITFReader {
|
||||
}
|
||||
|
||||
let mut bestMatch = self.decodeDigit(&counterBlack)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch).ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString.push(char::from_u32('0' as u32 + bestMatch).ok_or(Exceptions::parse)?);
|
||||
bestMatch = self.decodeDigit(&counterWhite)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch).ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString.push(char::from_u32('0' as u32 + bestMatch).ok_or(Exceptions::parse)?);
|
||||
|
||||
payloadStart += counterDigitPair.iter().sum::<u32>() as usize;
|
||||
}
|
||||
@@ -265,7 +261,7 @@ impl ITFReader {
|
||||
|
||||
if quietCount != 0 {
|
||||
// Unable to find the necessary number of quiet zone pixels.
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@@ -282,7 +278,7 @@ impl ITFReader {
|
||||
let width = row.getSize();
|
||||
let endStart = row.getNextSet(0);
|
||||
if endStart == width {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
Ok(endStart)
|
||||
@@ -377,7 +373,7 @@ impl ITFReader {
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,7 +402,7 @@ impl ITFReader {
|
||||
if bestMatch >= 0 {
|
||||
Ok(bestMatch as u32 % 10)
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,14 +33,14 @@ impl OneDimensionalCodeWriter for ITFWriter {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let length = contents.chars().count();
|
||||
if length % 2 != 0 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
"The length of the input should be even".to_owned(),
|
||||
)));
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"The length of the input should be even",
|
||||
));
|
||||
}
|
||||
if length > 80 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Requested contents should be less than 80 digits long, but got {length}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
|
||||
Self::checkNumeric(contents)?;
|
||||
@@ -52,15 +52,15 @@ impl OneDimensionalCodeWriter for ITFWriter {
|
||||
let one = contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
||||
.ok_or(Exceptions::parse)? as usize;
|
||||
let two = contents
|
||||
.chars()
|
||||
.nth(i + 1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
||||
.ok_or(Exceptions::parse)? as usize;
|
||||
let mut encoding = [0; 10];
|
||||
for j in 0..5 {
|
||||
encoding[2 * j] = PATTERNS[one][j];
|
||||
|
||||
@@ -47,7 +47,7 @@ impl OneDReader for MultiFormatOneDReader {
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
impl MultiFormatOneDReader {
|
||||
@@ -166,7 +166,7 @@ impl Reader for MultiFormatOneDReader {
|
||||
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ impl OneDReader for MultiFormatUPCEANReader {
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ impl Reader for MultiFormatUPCEANReader {
|
||||
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,9 +101,9 @@ pub trait OneDimensionalCodeWriter: Writer {
|
||||
*/
|
||||
fn checkNumeric(contents: &str) -> Result<()> {
|
||||
if !NUMERIC.is_match(contents) {
|
||||
Err(Exceptions::IllegalArgumentException(Some(
|
||||
"Input should only contain digits 0-9".to_owned(),
|
||||
)))
|
||||
Err(Exceptions::illegalArgumentWith(
|
||||
"Input should only contain digits 0-9",
|
||||
))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@@ -164,28 +164,26 @@ impl Writer for L {
|
||||
hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<crate::common::BitMatrix> {
|
||||
if contents.is_empty() {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
"Found empty contents".to_owned(),
|
||||
)));
|
||||
return Err(Exceptions::illegalArgumentWith("Found empty contents"));
|
||||
}
|
||||
|
||||
if width < 0 || height < 0 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Negative size is not allowed. Input: {width}x{height}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
if let Some(supportedFormats) = self.getSupportedWriteFormats() {
|
||||
if !supportedFormats.contains(format) {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Can only encode {supportedFormats:?}, but got {format:?}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
let mut sidesMargin = self.getDefaultMargin();
|
||||
if let Some(EncodeHintValue::Margin(margin)) = hints.get(&EncodeHintType::MARGIN) {
|
||||
sidesMargin = margin.parse::<u32>().map_err(|e| {
|
||||
Exceptions::IllegalArgumentException(Some(format!("couldnt parse {margin}: {e}")))
|
||||
Exceptions::illegalArgumentWith(format!("couldnt parse {margin}: {e}"))
|
||||
})?;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ pub trait OneDReader: Reader {
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +212,7 @@ pub fn recordPattern(row: &BitArray, start: usize, counters: &mut [u32]) -> Resu
|
||||
|
||||
let end = row.getSize();
|
||||
if start >= end {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let mut isWhite = !row.get(start);
|
||||
@@ -235,7 +235,7 @@ pub fn recordPattern(row: &BitArray, start: usize, counters: &mut [u32]) -> Resu
|
||||
// If we read fully the last section of pixels and filled up our counters -- or filled
|
||||
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
|
||||
if !(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end)) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -253,7 +253,7 @@ pub fn recordPatternInReverse(row: &BitArray, start: usize, counters: &mut [u32]
|
||||
}
|
||||
}
|
||||
if numTransitionsLeft >= 0 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
recordPattern(row, start + 1, counters)?;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ pub trait AbstractRSSReaderTrait: OneDReader {
|
||||
return Ok(value as u32);
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,23 +53,13 @@ pub fn buildBitArrayFromString(data: &str) -> Result<BitArray> {
|
||||
// for (int i = 0; i < dotsAndXs.length(); ++i) {
|
||||
if i % 9 == 0 {
|
||||
// spaces
|
||||
if dotsAndXs
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::ParseException(None))?
|
||||
!= ' '
|
||||
{
|
||||
return Err(Exceptions::IllegalStateException(Some(
|
||||
"space expected".to_owned(),
|
||||
)));
|
||||
if dotsAndXs.chars().nth(i).ok_or(Exceptions::parse)? != ' ' {
|
||||
return Err(Exceptions::illegalStateWith("space expected"));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
let currentChar = dotsAndXs
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::ParseException(None))?;
|
||||
let currentChar = dotsAndXs.chars().nth(i).ok_or(Exceptions::parse)?;
|
||||
if currentChar == 'X' || currentChar == 'x' {
|
||||
binary.set(counter);
|
||||
}
|
||||
@@ -91,12 +81,7 @@ pub fn buildBitArrayFromStringWithoutSpaces(data: &str) -> Result<BitArray> {
|
||||
sb.push(' ');
|
||||
let mut i = 0;
|
||||
while i < 8 && current < dotsAndXs_length {
|
||||
sb.push(
|
||||
dotsAndXs
|
||||
.chars()
|
||||
.nth(current)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
sb.push(dotsAndXs.chars().nth(current).ok_or(Exceptions::parse)?);
|
||||
current += 1;
|
||||
|
||||
i += 1;
|
||||
|
||||
@@ -152,7 +152,7 @@ pub fn createDecoder<'a>(
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Err(Exceptions::IllegalStateException(Some(format!(
|
||||
Err(Exceptions::illegalStateWith(format!(
|
||||
"unknown decoder: {information}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ impl AI01decoder for AI01392xDecoder<'_> {}
|
||||
impl AbstractExpandedDecoder for AI01392xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
return Err(crate::Exceptions::notFound);
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
@@ -39,7 +39,7 @@ impl AI01decoder for AI01393xDecoder<'_> {}
|
||||
impl AbstractExpandedDecoder for AI01393xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
return Err(crate::Exceptions::notFound);
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
@@ -57,7 +57,7 @@ impl AbstractExpandedDecoder for AI013x0x1xDecoder<'_> {
|
||||
if self.information.getSize()
|
||||
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE + Self::DATE_SIZE
|
||||
{
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
return Err(crate::Exceptions::notFound);
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
@@ -53,7 +53,7 @@ impl AbstractExpandedDecoder for AI013x0xDecoder<'_> {
|
||||
if self.information.getSize()
|
||||
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE
|
||||
{
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
return Err(crate::Exceptions::notFound);
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
@@ -52,7 +52,7 @@ impl DecodedNumeric {
|
||||
if
|
||||
/*firstDigit < 0 ||*/
|
||||
firstDigit > 10 || /*secondDigit < 0 ||*/ secondDigit > 10 {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -146,7 +146,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
|
||||
// Processing 2-digit AIs
|
||||
|
||||
if rawInformation.chars().count() < 2 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let lookup: String = rawInformation.chars().take(2).collect();
|
||||
@@ -159,7 +159,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
|
||||
}
|
||||
|
||||
if rawInformation.chars().count() < 3 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let firstThreeDigits: String = rawInformation.chars().take(3).collect();
|
||||
@@ -172,7 +172,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
|
||||
}
|
||||
|
||||
if rawInformation.chars().count() < 4 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let threeDigitPlusDigitDataLength = THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.get(&firstThreeDigits);
|
||||
@@ -192,18 +192,18 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
|
||||
return processFixedAI(4, ffdl.length, rawInformation);
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn processFixedAI(aiSize: usize, fieldSize: usize, rawInformation: &str) -> Result<String> {
|
||||
if rawInformation.chars().count() < aiSize {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let ai: String = rawInformation.chars().take(aiSize).collect();
|
||||
|
||||
if rawInformation.chars().count() < aiSize + fieldSize {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let field: String = rawInformation
|
||||
|
||||
@@ -198,7 +198,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
if let Some(r) = result.getDecodedInformation() {
|
||||
Ok(r.clone())
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,8 +344,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
if (5..15).contains(&fiveBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 5,
|
||||
char::from_u32('0' as u32 + fiveBitValue - 5)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32('0' as u32 + fiveBitValue - 5).ok_or(Exceptions::parse)?,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -354,14 +353,14 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
if (64..90).contains(&sevenBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 7,
|
||||
char::from_u32(sevenBitValue + 1).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(sevenBitValue + 1).ok_or(Exceptions::parse)?,
|
||||
));
|
||||
}
|
||||
|
||||
if (90..116).contains(&sevenBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 7,
|
||||
char::from_u32(sevenBitValue + 7).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(sevenBitValue + 7).ok_or(Exceptions::parse)?,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -388,7 +387,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
250 => '?',
|
||||
251 => '_',
|
||||
252 => ' ',
|
||||
_ => return Err(Exceptions::FormatException(None)),
|
||||
_ => return Err(Exceptions::format),
|
||||
};
|
||||
|
||||
Ok(DecodedChar::new(pos + 8, c))
|
||||
@@ -423,8 +422,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
if (5..15).contains(&fiveBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 5,
|
||||
char::from_u32('0' as u32 + fiveBitValue - 5)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32('0' as u32 + fiveBitValue - 5).ok_or(Exceptions::parse)?,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -433,7 +431,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
if (32..58).contains(&sixBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 6,
|
||||
char::from_u32(sixBitValue + 33).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(sixBitValue + 33).ok_or(Exceptions::parse)?,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -444,9 +442,9 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
61 => '.',
|
||||
62 => '/',
|
||||
_ => {
|
||||
return Err(Exceptions::IllegalStateException(Some(format!(
|
||||
return Err(Exceptions::illegalStateWith(format!(
|
||||
"Decoding invalid alphanumeric value: {sixBitValue}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ impl Reader for RSSExpandedReader {
|
||||
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -294,9 +294,7 @@ impl RSSExpandedReader {
|
||||
if let Ok(to_add) = to_add_res {
|
||||
self.pairs.push(to_add);
|
||||
} else if self.pairs.is_empty() {
|
||||
return Err(to_add_res
|
||||
.err()
|
||||
.unwrap_or(Exceptions::IllegalStateException(None)));
|
||||
return Err(to_add_res.err().unwrap_or(Exceptions::illegalState));
|
||||
} else {
|
||||
// exit this loop when retrieveNextPair() fails and throws
|
||||
done = true;
|
||||
@@ -328,7 +326,7 @@ impl RSSExpandedReader {
|
||||
// }
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn checkRows(&mut self, reverse: bool) -> Option<Vec<ExpandedPair>> {
|
||||
@@ -372,10 +370,7 @@ impl RSSExpandedReader {
|
||||
) -> Result<Vec<ExpandedPair>> {
|
||||
for i in currentRow..self.rows.len() {
|
||||
// for (int i = currentRow; i < rows.size(); i++) {
|
||||
let row = self
|
||||
.rows
|
||||
.get(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
let row = self.rows.get(i).ok_or(Exceptions::indexOutOfBounds)?;
|
||||
self.pairs.clear();
|
||||
for collectedRow in &collectedRows.clone() {
|
||||
// for (ExpandedRow collectedRow : collectedRows) {
|
||||
@@ -403,7 +398,7 @@ impl RSSExpandedReader {
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
/// Whether the pairs form a valid find pattern sequence,
|
||||
@@ -541,17 +536,17 @@ impl RSSExpandedReader {
|
||||
|
||||
let firstPoints = pairs
|
||||
.get(0)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.getFinderPattern()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalState)?
|
||||
.getPoints();
|
||||
let lastPoints = pairs
|
||||
.last()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.getFinderPattern()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalState)?
|
||||
.getPoints();
|
||||
|
||||
let mut result = RXingResult::new(
|
||||
@@ -650,9 +645,7 @@ impl RSSExpandedReader {
|
||||
|
||||
let leftChar = self.decodeDataCharacter(
|
||||
row,
|
||||
pattern
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::NotFoundException(None))?,
|
||||
pattern.as_ref().ok_or(Exceptions::notFound)?,
|
||||
isOddPattern,
|
||||
true,
|
||||
)?;
|
||||
@@ -660,18 +653,16 @@ impl RSSExpandedReader {
|
||||
if !previousPairs.is_empty()
|
||||
&& previousPairs
|
||||
.last()
|
||||
.ok_or(Exceptions::NotFoundException(None))?
|
||||
.ok_or(Exceptions::notFound)?
|
||||
.mustBeLast()
|
||||
{
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let rightChar = self
|
||||
.decodeDataCharacter(
|
||||
row,
|
||||
pattern
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::NotFoundException(None))?,
|
||||
pattern.as_ref().ok_or(Exceptions::notFound)?,
|
||||
isOddPattern,
|
||||
false,
|
||||
)
|
||||
@@ -701,13 +692,11 @@ impl RSSExpandedReader {
|
||||
} else if previousPairs.is_empty() {
|
||||
rowOffset = 0;
|
||||
} else {
|
||||
let lastPair = previousPairs
|
||||
.last()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
let lastPair = previousPairs.last().ok_or(Exceptions::indexOutOfBounds)?;
|
||||
rowOffset = lastPair
|
||||
.getFinderPattern()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalState)?
|
||||
.getStartEnd()[1] as i32;
|
||||
}
|
||||
let mut searchingEvenPair = previousPairs.len() % 2 != 0;
|
||||
@@ -759,7 +748,7 @@ impl RSSExpandedReader {
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn reverseCounters(counters: &mut [u32]) {
|
||||
@@ -856,7 +845,7 @@ impl RSSExpandedReader {
|
||||
let expectedElementWidth: f32 =
|
||||
(pattern.getStartEnd()[1] - pattern.getStartEnd()[0]) as f32 / 15.0;
|
||||
if (elementWidth - expectedElementWidth).abs() / expectedElementWidth > 0.3 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
for (i, counter) in counters.iter().enumerate() {
|
||||
@@ -865,12 +854,12 @@ impl RSSExpandedReader {
|
||||
let mut count = (value + 0.5) as i32; // Round
|
||||
if count < 1 {
|
||||
if value < 0.3 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
count = 1;
|
||||
} else if count > 8 {
|
||||
if value > 8.7 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
count = 8;
|
||||
}
|
||||
@@ -910,7 +899,7 @@ impl RSSExpandedReader {
|
||||
let checksumPortion = oddChecksumPortion + evenChecksumPortion;
|
||||
|
||||
if (oddSum & 0x01) != 0 || !(4..=13).contains(&oddSum) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let group = ((13 - oddSum) / 2) as usize;
|
||||
@@ -958,12 +947,12 @@ impl RSSExpandedReader {
|
||||
1 => {
|
||||
if oddParityBad {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
decrementOdd = true;
|
||||
} else {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
decrementEven = true;
|
||||
}
|
||||
@@ -971,12 +960,12 @@ impl RSSExpandedReader {
|
||||
-1 => {
|
||||
if oddParityBad {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
incrementOdd = true;
|
||||
} else {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
incrementEven = true;
|
||||
}
|
||||
@@ -984,7 +973,7 @@ impl RSSExpandedReader {
|
||||
0 => {
|
||||
if oddParityBad {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
// Both bad
|
||||
if oddSum < evenSum {
|
||||
@@ -995,16 +984,16 @@ impl RSSExpandedReader {
|
||||
incrementEven = true;
|
||||
}
|
||||
} else if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::NotFoundException(None)),
|
||||
_ => return Err(Exceptions::notFound),
|
||||
}
|
||||
|
||||
if incrementOdd {
|
||||
if decrementOdd {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
|
||||
}
|
||||
@@ -1013,7 +1002,7 @@ impl RSSExpandedReader {
|
||||
}
|
||||
if incrementEven {
|
||||
if decrementEven {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
Self::increment(&mut self.evenCounts, &self.oddRoundingErrors);
|
||||
}
|
||||
|
||||
@@ -64,12 +64,12 @@ impl OneDReader for RSS14Reader {
|
||||
if right.getCount() > 1 && self.checkChecksum(left, right) {
|
||||
return self
|
||||
.constructRXingResult(left, right)
|
||||
.ok_or(Exceptions::IllegalStateException(None));
|
||||
.ok_or(Exceptions::illegalState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
impl Reader for RSS14Reader {
|
||||
@@ -123,7 +123,7 @@ impl Reader for RSS14Reader {
|
||||
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -340,7 +340,7 @@ impl RSS14Reader {
|
||||
|
||||
if outsideChar {
|
||||
if (oddSum & 0x01) != 0 || !(4..=12).contains(&oddSum) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
let group = ((12 - oddSum) / 2) as usize;
|
||||
let oddWidest = Self::OUTSIDE_ODD_WIDEST[group];
|
||||
@@ -355,7 +355,7 @@ impl RSS14Reader {
|
||||
))
|
||||
} else {
|
||||
if (evenSum & 0x01) != 0 || !(4..=10).contains(&evenSum) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
let group = ((10 - evenSum) / 2) as usize;
|
||||
let oddWidest = Self::INSIDE_ODD_WIDEST[group];
|
||||
@@ -414,7 +414,7 @@ impl RSS14Reader {
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn parseFoundFinderPattern(
|
||||
@@ -511,12 +511,12 @@ impl RSS14Reader {
|
||||
1 => {
|
||||
if oddParityBad {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
decrementOdd = true;
|
||||
} else {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
decrementEven = true;
|
||||
}
|
||||
@@ -524,12 +524,12 @@ impl RSS14Reader {
|
||||
-1 => {
|
||||
if oddParityBad {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
incrementOdd = true;
|
||||
} else {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
incrementEven = true;
|
||||
}
|
||||
@@ -537,7 +537,7 @@ impl RSS14Reader {
|
||||
0 => {
|
||||
if oddParityBad {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
// Both bad
|
||||
if oddSum < evenSum {
|
||||
@@ -548,15 +548,15 @@ impl RSS14Reader {
|
||||
incrementEven = true;
|
||||
}
|
||||
} else if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
}
|
||||
_ => return Err(Exceptions::NotFoundException(None)),
|
||||
_ => return Err(Exceptions::notFound),
|
||||
}
|
||||
|
||||
if incrementOdd {
|
||||
if decrementOdd {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
|
||||
}
|
||||
@@ -565,7 +565,7 @@ impl RSS14Reader {
|
||||
}
|
||||
if incrementEven {
|
||||
if decrementEven {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
Self::increment(&mut self.evenCounts, &self.evenRoundingErrors);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ impl UPCAReader {
|
||||
|
||||
Ok(upcaRXingResult)
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ impl Writer for UPCAWriter {
|
||||
hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<crate::common::BitMatrix> {
|
||||
if format != &BarcodeFormat::UPC_A {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Can only encode UPC-A, but got {format:?}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
// Transform a UPC-A code into the equivalent EAN-13 code and write it that way
|
||||
self.0.encode_with_hints(
|
||||
|
||||
@@ -49,10 +49,8 @@ impl UPCEANReader for UPCEReader {
|
||||
let mut x = 0;
|
||||
while x < 6 && rowOffset < end {
|
||||
let bestMatch = self.decodeDigit(row, &mut counters, rowOffset, &L_AND_G_PATTERNS)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString
|
||||
.push(char::from_u32('0' as u32 + bestMatch as u32 % 10).ok_or(Exceptions::parse)?);
|
||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||
|
||||
if bestMatch >= 10 {
|
||||
@@ -128,18 +126,15 @@ impl UPCEReader {
|
||||
if lgPatternFound == Self::NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d] {
|
||||
resultString.insert(
|
||||
0,
|
||||
char::from_u32('0' as u32 + numSys as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + d as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32('0' as u32 + numSys as u32).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
resultString
|
||||
.push(char::from_u32('0' as u32 + d as u32).ok_or(Exceptions::parse)?);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,24 +47,24 @@ impl OneDimensionalCodeWriter for UPCEWriter {
|
||||
// No check digit present, calculate it and add it
|
||||
let check = reader.getStandardUPCEANChecksum(
|
||||
&upc_e_reader::convertUPCEtoUPCA(&contents)
|
||||
.ok_or(Exceptions::IllegalArgumentException(None))?,
|
||||
.ok_or(Exceptions::illegalArgument)?,
|
||||
)?;
|
||||
contents.push_str(&check.to_string());
|
||||
}
|
||||
8 => {
|
||||
if !reader.checkStandardUPCEANChecksum(
|
||||
&upc_e_reader::convertUPCEtoUPCA(&contents)
|
||||
.ok_or(Exceptions::IllegalArgumentException(None))?,
|
||||
.ok_or(Exceptions::illegalArgument)?,
|
||||
)? {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
"Contents do not pass checksum".to_owned(),
|
||||
)));
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"Contents do not pass checksum",
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Requested contents should be 7 or 8 digits long, but got {length}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,21 +73,21 @@ impl OneDimensionalCodeWriter for UPCEWriter {
|
||||
let firstDigit = contents
|
||||
.chars()
|
||||
.next()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize; //Character.digit(contents.charAt(0), 10);
|
||||
.ok_or(Exceptions::parse)? as usize; //Character.digit(contents.charAt(0), 10);
|
||||
if firstDigit != 0 && firstDigit != 1 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
"Number system must be 0 or 1".to_owned(),
|
||||
)));
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"Number system must be 0 or 1",
|
||||
));
|
||||
}
|
||||
|
||||
let checkDigit = contents
|
||||
.chars()
|
||||
.nth(7)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize; //Character.digit(contents.charAt(7), 10);
|
||||
.ok_or(Exceptions::parse)? as usize; //Character.digit(contents.charAt(7), 10);
|
||||
let parities = UPCEReader::NUMSYS_AND_CHECK_DIGIT_PATTERNS[firstDigit][checkDigit];
|
||||
let mut result = [false; CODE_WIDTH];
|
||||
|
||||
@@ -99,9 +99,9 @@ impl OneDimensionalCodeWriter for UPCEWriter {
|
||||
let mut digit = contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize; //Character.digit(contents.charAt(i), 10);
|
||||
.ok_or(Exceptions::parse)? as usize; //Character.digit(contents.charAt(i), 10);
|
||||
if (parities >> (6 - i) & 1) == 1 {
|
||||
digit += 10;
|
||||
}
|
||||
|
||||
@@ -87,10 +87,8 @@ impl UPCEANExtension2Support {
|
||||
rowOffset,
|
||||
&upc_ean_reader::L_AND_G_PATTERNS,
|
||||
)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString
|
||||
.push(char::from_u32('0' as u32 + bestMatch as u32 % 10).ok_or(Exceptions::parse)?);
|
||||
|
||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||
|
||||
@@ -106,15 +104,16 @@ impl UPCEANExtension2Support {
|
||||
}
|
||||
|
||||
if resultString.chars().count() != 2 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
if resultString.parse::<u32>().map_err(|e| {
|
||||
Exceptions::ParseException(Some(format!("could not parse {resultString}: {e}")))
|
||||
})? % 4
|
||||
if resultString
|
||||
.parse::<u32>()
|
||||
.map_err(|e| Exceptions::parseWith(format!("could not parse {resultString}: {e}")))?
|
||||
% 4
|
||||
!= checkParity
|
||||
{
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
Ok(rowOffset as u32)
|
||||
|
||||
@@ -86,10 +86,8 @@ impl UPCEANExtension5Support {
|
||||
rowOffset,
|
||||
&upc_ean_reader::L_AND_G_PATTERNS,
|
||||
)?;
|
||||
resultString.push(
|
||||
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
resultString
|
||||
.push(char::from_u32('0' as u32 + bestMatch as u32 % 10).ok_or(Exceptions::parse)?);
|
||||
|
||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||
|
||||
@@ -106,15 +104,14 @@ impl UPCEANExtension5Support {
|
||||
}
|
||||
|
||||
if resultString.chars().count() != 5 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let checkDigit = Self::determineCheckDigit(lgPatternFound)?;
|
||||
if Self::extensionChecksum(resultString)
|
||||
.ok_or(Exceptions::IllegalArgumentException(None))?
|
||||
if Self::extensionChecksum(resultString).ok_or(Exceptions::illegalArgument)?
|
||||
!= checkDigit as u32
|
||||
{
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
Ok(rowOffset as u32)
|
||||
@@ -149,7 +146,7 @@ impl UPCEANExtension5Support {
|
||||
return Ok(d);
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -183,18 +183,18 @@ pub trait UPCEANReader: OneDReader {
|
||||
let end = endRange[1];
|
||||
let quietEnd = end + (end - endRange[0]);
|
||||
if quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)? {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
|
||||
let resultString = result;
|
||||
|
||||
// UPC/EAN should never be less than 8 chars anyway
|
||||
if resultString.chars().count() < 8 {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
|
||||
if !self.checkChecksum(&resultString)? {
|
||||
return Err(Exceptions::ChecksumException(None));
|
||||
return Err(Exceptions::checksum);
|
||||
}
|
||||
|
||||
let left = (startGuardRange[1] + startGuardRange[0]) as f32 / 2.0;
|
||||
@@ -241,7 +241,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
}
|
||||
}
|
||||
if !valid {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFound);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
let char_in_question = s
|
||||
.chars()
|
||||
.nth(length - 1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBounds)?;
|
||||
let check = char_in_question.is_ascii_digit();
|
||||
|
||||
let check_against = &s[..length - 1]; //s.subSequence(0, length - 1);
|
||||
@@ -300,9 +300,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
|
||||
Ok(calculated_checksum
|
||||
== if check {
|
||||
char_in_question
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))?
|
||||
char_in_question.to_digit(10).ok_or(Exceptions::parse)?
|
||||
} else {
|
||||
u32::MAX
|
||||
})
|
||||
@@ -314,13 +312,13 @@ pub trait UPCEANReader: OneDReader {
|
||||
let mut i = length as isize - 1;
|
||||
while i >= 0 {
|
||||
// for (int i = length - 1; i >= 0; i -= 2) {
|
||||
let digit =
|
||||
(s.chars()
|
||||
.nth(i as usize)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as i32)
|
||||
- ('0' as i32);
|
||||
let digit = (s
|
||||
.chars()
|
||||
.nth(i as usize)
|
||||
.ok_or(Exceptions::indexOutOfBounds)? as i32)
|
||||
- ('0' as i32);
|
||||
if !(0..=9).contains(&digit) {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
sum += digit;
|
||||
|
||||
@@ -330,13 +328,13 @@ pub trait UPCEANReader: OneDReader {
|
||||
let mut i = length as isize - 2;
|
||||
while i >= 0 {
|
||||
// for (int i = length - 2; i >= 0; i -= 2) {
|
||||
let digit =
|
||||
(s.chars()
|
||||
.nth(i as usize)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as i32)
|
||||
- ('0' as i32);
|
||||
let digit = (s
|
||||
.chars()
|
||||
.nth(i as usize)
|
||||
.ok_or(Exceptions::indexOutOfBounds)? as i32)
|
||||
- ('0' as i32);
|
||||
if !(0..=9).contains(&digit) {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
sum += digit;
|
||||
|
||||
@@ -423,7 +421,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,7 +458,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
if bestMatch >= 0 {
|
||||
Ok(bestMatch as usize)
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user