cargo fmt

This commit is contained in:
Henry Schimke
2022-12-14 17:58:40 -06:00
parent 2de4061f8b
commit 14d8245568
7 changed files with 557 additions and 524 deletions

View File

@@ -24,19 +24,16 @@
* http://www.piramidepse.com/
*/
use crate::{Exceptions, common::BitArray};
use crate::{common::BitArray, Exceptions};
use super::GeneralAppIdDecoder;
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/
pub trait AbstractExpandedDecoder {
// private final BitArray information;
// private final GeneralAppIdDecoder generalDecoder;

View File

@@ -40,7 +40,9 @@ impl AbstractExpandedDecoder for AI01AndOtherAIs<'_> {
buff.push_str("(01)");
let initialGtinPosition = buff.chars().count();
let firstGtinDigit = self.getGeneralDecoder().extractNumericValueFromBitArray(Self::HEADER_SIZE, 4);
let firstGtinDigit = self
.getGeneralDecoder()
.extractNumericValueFromBitArray(Self::HEADER_SIZE, 4);
buff.push_str(&firstGtinDigit.to_string());
self.encodeCompressedGtinWithoutAI(&mut buff, Self::HEADER_SIZE + 4, initialGtinPosition);

View File

@@ -26,13 +26,11 @@
use super::AbstractExpandedDecoder;
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/
pub trait AI01decoder: AbstractExpandedDecoder {
const GTIN_SIZE: u32 = 40;
fn encodeCompressedGtin(&self, buf: &mut String, currentPos: usize) {
@@ -43,10 +41,17 @@ pub trait AI01decoder : AbstractExpandedDecoder {
self.encodeCompressedGtinWithoutAI(buf, currentPos, initialPosition);
}
fn encodeCompressedGtinWithoutAI(&self, buf:&mut String, currentPos:usize, initialBufferPosition:usize) {
fn encodeCompressedGtinWithoutAI(
&self,
buf: &mut String,
currentPos: usize,
initialBufferPosition: usize,
) {
for i in 0..4 {
// for (int i = 0; i < 4; ++i) {
let currentBlock = self.getGeneralDecoder().extractNumericValueFromBitArray(currentPos + 10 * i, 10);
let currentBlock = self
.getGeneralDecoder()
.extractNumericValueFromBitArray(currentPos + 10 * i, 10);
if currentBlock / 100 == 0 {
buf.push('0');
}
@@ -58,9 +63,6 @@ pub trait AI01decoder : AbstractExpandedDecoder {
appendCheckDigit(buf, initialBufferPosition);
}
}
pub(super) fn appendCheckDigit(buf: &mut String, currentPos: usize) {

View File

@@ -24,13 +24,9 @@
* http://www.piramidepse.com/
*/
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/
pub trait DecodedObject {
fn getNewPosition(&self) -> usize;
}

View File

@@ -281,8 +281,6 @@ impl DataLength {
}
}
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)

View File

@@ -26,14 +26,16 @@
use crate::{common::BitArray, Exceptions};
use super::{CurrentParsingState, DecodedChar, DecodedNumeric, DecodedInformation, BlockParsedRXingResult, DecodedObject, field_parser};
use super::{
field_parser, BlockParsedRXingResult, CurrentParsingState, DecodedChar, DecodedInformation,
DecodedNumeric, DecodedObject,
};
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/
pub struct GeneralAppIdDecoder<'a> {
information: &'a BitArray,
current: CurrentParsingState, //= new CurrentParsingState();
buffer: String, //= new StringBuilder();
@@ -48,7 +50,11 @@ impl<'a> GeneralAppIdDecoder<'_> {
}
}
pub fn decodeAllCodes(&mut self, buff:String, initialPosition:usize) -> Result<String,Exceptions> {
pub fn decodeAllCodes(
&mut self,
buff: String,
initialPosition: usize,
) -> Result<String, Exceptions> {
let mut buff = buff;
let mut currentPosition = initialPosition;
let mut remaining = "".to_owned();
@@ -64,7 +70,8 @@ impl<'a> GeneralAppIdDecoder<'_> {
remaining = "".to_owned();
}
if currentPosition == info.getNewPosition() { // No step forward!
if currentPosition == info.getNewPosition() {
// No step forward!
break;
}
currentPosition = info.getNewPosition();
@@ -94,9 +101,17 @@ impl<'a> GeneralAppIdDecoder<'_> {
if pos + 7 > self.information.getSize() {
let numeric = self.extractNumericValueFromBitArray(pos, 4);
if numeric == 0 {
return DecodedNumeric::new(self.information.getSize(), DecodedNumeric::FNC1, DecodedNumeric::FNC1);
return DecodedNumeric::new(
self.information.getSize(),
DecodedNumeric::FNC1,
DecodedNumeric::FNC1,
);
}
return DecodedNumeric::new(self.information.getSize(), numeric - 1, DecodedNumeric::FNC1);
return DecodedNumeric::new(
self.information.getSize(),
numeric - 1,
DecodedNumeric::FNC1,
);
}
let numeric = self.extractNumericValueFromBitArray(pos, 7);
@@ -110,7 +125,11 @@ impl<'a> GeneralAppIdDecoder<'_> {
Self::extractNumericValueFromBitArrayWithInformation(&self.information, pos, bits)
}
pub fn extractNumericValueFromBitArrayWithInformation( information:&BitArray, pos:usize, bits:u32) ->u32{
pub fn extractNumericValueFromBitArrayWithInformation(
information: &BitArray,
pos: usize,
bits: u32,
) -> u32 {
let mut value = 0;
for i in 0..bits {
// for (int i = 0; i < bits; ++i) {
@@ -122,7 +141,11 @@ impl<'a> GeneralAppIdDecoder<'_> {
value
}
pub fn decodeGeneralPurposeField(&mut self, pos:usize, remaining:&str) -> Result<DecodedInformation,Exceptions> {
pub fn decodeGeneralPurposeField(
&mut self,
pos: usize,
remaining: &str,
) -> Result<DecodedInformation, Exceptions> {
self.buffer.clear();
if !remaining.is_empty() {
@@ -133,10 +156,17 @@ impl<'a> GeneralAppIdDecoder<'_> {
if let Ok(lastDecoded) = self.parseBlocks() {
if lastDecoded.isRemaining() {
return Ok(DecodedInformation::with_remaining_value(self.current.getPosition(),
self.buffer.clone(), lastDecoded.getRemainingValue()));
}}
Ok(DecodedInformation::new(self.current.getPosition(), self.buffer.clone()))
return Ok(DecodedInformation::with_remaining_value(
self.current.getPosition(),
self.buffer.clone(),
lastDecoded.getRemainingValue(),
));
}
}
Ok(DecodedInformation::new(
self.current.getPosition(),
self.buffer.clone(),
))
}
fn parseBlocks(&mut self) -> Result<DecodedInformation, Exceptions> {
@@ -151,7 +181,8 @@ impl<'a> GeneralAppIdDecoder<'_> {
} else if self.current.isIsoIec646() {
result = self.parseIsoIec646Block()?;
isFinished = result.isFinished();
} else { // it must be numeric
} else {
// it must be numeric
result = self.parseNumericBlock()?;
isFinished = result.isFinished();
}
@@ -161,7 +192,9 @@ impl<'a> GeneralAppIdDecoder<'_> {
break;
}
if !(!isFinished) { break; }
if !(!isFinished) {
break;
}
} //while (!isFinished);
Ok(result.getDecodedInformation().as_ref().unwrap().clone())
@@ -173,19 +206,29 @@ impl<'a> GeneralAppIdDecoder<'_> {
self.current.setPosition(numeric.getNewPosition());
if numeric.isFirstDigitFNC1() {
let information=
if numeric.isSecondDigitFNC1() {
let information = if numeric.isSecondDigitFNC1() {
DecodedInformation::new(self.current.getPosition(), self.buffer.clone())
} else {
DecodedInformation::with_remaining_value(self.current.getPosition(), self.buffer.clone(), numeric.getSecondDigit())
DecodedInformation::with_remaining_value(
self.current.getPosition(),
self.buffer.clone(),
numeric.getSecondDigit(),
)
};
return Ok(BlockParsedRXingResult::with_information(Some(information), true));
return Ok(BlockParsedRXingResult::with_information(
Some(information),
true,
));
}
self.buffer.push_str(&numeric.getFirstDigit().to_string());
if numeric.isSecondDigitFNC1() {
let information = DecodedInformation::new(self.current.getPosition(), self.buffer.clone());
return Ok(BlockParsedRXingResult::with_information(Some(information), true));
let information =
DecodedInformation::new(self.current.getPosition(), self.buffer.clone());
return Ok(BlockParsedRXingResult::with_information(
Some(information),
true,
));
}
self.buffer.push_str(&numeric.getSecondDigit().to_string());
}
@@ -204,8 +247,12 @@ impl<'a> GeneralAppIdDecoder<'_> {
self.current.setPosition(iso.getNewPosition());
if iso.isFNC1() {
let information = DecodedInformation::new(self.current.getPosition(), self.buffer.clone());
return Ok(BlockParsedRXingResult::with_information(Some(information), true));
let information =
DecodedInformation::new(self.current.getPosition(), self.buffer.clone());
return Ok(BlockParsedRXingResult::with_information(
Some(information),
true,
));
}
self.buffer.push_str(&iso.getValue().to_string());
}
@@ -231,8 +278,12 @@ impl<'a> GeneralAppIdDecoder<'_> {
self.current.setPosition(alpha.getNewPosition());
if alpha.isFNC1() {
let information = DecodedInformation::new(self.current.getPosition(), self.buffer.clone());
return Ok(BlockParsedRXingResult::with_information(Some(information), true)); //end of the char block
let information =
DecodedInformation::new(self.current.getPosition(), self.buffer.clone());
return Ok(BlockParsedRXingResult::with_information(
Some(information),
true,
)); //end of the char block
}
self.buffer.push_str(&alpha.getValue().to_string());
@@ -280,7 +331,6 @@ impl<'a> GeneralAppIdDecoder<'_> {
let eightBitValue = self.extractNumericValueFromBitArray(pos, 8);
eightBitValue >= 232 && eightBitValue < 253
}
fn decodeIsoIec646(&self, pos: usize) -> Result<DecodedChar, Exceptions> {
@@ -290,66 +340,52 @@ impl<'a> GeneralAppIdDecoder<'_> {
}
if fiveBitValue >= 5 && fiveBitValue < 15 {
return Ok(DecodedChar::new(pos + 5, char::from_u32 ('0' as u32 + fiveBitValue - 5).unwrap()));
return Ok(DecodedChar::new(
pos + 5,
char::from_u32('0' as u32 + fiveBitValue - 5).unwrap(),
));
}
let sevenBitValue = self.extractNumericValueFromBitArray(pos, 7);
if sevenBitValue >= 64 && sevenBitValue < 90 {
return Ok(DecodedChar::new(pos + 7, char::from_u32 (sevenBitValue + 1).unwrap()));
return Ok(DecodedChar::new(
pos + 7,
char::from_u32(sevenBitValue + 1).unwrap(),
));
}
if sevenBitValue >= 90 && sevenBitValue < 116 {
return Ok(DecodedChar::new(pos + 7, char::from_u32 (sevenBitValue + 7).unwrap()));
return Ok(DecodedChar::new(
pos + 7,
char::from_u32(sevenBitValue + 7).unwrap(),
));
}
let eightBitValue = self.extractNumericValueFromBitArray(pos, 8);
let c=
match eightBitValue {
232=>
'!',
233=>
'"',
234=>
'%',
235=>
'&',
236=>
'\'',
237=>
'(',
238=>
')',
239=>
'*',
240=>
'+',
241=>
',',
242=>
'-',
243=>
'.',
244=>
'/',
245=>
':',
246=>
';',
247=>
'<',
248=>
'=',
249=>
'>',
250=>
'?',
251=>
'_',
252=>
' ',
_=>
return Err(Exceptions::FormatException("".to_owned())),
let c = match eightBitValue {
232 => '!',
233 => '"',
234 => '%',
235 => '&',
236 => '\'',
237 => '(',
238 => ')',
239 => '*',
240 => '+',
241 => ',',
242 => '-',
243 => '.',
244 => '/',
245 => ':',
246 => ';',
247 => '<',
248 => '=',
249 => '>',
250 => '?',
251 => '_',
252 => ' ',
_ => return Err(Exceptions::FormatException("".to_owned())),
};
Ok(DecodedChar::new(pos + 8, c))
@@ -382,29 +418,33 @@ impl<'a> GeneralAppIdDecoder<'_> {
}
if fiveBitValue >= 5 && fiveBitValue < 15 {
return Ok(DecodedChar::new(pos + 5, char::from_u32 ('0' as u32 + fiveBitValue - 5).unwrap()));
return Ok(DecodedChar::new(
pos + 5,
char::from_u32('0' as u32 + fiveBitValue - 5).unwrap(),
));
}
let sixBitValue = self.extractNumericValueFromBitArray(pos, 6);
if sixBitValue >= 32 && sixBitValue < 58 {
return Ok(DecodedChar::new(pos + 6, char::from_u32 (sixBitValue + 33).unwrap()));
return Ok(DecodedChar::new(
pos + 6,
char::from_u32(sixBitValue + 33).unwrap(),
));
}
let c =
match sixBitValue {
58=>
'*',
59=>
',',
60=>
'-',
61=>
'.',
62=>
'/',
_=>
return Err(Exceptions::IllegalStateException(format!("Decoding invalid alphanumeric value: {}" , sixBitValue))),
let c = match sixBitValue {
58 => '*',
59 => ',',
60 => '-',
61 => '.',
62 => '/',
_ => {
return Err(Exceptions::IllegalStateException(format!(
"Decoding invalid alphanumeric value: {}",
sixBitValue
)))
}
};
Ok(DecodedChar::new(pos + 6, c))

View File

@@ -1,5 +1,3 @@
pub mod abstract_expanded_decoder;
pub use abstract_expanded_decoder::AbstractExpandedDecoder;
mod ai_01_and_other_ais;