mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
Implement clippy suggestions
This commit is contained in:
@@ -47,18 +47,16 @@ pub trait AbstractRSSReaderTrait: OneDReader {
|
||||
// }
|
||||
|
||||
fn parseFinderValue(counters: &[u32], finderPatterns: &[[u32; 4]]) -> Result<u32, Exceptions> {
|
||||
for value in 0..finderPatterns.len() {
|
||||
for (value, pattern) in finderPatterns.iter().enumerate() {
|
||||
// for value in 0..finderPatterns.len() {
|
||||
// for (int value = 0; value < finderPatterns.length; value++) {
|
||||
if one_d_reader::patternMatchVariance(
|
||||
counters,
|
||||
&finderPatterns[value],
|
||||
Self::MAX_INDIVIDUAL_VARIANCE,
|
||||
) < Self::MAX_AVG_VARIANCE
|
||||
if one_d_reader::patternMatchVariance(counters, pattern, Self::MAX_INDIVIDUAL_VARIANCE)
|
||||
< Self::MAX_AVG_VARIANCE
|
||||
{
|
||||
return Ok(value as u32);
|
||||
}
|
||||
}
|
||||
Err(Exceptions::NotFoundException("".to_owned()))
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,10 +72,10 @@ pub trait AbstractRSSReaderTrait: OneDReader {
|
||||
fn increment(array: &mut [u32], errors: &[f32]) {
|
||||
let mut index = 0;
|
||||
let mut biggestError = errors[0];
|
||||
for i in 1..array.len() {
|
||||
for (i, error) in errors.iter().enumerate().take(array.len()).skip(1) {
|
||||
// for (int i = 1; i < array.length; i++) {
|
||||
if errors[i] > biggestError {
|
||||
biggestError = errors[i];
|
||||
if *error > biggestError {
|
||||
biggestError = *error;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
@@ -87,10 +85,11 @@ pub trait AbstractRSSReaderTrait: OneDReader {
|
||||
fn decrement(array: &mut [u32], errors: &[f32]) {
|
||||
let mut index = 0;
|
||||
let mut biggestError = errors[0];
|
||||
for i in 1..array.len() {
|
||||
for (i, error) in errors.iter().enumerate().take(array.len()).skip(1) {
|
||||
// for i in 1..array.len() {
|
||||
// for (int i = 1; i < array.length; i++) {
|
||||
if errors[i] < biggestError {
|
||||
biggestError = errors[i];
|
||||
if *error < biggestError {
|
||||
biggestError = *error;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
@@ -116,6 +115,6 @@ pub trait AbstractRSSReaderTrait: OneDReader {
|
||||
}
|
||||
return maxCounter < 10 * minCounter;
|
||||
}
|
||||
return false;
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ pub fn buildBitArrayFromString(data: &str) -> Result<BitArray, Exceptions> {
|
||||
if i % 9 == 0 {
|
||||
// spaces
|
||||
if dotsAndXs.chars().nth(i).unwrap() != ' ' {
|
||||
return Err(Exceptions::IllegalStateException(
|
||||
return Err(Exceptions::IllegalStateException(Some(
|
||||
"space expected".to_owned(),
|
||||
));
|
||||
)));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ use super::ExpandedPair;
|
||||
|
||||
pub fn buildBitArray(pairs: &Vec<ExpandedPair>) -> BitArray {
|
||||
let mut charNumber = (pairs.len() * 2) - 1;
|
||||
if pairs.get(pairs.len() - 1).unwrap().getRightChar().is_none() {
|
||||
if pairs.last().unwrap().getRightChar().is_none() {
|
||||
charNumber -= 1;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ pub fn buildBitArray(pairs: &Vec<ExpandedPair>) -> BitArray {
|
||||
}
|
||||
}
|
||||
}
|
||||
return binary;
|
||||
binary
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,9 +118,8 @@ mod BitArrayBuilderTest {
|
||||
|
||||
fn buildBitArray(pairValues: &Vec<Vec<u32>>) -> BitArray {
|
||||
let mut pairs = Vec::new(); //new ArrayList<>();
|
||||
for i in 0..pairValues.len() {
|
||||
for (i, pair) in pairValues.iter().enumerate() {
|
||||
// for (int i = 0; i < pairValues.length; ++i) {
|
||||
let pair = &pairValues[i];
|
||||
|
||||
let leftChar = if i == 0 {
|
||||
None
|
||||
|
||||
@@ -149,8 +149,8 @@ pub fn createDecoder<'a>(
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Err(Exceptions::IllegalStateException(format!(
|
||||
Err(Exceptions::IllegalStateException(Some(format!(
|
||||
"unknown decoder: {}",
|
||||
information
|
||||
)))
|
||||
))))
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ impl AI01decoder for AI01392xDecoder<'_> {}
|
||||
impl AbstractExpandedDecoder for AI01392xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
||||
return Err(crate::Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
@@ -58,7 +58,7 @@ impl AbstractExpandedDecoder for AI01392xDecoder<'_> {
|
||||
Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::LAST_DIGIT_SIZE,
|
||||
"",
|
||||
)?;
|
||||
buf.push_str(&decodedInformation.getNewString());
|
||||
buf.push_str(decodedInformation.getNewString());
|
||||
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ impl AI01decoder for AI01393xDecoder<'_> {}
|
||||
impl AbstractExpandedDecoder for AI01393xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
||||
return Err(crate::Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
@@ -74,7 +74,7 @@ impl AbstractExpandedDecoder for AI01393xDecoder<'_> {
|
||||
+ Self::FIRST_THREE_DIGITS_SIZE,
|
||||
"",
|
||||
)?;
|
||||
buf.push_str(&generalInformation.getNewString());
|
||||
buf.push_str(generalInformation.getNewString());
|
||||
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
@@ -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("".to_owned()));
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
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("".to_owned()));
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
@@ -33,7 +33,7 @@ use super::{AI01decoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
pub struct AI01AndOtherAIs<'a>(&'a BitArray, GeneralAppIdDecoder<'a>);
|
||||
impl<'a> AI01decoder for AI01AndOtherAIs<'_> {}
|
||||
impl AI01decoder for AI01AndOtherAIs<'_> {}
|
||||
impl AbstractExpandedDecoder for AI01AndOtherAIs<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
let mut buff = String::new(); //new StringBuilder();
|
||||
|
||||
@@ -34,6 +34,13 @@ pub struct BlockParsedRXingResult {
|
||||
decodedInformation: Option<DecodedInformation>,
|
||||
finished: bool,
|
||||
}
|
||||
|
||||
impl Default for BlockParsedRXingResult {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockParsedRXingResult {
|
||||
pub fn new() -> Self {
|
||||
Self::with_information(None, false)
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
*/
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum State {
|
||||
NUMERIC,
|
||||
ALPHA,
|
||||
ISO_IEC_646,
|
||||
Numeric,
|
||||
Alpha,
|
||||
IsoIec646,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ impl CurrentParsingState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
position: 0,
|
||||
encoding: State::NUMERIC,
|
||||
encoding: State::Numeric,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,26 +59,32 @@ impl CurrentParsingState {
|
||||
}
|
||||
|
||||
pub fn isAlpha(&self) -> bool {
|
||||
self.encoding == State::ALPHA
|
||||
self.encoding == State::Alpha
|
||||
}
|
||||
|
||||
pub fn isNumeric(&self) -> bool {
|
||||
self.encoding == State::NUMERIC
|
||||
self.encoding == State::Numeric
|
||||
}
|
||||
|
||||
pub fn isIsoIec646(&self) -> bool {
|
||||
self.encoding == State::ISO_IEC_646
|
||||
self.encoding == State::IsoIec646
|
||||
}
|
||||
|
||||
pub fn setNumeric(&mut self) {
|
||||
self.encoding = State::NUMERIC;
|
||||
self.encoding = State::Numeric;
|
||||
}
|
||||
|
||||
pub fn setAlpha(&mut self) {
|
||||
self.encoding = State::ALPHA;
|
||||
self.encoding = State::Alpha;
|
||||
}
|
||||
|
||||
pub fn setIsoIec646(&mut self) {
|
||||
self.encoding = State::ISO_IEC_646;
|
||||
self.encoding = State::IsoIec646;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CurrentParsingState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +51,7 @@ impl DecodedNumeric {
|
||||
if
|
||||
/*firstDigit < 0 ||*/
|
||||
firstDigit > 10 || /*secondDigit < 0 ||*/ secondDigit > 10 {
|
||||
return Err(Exceptions::FormatException(
|
||||
".getFormatInstance();".to_owned(),
|
||||
));
|
||||
return Err(Exceptions::FormatException(None));
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -149,7 +149,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
||||
// Processing 2-digit AIs
|
||||
|
||||
if rawInformation.chars().count() < 2 {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let lookup: String = rawInformation.chars().take(2).collect();
|
||||
@@ -162,7 +162,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
||||
}
|
||||
|
||||
if rawInformation.chars().count() < 3 {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let firstThreeDigits: String = rawInformation.chars().take(3).collect(); //rawInformation.substring(0, 3);
|
||||
@@ -175,7 +175,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
||||
}
|
||||
|
||||
if rawInformation.chars().count() < 4 {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let threeDigitPlusDigitDataLength = THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.get(&firstThreeDigits);
|
||||
@@ -195,7 +195,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
||||
return processFixedAI(4, ffdl.length, rawInformation);
|
||||
}
|
||||
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
|
||||
fn processFixedAI(
|
||||
@@ -204,13 +204,13 @@ fn processFixedAI(
|
||||
rawInformation: &str,
|
||||
) -> Result<String, Exceptions> {
|
||||
if rawInformation.chars().count() < aiSize {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let ai: String = rawInformation.chars().take(aiSize).collect();
|
||||
|
||||
if rawInformation.chars().count() < aiSize + fieldSize {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let field: String = rawInformation
|
||||
@@ -234,16 +234,12 @@ fn processVariableAI(
|
||||
variableFieldSize: usize,
|
||||
rawInformation: &str,
|
||||
) -> Result<String, Exceptions> {
|
||||
let ai: String = rawInformation.chars().take(aiSize as usize).collect(); //rawInformation.substring(0, aiSize);
|
||||
let ai: String = rawInformation.chars().take(aiSize).collect(); //rawInformation.substring(0, aiSize);
|
||||
let maxSize = rawInformation
|
||||
.chars()
|
||||
.count()
|
||||
.min(aiSize + variableFieldSize);
|
||||
let field: String = rawInformation
|
||||
.chars()
|
||||
.skip(aiSize as usize)
|
||||
.take(maxSize)
|
||||
.collect(); // (aiSize, maxSize);
|
||||
let field: String = rawInformation.chars().skip(aiSize).take(maxSize).collect(); // (aiSize, maxSize);
|
||||
let remaining: String = rawInformation.chars().skip(maxSize).collect();
|
||||
let result = format!("({}){}", ai, field); //'(' + ai + ')' + field;
|
||||
let parsedAI = parseFieldsInGeneralPurpose(&remaining)?;
|
||||
@@ -287,7 +283,7 @@ impl DataLength {
|
||||
mod FieldParserTest {
|
||||
|
||||
fn checkFields(expected: &str) {
|
||||
let field = expected.replace("(", "").replace(")", "");
|
||||
let field = expected.replace(['(', ')'], "");
|
||||
let actual = super::parseFieldsInGeneralPurpose(&field).expect("parse");
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
}
|
||||
|
||||
pub fn extractNumericValueFromBitArray(&self, pos: usize, bits: u32) -> u32 {
|
||||
Self::extractNumericValueFromBitArrayWithInformation(&self.information, pos, bits)
|
||||
Self::extractNumericValueFromBitArrayWithInformation(self.information, pos, bits)
|
||||
}
|
||||
|
||||
pub fn extractNumericValueFromBitArrayWithInformation(
|
||||
@@ -192,7 +192,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
break;
|
||||
}
|
||||
|
||||
if !(!isFinished) {
|
||||
if isFinished {
|
||||
break;
|
||||
}
|
||||
} //while (!isFinished);
|
||||
@@ -200,7 +200,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
if result.getDecodedInformation().is_some() {
|
||||
Ok(result.getDecodedInformation().as_ref().unwrap().clone())
|
||||
} else {
|
||||
Err(Exceptions::NotFoundException("".to_owned()))
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
}
|
||||
|
||||
let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5);
|
||||
if fiveBitValue >= 5 && fiveBitValue < 16 {
|
||||
if (5..16).contains(&fiveBitValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
}
|
||||
|
||||
let sevenBitValue = self.extractNumericValueFromBitArray(pos, 7);
|
||||
if sevenBitValue >= 64 && sevenBitValue < 116 {
|
||||
if (64..116).contains(&sevenBitValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
|
||||
let eightBitValue = self.extractNumericValueFromBitArray(pos, 8);
|
||||
|
||||
eightBitValue >= 232 && eightBitValue < 253
|
||||
(232..253).contains(&eightBitValue)
|
||||
}
|
||||
|
||||
fn decodeIsoIec646(&self, pos: usize) -> Result<DecodedChar, Exceptions> {
|
||||
@@ -343,7 +343,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
return Ok(DecodedChar::new(pos + 5, DecodedChar::FNC1));
|
||||
}
|
||||
|
||||
if fiveBitValue >= 5 && fiveBitValue < 15 {
|
||||
if (5..15).contains(&fiveBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 5,
|
||||
char::from_u32('0' as u32 + fiveBitValue - 5).unwrap(),
|
||||
@@ -352,14 +352,14 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
|
||||
let sevenBitValue = self.extractNumericValueFromBitArray(pos, 7);
|
||||
|
||||
if sevenBitValue >= 64 && sevenBitValue < 90 {
|
||||
if (64..90).contains(&sevenBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 7,
|
||||
char::from_u32(sevenBitValue + 1).unwrap(),
|
||||
));
|
||||
}
|
||||
|
||||
if sevenBitValue >= 90 && sevenBitValue < 116 {
|
||||
if (90..116).contains(&sevenBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 7,
|
||||
char::from_u32(sevenBitValue + 7).unwrap(),
|
||||
@@ -389,7 +389,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
250 => '?',
|
||||
251 => '_',
|
||||
252 => ' ',
|
||||
_ => return Err(Exceptions::FormatException("".to_owned())),
|
||||
_ => return Err(Exceptions::FormatException(None)),
|
||||
};
|
||||
|
||||
Ok(DecodedChar::new(pos + 8, c))
|
||||
@@ -402,7 +402,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
|
||||
// We now check if it's a valid 5-bit value (0..9 and FNC1)
|
||||
let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5);
|
||||
if fiveBitValue >= 5 && fiveBitValue < 16 {
|
||||
if (5..16).contains(&fiveBitValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -412,7 +412,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
|
||||
let sixBitValue = self.extractNumericValueFromBitArray(pos, 6);
|
||||
|
||||
sixBitValue >= 16 && sixBitValue < 63 // 63 not included
|
||||
(16..63).contains(&sixBitValue) // 63 not included
|
||||
}
|
||||
|
||||
fn decodeAlphanumeric(&self, pos: usize) -> Result<DecodedChar, Exceptions> {
|
||||
@@ -421,7 +421,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
return Ok(DecodedChar::new(pos + 5, DecodedChar::FNC1));
|
||||
}
|
||||
|
||||
if fiveBitValue >= 5 && fiveBitValue < 15 {
|
||||
if (5..15).contains(&fiveBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 5,
|
||||
char::from_u32('0' as u32 + fiveBitValue - 5).unwrap(),
|
||||
@@ -430,7 +430,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
|
||||
let sixBitValue = self.extractNumericValueFromBitArray(pos, 6);
|
||||
|
||||
if sixBitValue >= 32 && sixBitValue < 58 {
|
||||
if (32..58).contains(&sixBitValue) {
|
||||
return Ok(DecodedChar::new(
|
||||
pos + 6,
|
||||
char::from_u32(sixBitValue + 33).unwrap(),
|
||||
@@ -444,10 +444,10 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
61 => '.',
|
||||
62 => '/',
|
||||
_ => {
|
||||
return Err(Exceptions::IllegalStateException(format!(
|
||||
return Err(Exceptions::IllegalStateException(Some(format!(
|
||||
"Decoding invalid alphanumeric value: {}",
|
||||
sixBitValue
|
||||
)))
|
||||
))))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use std::fmt::Display;
|
||||
use std::{fmt::Display, hash::Hash};
|
||||
|
||||
use super::ExpandedPair;
|
||||
|
||||
/**
|
||||
* One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
|
||||
*/
|
||||
#[derive(Hash, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct ExpandedRow {
|
||||
pairs: Vec<ExpandedPair>,
|
||||
rowNumber: u32,
|
||||
@@ -58,6 +58,12 @@ impl PartialEq for ExpandedRow {
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for ExpandedRow {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.pairs.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ExpandedRow {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{{ ")?;
|
||||
|
||||
@@ -74,7 +74,7 @@ fn assertCorrectImage2result(fileName: &str, expected: ExpandedProductParsedRXin
|
||||
let mut binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(image)),
|
||||
))));
|
||||
let rowNumber = binaryMap.getHeight() as usize / 2;
|
||||
let rowNumber = binaryMap.getHeight() / 2;
|
||||
let row = binaryMap.getBlackRow(rowNumber).expect("get row");
|
||||
|
||||
let mut rssExpandedReader = RSSExpandedReader::new();
|
||||
|
||||
@@ -37,7 +37,7 @@ use crate::{
|
||||
OneDReader,
|
||||
},
|
||||
BarcodeFormat, DecodeHintType, DecodingHintDictionary, Exceptions, RXingResult,
|
||||
RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, ResultPoint,
|
||||
RXingResultMetadataType, RXingResultMetadataValue, Reader,
|
||||
};
|
||||
|
||||
use super::{bit_array_builder, decoders::abstract_expanded_decoder, ExpandedPair, ExpandedRow};
|
||||
@@ -132,6 +132,7 @@ lazy_static! {
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
*/
|
||||
#[derive(Default)]
|
||||
pub struct RSSExpandedReader {
|
||||
_possibleLeftPairs: Vec<Pair>,
|
||||
_possibleRightPairs: Vec<Pair>,
|
||||
@@ -225,18 +226,21 @@ impl Reader for RSSExpandedReader {
|
||||
// for point in result.getRXingResultPointsMut().iter_mut() {
|
||||
let total_points = result.getRXingResultPoints().len();
|
||||
let points = result.getRXingResultPointsMut();
|
||||
for i in 0..total_points {
|
||||
for point in points.iter_mut().take(total_points) {
|
||||
// for i in 0..total_points {
|
||||
// for (int i = 0; i < points.length; i++) {
|
||||
points[i] = RXingResultPoint::new(
|
||||
height as f32 - points[i].getY() - 1.0,
|
||||
points[i].getX(),
|
||||
);
|
||||
std::mem::swap(&mut point.x, &mut point.y);
|
||||
point.x = height as f32 - point.x - 1.0;
|
||||
// points[i] = RXingResultPoint::new(
|
||||
// height as f32 - points[i].getY() - 1.0,
|
||||
// points[i].getX(),
|
||||
// );
|
||||
}
|
||||
// }
|
||||
|
||||
Ok(result)
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,16 +339,16 @@ impl RSSExpandedReader {
|
||||
// When the image is 180-rotated, then rows are sorted in wrong direction.
|
||||
// Try twice with both the directions.
|
||||
let ps = self.checkRows(false);
|
||||
if ps.is_some() {
|
||||
return Ok(ps.unwrap());
|
||||
if let Some(ps) = ps {
|
||||
return Ok(ps);
|
||||
}
|
||||
let ps = self.checkRows(true);
|
||||
if ps.is_some() {
|
||||
return Ok(ps.unwrap());
|
||||
if let Some(ps) = ps {
|
||||
return Ok(ps);
|
||||
}
|
||||
}
|
||||
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
|
||||
fn checkRows(&mut self, reverse: bool) -> Option<Vec<ExpandedPair>> {
|
||||
@@ -415,7 +419,7 @@ impl RSSExpandedReader {
|
||||
}
|
||||
}
|
||||
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
|
||||
// Whether the pairs form a valid find pattern sequence,
|
||||
@@ -427,7 +431,7 @@ impl RSSExpandedReader {
|
||||
// for (int[] sequence : FINDER_PATTERN_SEQUENCES) {
|
||||
if pairs.len() <= sequence.len() {
|
||||
let mut stop = true;
|
||||
for j in 0..pairs.len() {
|
||||
for (j, seq) in sequence.iter().enumerate().take(pairs.len()) {
|
||||
// for (int j = 0; j < pairs.size(); j++) {
|
||||
if pairs
|
||||
.get(j)
|
||||
@@ -436,7 +440,7 @@ impl RSSExpandedReader {
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.getValue()
|
||||
!= sequence[j]
|
||||
!= *seq
|
||||
{
|
||||
stop = false;
|
||||
break;
|
||||
@@ -448,7 +452,7 @@ impl RSSExpandedReader {
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
fn storeRow(&mut self, rowNumber: u32) {
|
||||
@@ -535,7 +539,7 @@ impl RSSExpandedReader {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
// Only used for unit testing
|
||||
@@ -564,7 +568,7 @@ impl RSSExpandedReader {
|
||||
.unwrap()
|
||||
.getRXingResultPoints();
|
||||
let lastPoints = pairs
|
||||
.get(pairs.len() - 1)
|
||||
.last()
|
||||
.unwrap()
|
||||
.getFinderPattern()
|
||||
.as_ref()
|
||||
@@ -663,13 +667,8 @@ impl RSSExpandedReader {
|
||||
let leftChar =
|
||||
self.decodeDataCharacter(row, pattern.as_ref().unwrap(), isOddPattern, true)?;
|
||||
|
||||
if !previousPairs.is_empty()
|
||||
&& previousPairs
|
||||
.get(previousPairs.len() - 1)
|
||||
.unwrap()
|
||||
.mustBeLast()
|
||||
{
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
if !previousPairs.is_empty() && previousPairs.last().unwrap().mustBeLast() {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let rightChar = if let Ok(ch) =
|
||||
@@ -708,7 +707,7 @@ impl RSSExpandedReader {
|
||||
} else if previousPairs.is_empty() {
|
||||
rowOffset = 0;
|
||||
} else {
|
||||
let lastPair = previousPairs.get(previousPairs.len() - 1).unwrap();
|
||||
let lastPair = previousPairs.last().unwrap();
|
||||
rowOffset = lastPair.getFinderPattern().as_ref().unwrap().getStartEnd()[1] as i32;
|
||||
}
|
||||
let mut searchingEvenPair = previousPairs.len() % 2 != 0;
|
||||
@@ -760,16 +759,14 @@ impl RSSExpandedReader {
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
|
||||
fn reverseCounters(counters: &mut [u32]) {
|
||||
let length = counters.len();
|
||||
for i in 0..length / 2 {
|
||||
// for (int i = 0; i < length / 2; ++i) {
|
||||
let tmp = counters[i];
|
||||
counters[i] = counters[length - i - 1];
|
||||
counters[length - i - 1] = tmp;
|
||||
counters.swap(i, length - i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -861,7 +858,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("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
// let oddCounts = &mut self.oddCounts;
|
||||
@@ -869,18 +866,18 @@ impl RSSExpandedReader {
|
||||
// let oddRoundingErrors = &mut self.oddRoundingErrors;
|
||||
// let evenRoundingErrors = &mut self.evenRoundingErrors;
|
||||
|
||||
for i in 0..counters.len() {
|
||||
for (i, counter) in counters.iter().enumerate() {
|
||||
// for (int i = 0; i < counters.length; i++) {
|
||||
let value: f32 = 1.0 * counters[i] as f32 / elementWidth;
|
||||
let value: f32 = 1.0 * (*counter as f32) / elementWidth;
|
||||
let mut count = (value + 0.5) as i32; // Round
|
||||
if count < 1 {
|
||||
if value < 0.3 {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
count = 1;
|
||||
} else if count > 8 {
|
||||
if value > 8.7 {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
count = 8;
|
||||
}
|
||||
@@ -898,7 +895,7 @@ impl RSSExpandedReader {
|
||||
|
||||
let weightRowNumber = (4 * pattern.getValue() as isize
|
||||
+ (if isOddPattern { 0 } else { 2 })
|
||||
+ (if leftChar { 0 } else { 1 })
|
||||
+ isize::from(!leftChar)//(if leftChar { 0 } else { 1 })
|
||||
- 1) as usize;
|
||||
|
||||
let mut oddSum = 0;
|
||||
@@ -921,8 +918,8 @@ impl RSSExpandedReader {
|
||||
}
|
||||
let checksumPortion = oddChecksumPortion + evenChecksumPortion;
|
||||
|
||||
if (oddSum & 0x01) != 0 || oddSum > 13 || oddSum < 4 {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
if (oddSum & 0x01) != 0 || !(4..=13).contains(&oddSum) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
let group = ((13 - oddSum) / 2) as usize;
|
||||
@@ -971,12 +968,12 @@ impl RSSExpandedReader {
|
||||
1 => {
|
||||
if oddParityBad {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
decrementOdd = true;
|
||||
} else {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
decrementEven = true;
|
||||
}
|
||||
@@ -984,12 +981,12 @@ impl RSSExpandedReader {
|
||||
-1 => {
|
||||
if oddParityBad {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
incrementOdd = true;
|
||||
} else {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
incrementEven = true;
|
||||
}
|
||||
@@ -997,7 +994,7 @@ impl RSSExpandedReader {
|
||||
0 => {
|
||||
if oddParityBad {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
// Both bad
|
||||
if oddSum < evenSum {
|
||||
@@ -1007,20 +1004,17 @@ impl RSSExpandedReader {
|
||||
decrementOdd = true;
|
||||
incrementEven = true;
|
||||
}
|
||||
} else {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
}
|
||||
// Nothing to do!
|
||||
} else if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::NotFoundException("".to_owned())),
|
||||
_ => return Err(Exceptions::NotFoundException(None)),
|
||||
}
|
||||
|
||||
if incrementOdd {
|
||||
if decrementOdd {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
|
||||
}
|
||||
@@ -1029,7 +1023,7 @@ impl RSSExpandedReader {
|
||||
}
|
||||
if incrementEven {
|
||||
if decrementEven {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
Self::increment(&mut self.evenCounts, &self.oddRoundingErrors);
|
||||
}
|
||||
@@ -1040,22 +1034,3 @@ impl RSSExpandedReader {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RSSExpandedReader {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
_possibleLeftPairs: Default::default(),
|
||||
_possibleRightPairs: Default::default(),
|
||||
decodeFinderCounters: Default::default(),
|
||||
dataCharacterCounters: Default::default(),
|
||||
oddRoundingErrors: Default::default(),
|
||||
evenRoundingErrors: Default::default(),
|
||||
oddCounts: Default::default(),
|
||||
evenCounts: Default::default(),
|
||||
pairs: Default::default(),
|
||||
rows: Default::default(),
|
||||
startEnd: Default::default(),
|
||||
startFromEven: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,16 +33,13 @@ use crate::{common::GlobalHistogramBinarizer, BinaryBitmap, BufferedImageLuminan
|
||||
fn getBufferedImage(fileName: &str) -> DynamicImage {
|
||||
let path = format!("test_resources/blackbox/rssexpandedstacked-2/{}", fileName);
|
||||
|
||||
let image = image::open(path).expect("load image");
|
||||
|
||||
image
|
||||
image::open(path).expect("load image")
|
||||
}
|
||||
|
||||
pub(crate) fn getBinaryBitmap(fileName: &str) -> BinaryBitmap {
|
||||
let bufferedImage = getBufferedImage(fileName);
|
||||
let binaryMap = BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(bufferedImage)),
|
||||
))));
|
||||
|
||||
binaryMap
|
||||
BinaryBitmap::new(Rc::new(RefCell::new(GlobalHistogramBinarizer::new(
|
||||
Box::new(BufferedImageLuminanceSource::new(bufferedImage)),
|
||||
))))
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::{
|
||||
common::BitArray,
|
||||
oned::{one_d_reader, OneDReader},
|
||||
BarcodeFormat, DecodeHintType, DecodingHintDictionary, Exceptions, RXingResult,
|
||||
RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, ResultPoint,
|
||||
RXingResultMetadataType, RXingResultMetadataValue, Reader,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -63,13 +63,13 @@ impl OneDReader for RSS14Reader {
|
||||
if left.getCount() > 1 {
|
||||
for right in &self.possibleRightPairs {
|
||||
// for (Pair right : possibleRightPairs) {
|
||||
if right.getCount() > 1 && self.checkChecksum(&left, &right) {
|
||||
return Ok(self.constructRXingResult(&left, &right));
|
||||
if right.getCount() > 1 && self.checkChecksum(left, right) {
|
||||
return Ok(self.constructRXingResult(left, right));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
}
|
||||
impl Reader for RSS14Reader {
|
||||
@@ -119,18 +119,21 @@ impl Reader for RSS14Reader {
|
||||
// for point in result.getRXingResultPointsMut().iter_mut() {
|
||||
let total_points = result.getRXingResultPoints().len();
|
||||
let points = result.getRXingResultPointsMut();
|
||||
for i in 0..total_points {
|
||||
// for i in 0..total_points {
|
||||
for point in points.iter_mut().take(total_points) {
|
||||
// for (int i = 0; i < points.length; i++) {
|
||||
points[i] = RXingResultPoint::new(
|
||||
height as f32 - points[i].getY() - 1.0,
|
||||
points[i].getX(),
|
||||
);
|
||||
std::mem::swap(&mut point.x, &mut point.y);
|
||||
point.x = height as f32 - point.x - 1.0
|
||||
// points[i] = RXingResultPoint::new(
|
||||
// height as f32 - points[i].getY() - 1.0,
|
||||
// points[i].getX(),
|
||||
// );
|
||||
}
|
||||
// }
|
||||
|
||||
Ok(result)
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,10 +287,10 @@ impl RSS14Reader {
|
||||
pattern,
|
||||
))
|
||||
}();
|
||||
if pos_pair.is_err() {
|
||||
None
|
||||
if let Ok(ppair) = pos_pair {
|
||||
Some(ppair)
|
||||
} else {
|
||||
Some(pos_pair.unwrap())
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,15 +331,16 @@ impl RSS14Reader {
|
||||
// let oddRoundingErrors = //&mut self.oddRoundingErrors;//[0f32; 4]; // self.getOddRoundingErrors();
|
||||
// let evenRoundingErrors = &mut self.evenRoundingErrors;//[0f32; 4]; // self.getEvenRoundingErrors();
|
||||
|
||||
for i in 0..counters.len() {
|
||||
for (i, counter) in counters.iter().enumerate() {
|
||||
// for (int i = 0; i < counters.length; i++) {
|
||||
let value: f32 = counters[i] as f32 / elementWidth;
|
||||
let mut count = (value + 0.5) as u32; // Round
|
||||
if count < 1 {
|
||||
count = 1;
|
||||
} else if count > 8 {
|
||||
count = 8;
|
||||
}
|
||||
let value: f32 = *counter as f32 / elementWidth;
|
||||
// let mut count = (value + 0.5) as u32; // Round
|
||||
let count = ((value + 0.5) as u32).clamp(1, 8);
|
||||
// if count < 1 {
|
||||
// count = 1;
|
||||
// } else if count > 8 {
|
||||
// count = 8;
|
||||
// }
|
||||
let offset = i / 2;
|
||||
if (i & 0x01) == 0 {
|
||||
self.oddCounts[offset] = count;
|
||||
@@ -368,8 +372,8 @@ impl RSS14Reader {
|
||||
let checksumPortion = oddChecksumPortion + 3 * evenChecksumPortion;
|
||||
|
||||
if outsideChar {
|
||||
if (oddSum & 0x01) != 0 || oddSum > 12 || oddSum < 4 {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
if (oddSum & 0x01) != 0 || !(4..=12).contains(&oddSum) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
let group = ((12 - oddSum) / 2) as usize;
|
||||
let oddWidest = Self::OUTSIDE_ODD_WIDEST[group];
|
||||
@@ -378,13 +382,13 @@ impl RSS14Reader {
|
||||
let vEven = rss_utils::getRSSvalue(&self.evenCounts, evenWidest, true);
|
||||
let tEven = Self::OUTSIDE_EVEN_TOTAL_SUBSET[group];
|
||||
let gSum = Self::OUTSIDE_GSUM[group];
|
||||
return Ok(DataCharacter::new(
|
||||
Ok(DataCharacter::new(
|
||||
vOdd * tEven + vEven + gSum,
|
||||
checksumPortion,
|
||||
));
|
||||
))
|
||||
} else {
|
||||
if (evenSum & 0x01) != 0 || evenSum > 10 || evenSum < 4 {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
if (evenSum & 0x01) != 0 || !(4..=10).contains(&evenSum) {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
let group = ((10 - evenSum) / 2) as usize;
|
||||
let oddWidest = Self::INSIDE_ODD_WIDEST[group];
|
||||
@@ -393,10 +397,10 @@ impl RSS14Reader {
|
||||
let vEven = rss_utils::getRSSvalue(&self.evenCounts, evenWidest, false);
|
||||
let tOdd = Self::INSIDE_ODD_TOTAL_SUBSET[group];
|
||||
let gSum = Self::INSIDE_GSUM[group];
|
||||
return Ok(DataCharacter::new(
|
||||
Ok(DataCharacter::new(
|
||||
vEven * tOdd + vOdd + gSum,
|
||||
checksumPortion,
|
||||
));
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,7 +453,7 @@ impl RSS14Reader {
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
|
||||
fn parseFoundFinderPattern(
|
||||
@@ -534,7 +538,7 @@ impl RSS14Reader {
|
||||
}
|
||||
|
||||
let mismatch = oddSum as i32 + evenSum as i32 - numModules as i32;
|
||||
let oddParityBad = (oddSum & 0x01) == (if outsideChar { 1 } else { 0 });
|
||||
let oddParityBad = (oddSum & 0x01) == u32::from(outsideChar); //(if outsideChar { 1 } else { 0 });
|
||||
let evenParityBad = (evenSum & 0x01) == 1;
|
||||
/*if (mismatch == 2) {
|
||||
if (!(oddParityBad && evenParityBad)) {
|
||||
@@ -553,12 +557,12 @@ impl RSS14Reader {
|
||||
1 => {
|
||||
if oddParityBad {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
decrementOdd = true;
|
||||
} else {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
decrementEven = true;
|
||||
}
|
||||
@@ -566,12 +570,12 @@ impl RSS14Reader {
|
||||
-1 => {
|
||||
if oddParityBad {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
incrementOdd = true;
|
||||
} else {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
incrementEven = true;
|
||||
}
|
||||
@@ -579,7 +583,7 @@ impl RSS14Reader {
|
||||
0 => {
|
||||
if oddParityBad {
|
||||
if !evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
// Both bad
|
||||
if oddSum < evenSum {
|
||||
@@ -589,19 +593,16 @@ impl RSS14Reader {
|
||||
decrementOdd = true;
|
||||
incrementEven = true;
|
||||
}
|
||||
} else {
|
||||
if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
}
|
||||
// Nothing to do!
|
||||
} else if evenParityBad {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
}
|
||||
_ => return Err(Exceptions::NotFoundException("".to_owned())),
|
||||
_ => return Err(Exceptions::NotFoundException(None)),
|
||||
}
|
||||
|
||||
if incrementOdd {
|
||||
if decrementOdd {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
|
||||
}
|
||||
@@ -610,7 +611,7 @@ impl RSS14Reader {
|
||||
}
|
||||
if incrementEven {
|
||||
if decrementEven {
|
||||
return Err(Exceptions::NotFoundException("".to_owned()));
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
Self::increment(&mut self.evenCounts, &self.evenRoundingErrors);
|
||||
}
|
||||
|
||||
@@ -64,13 +64,15 @@ pub fn getRSSvalue(widths: &[u32], maxWidth: u32, noNarrow: bool) -> u32 {
|
||||
}
|
||||
n -= elmWidth;
|
||||
}
|
||||
return val;
|
||||
val
|
||||
}
|
||||
|
||||
fn combins(n: u32, r: u32) -> u32 {
|
||||
let maxDenom;
|
||||
let minDenom;
|
||||
if n - r > r {
|
||||
|
||||
// if n - r > r {
|
||||
if n.checked_sub(r).is_none() {
|
||||
minDenom = r;
|
||||
maxDenom = n - r;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user