fix potential unwrap on none

This commit is contained in:
Henry Schimke
2023-01-06 10:56:00 -06:00
parent 7996f42c64
commit 6d41475786
5 changed files with 24 additions and 19 deletions

View File

@@ -78,13 +78,13 @@ impl StringUtils {
.unwrap()
.name()
{
"SJIS"
"SJIS"
} else if c.name() == encoding::all::UTF_8.name() {
"UTF8"
"UTF8"
} else if c.name() == encoding::all::ISO_8859_1.name() {
"ISO8859_1"
}else {
c.name()
"ISO8859_1"
} else {
c.name()
}
}

View File

@@ -46,7 +46,7 @@ impl EANManufacturerOrgSupport {
// let prefix = Integer.parseInt(productCode.substring(0, 3));
let max = self.ranges.len();
for (i, range) in self.ranges.iter().enumerate().take(max) {
// for i in 0..max {
// for i in 0..max {
// for (int i = 0; i < max; i++) {
// let range = self.ranges.get(i).expect("must have index i or fail");
let start = range[0];
@@ -58,8 +58,7 @@ impl EANManufacturerOrgSupport {
return Some(
self.countryIdentifiers
.get(i)
.expect("must have index i or fail")
// .clone(),
.expect("must have index i or fail"), // .clone(),
);
}
}

View File

@@ -98,10 +98,10 @@ pub trait OneDReader: Reader {
if attempt == 1 {
// trying again?
row.to_mut().reverse(); // reverse the row and continue
// This means we will only ever draw result points *once* in the life of this method
// since we want to avoid drawing the wrong points after flipping the row, and,
// don't want to clutter with noise from every single row scan -- just the scans
// that start on the center line.
// This means we will only ever draw result points *once* in the life of this method
// since we want to avoid drawing the wrong points after flipping the row, and,
// don't want to clutter with noise from every single row scan -- just the scans
// that start on the center line.
if hints.contains_key(&DecodeHintType::NEED_RESULT_POINT_CALLBACK) {
// let newHints = HashMap::new();
// newHints.putAll(hints);

View File

@@ -19,8 +19,8 @@ use std::collections::HashMap;
use crate::{
common::BitArray,
oned::{one_d_reader, OneDReader},
BarcodeFormat, DecodeHintType, DecodingHintDictionary, Exceptions, RXingResult,
RXingResultMetadataType, RXingResultMetadataValue, Reader, DecodeHintValue, RXingResultPoint,
BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions,
RXingResult, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader,
};
use super::{
@@ -263,14 +263,16 @@ impl RSS14Reader {
let startEnd = self.findFinderPattern(row, right)?;
let pattern = self.parseFoundFinderPattern(row, rowNumber, right, &startEnd)?;
if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK) {
if let Some(DecodeHintValue::NeedResultPointCallback(cb)) =
hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK)
{
let startEnd = pattern.getStartEnd();
let mut center :f32 = (startEnd[0] + startEnd[1] - 1) as f32 / 2.0;
let mut center: f32 = (startEnd[0] + startEnd[1] - 1) as f32 / 2.0;
if right {
// row is actually reversed
center = row.getSize() as f32 - 1.0 - center;
// row is actually reversed
center = row.getSize() as f32 - 1.0 - center;
}
cb( &RXingResultPoint::new(center, rowNumber as f32));
cb(&RXingResultPoint::new(center, rowNumber as f32));
}
let outside = self.decodeDataCharacter(row, &pattern, true)?;

View File

@@ -309,6 +309,10 @@ fn getBarcodeMetadata<T: DetectionRXingResultRowIndicatorColumn>(
// return leftBarcodeMetadata;
// }
if leftBarcodeMetadata.is_none() {
return None;
}
if leftBarcodeMetadata.as_ref().unwrap().getColumnCount()
!= rightBarcodeMetadata.as_ref().unwrap().getColumnCount()
&& leftBarcodeMetadata