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/ * http://www.piramidepse.com/
*/ */
use crate::{Exceptions, common::BitArray}; use crate::{common::BitArray, Exceptions};
use super::GeneralAppIdDecoder; use super::GeneralAppIdDecoder;
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es) * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/ */
pub trait AbstractExpandedDecoder { pub trait AbstractExpandedDecoder {
// private final BitArray information; // private final BitArray information;
// private final GeneralAppIdDecoder generalDecoder; // private final GeneralAppIdDecoder generalDecoder;
@@ -53,7 +50,7 @@ pub trait AbstractExpandedDecoder {
// return generalDecoder; // return generalDecoder;
// } // }
fn parseInformation(&mut self) -> Result<String,Exceptions>; fn parseInformation(&mut self) -> Result<String, Exceptions>;
fn getGeneralDecoder(&self) -> &GeneralAppIdDecoder; fn getGeneralDecoder(&self) -> &GeneralAppIdDecoder;
// fn new(information:&BitArray) -> Self where Self:Sized; // fn new(information:&BitArray) -> Self where Self:Sized;
} }

View File

@@ -32,15 +32,17 @@ use super::{AI01decoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es) * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/ */
pub struct AI01AndOtherAIs<'a>(&'a BitArray,GeneralAppIdDecoder<'a>); pub struct AI01AndOtherAIs<'a>(&'a BitArray, GeneralAppIdDecoder<'a>);
impl<'a> AI01decoder for AI01AndOtherAIs<'_> {} impl<'a> AI01decoder for AI01AndOtherAIs<'_> {}
impl AbstractExpandedDecoder for AI01AndOtherAIs<'_> { impl AbstractExpandedDecoder for AI01AndOtherAIs<'_> {
fn parseInformation(&mut self) -> Result<String,crate::Exceptions> { fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
let mut buff = String::new();//new StringBuilder(); let mut buff = String::new(); //new StringBuilder();
buff.push_str("(01)"); buff.push_str("(01)");
let initialGtinPosition = buff.chars().count(); 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()); buff.push_str(&firstGtinDigit.to_string());
self.encodeCompressedGtinWithoutAI(&mut buff, Self::HEADER_SIZE + 4, initialGtinPosition); self.encodeCompressedGtinWithoutAI(&mut buff, Self::HEADER_SIZE + 4, initialGtinPosition);
@@ -53,11 +55,11 @@ impl AbstractExpandedDecoder for AI01AndOtherAIs<'_> {
} }
} }
impl<'a> AI01AndOtherAIs<'_> { impl<'a> AI01AndOtherAIs<'_> {
fn new(information:&'a BitArray) -> AI01AndOtherAIs<'a> { fn new(information: &'a BitArray) -> AI01AndOtherAIs<'a> {
AI01AndOtherAIs( information,GeneralAppIdDecoder::new(information)) AI01AndOtherAIs(information, GeneralAppIdDecoder::new(information))
} }
const HEADER_SIZE : usize = 1 + 1 + 2; //first bit encodes the linkage flag, const HEADER_SIZE: usize = 1 + 1 + 2; //first bit encodes the linkage flag,
//the second one is the encodation method, and the other two are for the variable length //the second one is the encodation method, and the other two are for the variable length
// AI01AndOtherAIs(BitArray information) { // AI01AndOtherAIs(BitArray information) {
// super(information); // super(information);

View File

@@ -26,16 +26,14 @@
use super::AbstractExpandedDecoder; use super::AbstractExpandedDecoder;
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es) * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/ */
pub trait AI01decoder : AbstractExpandedDecoder { pub trait AI01decoder: AbstractExpandedDecoder {
const GTIN_SIZE: u32 = 40;
const GTIN_SIZE : u32 = 40; fn encodeCompressedGtin(&self, buf: &mut String, currentPos: usize) {
fn encodeCompressedGtin(&self, buf:&mut String, currentPos:usize) {
buf.push_str("(01)"); buf.push_str("(01)");
let initialPosition = buf.chars().count(); let initialPosition = buf.chars().count();
buf.push('9'); buf.push('9');
@@ -43,10 +41,17 @@ pub trait AI01decoder : AbstractExpandedDecoder {
self.encodeCompressedGtinWithoutAI(buf, currentPos, initialPosition); 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 i in 0..4 {
// for (int i = 0; i < 4; ++i) { // 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 { if currentBlock / 100 == 0 {
buf.push('0'); buf.push('0');
} }
@@ -58,17 +63,14 @@ pub trait AI01decoder : AbstractExpandedDecoder {
appendCheckDigit(buf, initialBufferPosition); appendCheckDigit(buf, initialBufferPosition);
} }
} }
pub(super) fn appendCheckDigit( buf:&mut String, currentPos:usize) { pub(super) fn appendCheckDigit(buf: &mut String, currentPos: usize) {
let mut checkDigit = 0; let mut checkDigit = 0;
for i in 0..13 { for i in 0..13 {
// for (int i = 0; i < 13; i++) { // for (int i = 0; i < 13; i++) {
let digit = buf.chars().nth(i + currentPos).unwrap() as u32 - '0' as u32; let digit = buf.chars().nth(i + currentPos).unwrap() as u32 - '0' as u32;
checkDigit += if (i & 0x01) == 0 {3 * digit} else {digit}; checkDigit += if (i & 0x01) == 0 { 3 * digit } else { digit };
} }
checkDigit = 10 - (checkDigit % 10); checkDigit = 10 - (checkDigit % 10);

View File

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

View File

@@ -281,17 +281,15 @@ impl DataLength {
} }
} }
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es) * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/ */
#[cfg(test)] #[cfg(test)]
mod FieldParserTest { mod FieldParserTest {
fn checkFields( expected:&str) { fn checkFields(expected: &str) {
let field = expected.replace("(", "").replace(")",""); let field = expected.replace("(", "").replace(")", "");
let actual = super::parseFieldsInGeneralPurpose(&field).expect("parse"); let actual = super::parseFieldsInGeneralPurpose(&field).expect("parse");
assert_eq!(expected, actual); assert_eq!(expected, actual);
} }

View File

@@ -26,35 +26,41 @@
use crate::{common::BitArray, Exceptions}; 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 Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es) * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
*/ */
pub struct GeneralAppIdDecoder<'a> { pub struct GeneralAppIdDecoder<'a> {
information: &'a BitArray,
information:&'a BitArray, current: CurrentParsingState, //= new CurrentParsingState();
current : CurrentParsingState, //= new CurrentParsingState(); buffer: String, //= new StringBuilder();
buffer :String, //= new StringBuilder();
} }
impl<'a> GeneralAppIdDecoder<'_> { impl<'a> GeneralAppIdDecoder<'_> {
pub fn new( information:&'a BitArray) -> GeneralAppIdDecoder<'a>{ pub fn new(information: &'a BitArray) -> GeneralAppIdDecoder<'a> {
GeneralAppIdDecoder{ GeneralAppIdDecoder {
information, information,
current: CurrentParsingState::new(), current: CurrentParsingState::new(),
buffer: String::new(), buffer: String::new(),
} }
} }
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 buff = buff;
let mut currentPosition = initialPosition; let mut currentPosition = initialPosition;
let mut remaining = "".to_owned(); let mut remaining = "".to_owned();
loop { loop {
let info = self.decodeGeneralPurposeField(currentPosition, &remaining)?; let info = self.decodeGeneralPurposeField(currentPosition, &remaining)?;
let parsedFields =field_parser::parseFieldsInGeneralPurpose(info.getNewString())?; let parsedFields = field_parser::parseFieldsInGeneralPurpose(info.getNewString())?;
if !parsedFields.is_empty() { if !parsedFields.is_empty() {
buff.push_str(&parsedFields); buff.push_str(&parsedFields);
} }
@@ -64,7 +70,8 @@ impl<'a> GeneralAppIdDecoder<'_> {
remaining = "".to_owned(); remaining = "".to_owned();
} }
if currentPosition == info.getNewPosition() { // No step forward! if currentPosition == info.getNewPosition() {
// No step forward!
break; break;
} }
currentPosition = info.getNewPosition(); currentPosition = info.getNewPosition();
@@ -73,14 +80,14 @@ impl<'a> GeneralAppIdDecoder<'_> {
Ok(buff) Ok(buff)
} }
fn isStillNumeric(&self, pos:usize) -> bool{ fn isStillNumeric(&self, pos: usize) -> bool {
// It's numeric if it still has 7 positions // It's numeric if it still has 7 positions
// and one of the first 4 bits is "1". // and one of the first 4 bits is "1".
if pos + 7 > self.information.getSize() { if pos + 7 > self.information.getSize() {
return pos + 4 <= self.information.getSize(); return pos + 4 <= self.information.getSize();
} }
for i in pos..pos+3 { for i in pos..pos + 3 {
// for (int i = pos; i < pos + 3; ++i) { // for (int i = pos; i < pos + 3; ++i) {
if self.information.get(i) { if self.information.get(i) {
return true; return true;
@@ -90,13 +97,21 @@ impl<'a> GeneralAppIdDecoder<'_> {
self.information.get(pos + 3) self.information.get(pos + 3)
} }
fn decodeNumeric(&self, pos:usize) -> Result<DecodedNumeric,Exceptions> { fn decodeNumeric(&self, pos: usize) -> Result<DecodedNumeric, Exceptions> {
if pos + 7 > self.information.getSize() { if pos + 7 > self.information.getSize() {
let numeric = self.extractNumericValueFromBitArray(pos, 4); let numeric = self.extractNumericValueFromBitArray(pos, 4);
if numeric == 0 { 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); let numeric = self.extractNumericValueFromBitArray(pos, 7);
@@ -106,11 +121,15 @@ impl<'a> GeneralAppIdDecoder<'_> {
DecodedNumeric::new(pos + 7, digit1, digit2) DecodedNumeric::new(pos + 7, digit1, digit2)
} }
pub fn extractNumericValueFromBitArray(&self, pos:usize, bits:u32) -> u32{ pub fn extractNumericValueFromBitArray(&self, pos: usize, bits: u32) -> u32 {
Self::extractNumericValueFromBitArrayWithInformation(&self.information, pos, bits) 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; let mut value = 0;
for i in 0..bits { for i in 0..bits {
// for (int i = 0; i < bits; ++i) { // for (int i = 0; i < bits; ++i) {
@@ -122,7 +141,11 @@ impl<'a> GeneralAppIdDecoder<'_> {
value 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(); self.buffer.clear();
if !remaining.is_empty() { if !remaining.is_empty() {
@@ -131,27 +154,35 @@ impl<'a> GeneralAppIdDecoder<'_> {
self.current.setPosition(pos); self.current.setPosition(pos);
if let Ok(lastDecoded) = self.parseBlocks(){ if let Ok(lastDecoded) = self.parseBlocks() {
if lastDecoded.isRemaining() { if lastDecoded.isRemaining() {
return Ok(DecodedInformation::with_remaining_value(self.current.getPosition(), return Ok(DecodedInformation::with_remaining_value(
self.buffer.clone(), lastDecoded.getRemainingValue())); self.current.getPosition(),
}} self.buffer.clone(),
Ok(DecodedInformation::new(self.current.getPosition(), self.buffer.clone())) lastDecoded.getRemainingValue(),
));
}
}
Ok(DecodedInformation::new(
self.current.getPosition(),
self.buffer.clone(),
))
} }
fn parseBlocks(&mut self) -> Result<DecodedInformation,Exceptions> { fn parseBlocks(&mut self) -> Result<DecodedInformation, Exceptions> {
let mut isFinished; let mut isFinished;
let mut result:BlockParsedRXingResult; let mut result: BlockParsedRXingResult;
loop { loop {
let initialPosition = self.current.getPosition(); let initialPosition = self.current.getPosition();
if self.current.isAlpha() { if self.current.isAlpha() {
result =self. parseAlphaBlock()?; result = self.parseAlphaBlock()?;
isFinished = result.isFinished(); isFinished = result.isFinished();
} else if self.current.isIsoIec646() { } else if self.current.isIsoIec646() {
result = self.parseIsoIec646Block()?; result = self.parseIsoIec646Block()?;
isFinished = result.isFinished(); isFinished = result.isFinished();
} else { // it must be numeric } else {
// it must be numeric
result = self.parseNumericBlock()?; result = self.parseNumericBlock()?;
isFinished = result.isFinished(); isFinished = result.isFinished();
} }
@@ -161,31 +192,43 @@ impl<'a> GeneralAppIdDecoder<'_> {
break; break;
} }
if !(!isFinished) { break; } if !(!isFinished) {
break;
}
} //while (!isFinished); } //while (!isFinished);
Ok(result.getDecodedInformation().as_ref().unwrap().clone()) Ok(result.getDecodedInformation().as_ref().unwrap().clone())
} }
fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult,Exceptions> { fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {
while self.isStillNumeric(self.current.getPosition()) { while self.isStillNumeric(self.current.getPosition()) {
let numeric = self.decodeNumeric(self.current.getPosition())?; let numeric = self.decodeNumeric(self.current.getPosition())?;
self.current.setPosition(numeric.getNewPosition()); self.current.setPosition(numeric.getNewPosition());
if numeric.isFirstDigitFNC1() { if numeric.isFirstDigitFNC1() {
let information= let information = if numeric.isSecondDigitFNC1() {
if numeric.isSecondDigitFNC1() {
DecodedInformation::new(self.current.getPosition(), self.buffer.clone()) DecodedInformation::new(self.current.getPosition(), self.buffer.clone())
} else { } 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()); self.buffer.push_str(&numeric.getFirstDigit().to_string());
if numeric.isSecondDigitFNC1() { if numeric.isSecondDigitFNC1() {
let information = DecodedInformation::new(self.current.getPosition(), self.buffer.clone()); let information =
return Ok(BlockParsedRXingResult::with_information(Some(information), true)); DecodedInformation::new(self.current.getPosition(), self.buffer.clone());
return Ok(BlockParsedRXingResult::with_information(
Some(information),
true,
));
} }
self.buffer.push_str(&numeric.getSecondDigit().to_string()); self.buffer.push_str(&numeric.getSecondDigit().to_string());
} }
@@ -198,14 +241,18 @@ impl<'a> GeneralAppIdDecoder<'_> {
Ok(BlockParsedRXingResult::new()) Ok(BlockParsedRXingResult::new())
} }
fn parseIsoIec646Block(&mut self) -> Result<BlockParsedRXingResult,Exceptions> { fn parseIsoIec646Block(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {
while self.isStillIsoIec646(self.current.getPosition()) { while self.isStillIsoIec646(self.current.getPosition()) {
let iso = self.decodeIsoIec646(self.current.getPosition())?; let iso = self.decodeIsoIec646(self.current.getPosition())?;
self.current.setPosition(iso.getNewPosition()); self.current.setPosition(iso.getNewPosition());
if iso.isFNC1() { if iso.isFNC1() {
let information = DecodedInformation::new(self.current.getPosition(), self.buffer.clone()); let information =
return Ok(BlockParsedRXingResult::with_information(Some(information), true)); DecodedInformation::new(self.current.getPosition(), self.buffer.clone());
return Ok(BlockParsedRXingResult::with_information(
Some(information),
true,
));
} }
self.buffer.push_str(&iso.getValue().to_string()); self.buffer.push_str(&iso.getValue().to_string());
} }
@@ -215,7 +262,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
self.current.setNumeric(); self.current.setNumeric();
} else if self.isAlphaTo646ToAlphaLatch(self.current.getPosition()) { } else if self.isAlphaTo646ToAlphaLatch(self.current.getPosition()) {
if self.current.getPosition() + 5 < self.information.getSize() { if self.current.getPosition() + 5 < self.information.getSize() {
self. current.incrementPosition(5); self.current.incrementPosition(5);
} else { } else {
self.current.setPosition(self.information.getSize()); self.current.setPosition(self.information.getSize());
} }
@@ -225,14 +272,18 @@ impl<'a> GeneralAppIdDecoder<'_> {
Ok(BlockParsedRXingResult::new()) Ok(BlockParsedRXingResult::new())
} }
fn parseAlphaBlock(&mut self) -> Result<BlockParsedRXingResult,Exceptions> { fn parseAlphaBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {
while self.isStillAlpha(self.current.getPosition()) { while self.isStillAlpha(self.current.getPosition()) {
let alpha = self.decodeAlphanumeric(self.current.getPosition())?; let alpha = self.decodeAlphanumeric(self.current.getPosition())?;
self.current.setPosition(alpha.getNewPosition()); self.current.setPosition(alpha.getNewPosition());
if alpha.isFNC1() { if alpha.isFNC1() {
let information = DecodedInformation::new(self.current.getPosition(), self.buffer.clone()); let information =
return Ok(BlockParsedRXingResult::with_information(Some(information), true)); //end of the char block 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()); self.buffer.push_str(&alpha.getValue().to_string());
@@ -254,12 +305,12 @@ impl<'a> GeneralAppIdDecoder<'_> {
Ok(BlockParsedRXingResult::new()) Ok(BlockParsedRXingResult::new())
} }
fn isStillIsoIec646(&self, pos:usize) -> bool{ fn isStillIsoIec646(&self, pos: usize) -> bool {
if pos + 5 > self.information.getSize() { if pos + 5 > self.information.getSize() {
return false; return false;
} }
let fiveBitValue =self. extractNumericValueFromBitArray(pos, 5); let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5);
if fiveBitValue >= 5 && fiveBitValue < 16 { if fiveBitValue >= 5 && fiveBitValue < 16 {
return true; return true;
} }
@@ -280,82 +331,67 @@ impl<'a> GeneralAppIdDecoder<'_> {
let eightBitValue = self.extractNumericValueFromBitArray(pos, 8); let eightBitValue = self.extractNumericValueFromBitArray(pos, 8);
eightBitValue >= 232 && eightBitValue < 253 eightBitValue >= 232 && eightBitValue < 253
} }
fn decodeIsoIec646(&self, pos:usize) -> Result<DecodedChar,Exceptions> { fn decodeIsoIec646(&self, pos: usize) -> Result<DecodedChar, Exceptions> {
let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5); let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5);
if fiveBitValue == 15 { if fiveBitValue == 15 {
return Ok(DecodedChar::new(pos + 5, DecodedChar::FNC1)); return Ok(DecodedChar::new(pos + 5, DecodedChar::FNC1));
} }
if fiveBitValue >= 5 && fiveBitValue < 15 { 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); let sevenBitValue = self.extractNumericValueFromBitArray(pos, 7);
if sevenBitValue >= 64 && sevenBitValue < 90 { 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 { 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 eightBitValue = self.extractNumericValueFromBitArray(pos, 8);
let c= let c = match eightBitValue {
match eightBitValue { 232 => '!',
232=> 233 => '"',
'!', 234 => '%',
233=> 235 => '&',
'"', 236 => '\'',
234=> 237 => '(',
'%', 238 => ')',
235=> 239 => '*',
'&', 240 => '+',
236=> 241 => ',',
'\'', 242 => '-',
237=> 243 => '.',
'(', 244 => '/',
238=> 245 => ':',
')', 246 => ';',
239=> 247 => '<',
'*', 248 => '=',
240=> 249 => '>',
'+', 250 => '?',
241=> 251 => '_',
',', 252 => ' ',
242=> _ => return Err(Exceptions::FormatException("".to_owned())),
'-',
243=>
'.',
244=>
'/',
245=>
':',
246=>
';',
247=>
'<',
248=>
'=',
249=>
'>',
250=>
'?',
251=>
'_',
252=>
' ',
_=>
return Err(Exceptions::FormatException("".to_owned())),
}; };
Ok(DecodedChar::new(pos + 8, c)) Ok(DecodedChar::new(pos + 8, c))
} }
fn isStillAlpha(&self, pos:usize) -> bool{ fn isStillAlpha(&self, pos: usize) -> bool {
if pos + 5 > self.information.getSize() { if pos + 5 > self.information.getSize() {
return false; return false;
} }
@@ -375,42 +411,46 @@ impl<'a> GeneralAppIdDecoder<'_> {
sixBitValue >= 16 && sixBitValue < 63 // 63 not included sixBitValue >= 16 && sixBitValue < 63 // 63 not included
} }
fn decodeAlphanumeric(&self, pos:usize) -> Result<DecodedChar,Exceptions> { fn decodeAlphanumeric(&self, pos: usize) -> Result<DecodedChar, Exceptions> {
let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5); let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5);
if fiveBitValue == 15 { if fiveBitValue == 15 {
return Ok(DecodedChar::new(pos + 5, DecodedChar::FNC1)); return Ok(DecodedChar::new(pos + 5, DecodedChar::FNC1));
} }
if fiveBitValue >= 5 && fiveBitValue < 15 { 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); let sixBitValue = self.extractNumericValueFromBitArray(pos, 6);
if sixBitValue >= 32 && sixBitValue < 58 { 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 = let c = match sixBitValue {
match sixBitValue { 58 => '*',
58=> 59 => ',',
'*', 60 => '-',
59=> 61 => '.',
',', 62 => '/',
60=> _ => {
'-', return Err(Exceptions::IllegalStateException(format!(
61=> "Decoding invalid alphanumeric value: {}",
'.', sixBitValue
62=> )))
'/', }
_=>
return Err(Exceptions::IllegalStateException(format!("Decoding invalid alphanumeric value: {}" , sixBitValue))),
}; };
Ok(DecodedChar::new(pos + 6, c)) Ok(DecodedChar::new(pos + 6, c))
} }
fn isAlphaTo646ToAlphaLatch(&self, pos:usize)-> bool { fn isAlphaTo646ToAlphaLatch(&self, pos: usize) -> bool {
if pos + 1 > self.information.getSize() { if pos + 1 > self.information.getSize() {
return false; return false;
} }
@@ -426,19 +466,19 @@ impl<'a> GeneralAppIdDecoder<'_> {
return false; return false;
} }
i+=1; i += 1;
} }
true true
} }
fn isAlphaOr646ToNumericLatch(&self, pos:usize) -> bool{ fn isAlphaOr646ToNumericLatch(&self, pos: usize) -> bool {
// Next is alphanumeric if there are 3 positions and they are all zeros // Next is alphanumeric if there are 3 positions and they are all zeros
if pos + 3 > self.information.getSize() { if pos + 3 > self.information.getSize() {
return false; return false;
} }
for i in pos..pos+3 { for i in pos..pos + 3 {
// for (int i = pos; i < pos + 3; ++i) { // for (int i = pos; i < pos + 3; ++i) {
if self.information.get(i) { if self.information.get(i) {
return false; return false;
@@ -448,7 +488,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
true true
} }
fn isNumericToAlphaNumericLatch(&self, pos:usize) -> bool{ fn isNumericToAlphaNumericLatch(&self, pos: usize) -> bool {
// Next is alphanumeric if there are 4 positions and they are all zeros, or // Next is alphanumeric if there are 4 positions and they are all zeros, or
// if there is a subset of this just before the end of the symbol // if there is a subset of this just before the end of the symbol
if pos + 1 > self.information.getSize() { if pos + 1 > self.information.getSize() {
@@ -461,7 +501,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
if self.information.get(pos + i) { if self.information.get(pos + i) {
return false; return false;
} }
i+=1; i += 1;
} }
true true

View File

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