mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
Merge branch 'main' into pr/point_refactor
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
Reference in New Issue
Block a user