cargo fmt

This commit is contained in:
Henry Schimke
2022-10-17 10:51:08 -05:00
parent 111fe47566
commit ae11af8c5b
136 changed files with 2117 additions and 1776 deletions

View File

@@ -176,8 +176,10 @@ fn testAztecWriter() {
);
// Test AztecWriter defaults
let data = "In ut magna vel mauris malesuada";
let writer = AztecWriter{};
let matrix = writer.encode(data, &BarcodeFormat::AZTEC, 0, 0).expect("matrix must exist");
let writer = AztecWriter {};
let matrix = writer
.encode(data, &BarcodeFormat::AZTEC, 0, 0)
.expect("matrix must exist");
let aztec = encoder::encode(
data,
encoder::DEFAULT_EC_PERCENT,
@@ -731,7 +733,8 @@ fn testWriter(
EncodeHintType::ERROR_CORRECTION,
EncodeHintValue::ErrorCorrection(ecc_percent.to_string()),
);
let mut matrix = AztecWriter{}.encode_with_hints(data, &BarcodeFormat::AZTEC, 0, 0, &hints)
let mut matrix = AztecWriter {}
.encode_with_hints(data, &BarcodeFormat::AZTEC, 0, 0, &hints)
.expect("encoder created");
let cset = match charset {

View File

@@ -52,8 +52,8 @@ impl Reader for AztecReader {
// let notFoundException = None;
// let formatException = None;
let mut detector = Detector::new(image.getBlackMatrix()?.clone());
let points;
let decoderRXingResult: DecoderRXingResult;
let points;
let decoderRXingResult: DecoderRXingResult;
// try {
let detectorRXingResult = if let Ok(det) = detector.detect(false) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
use std::{ collections::HashMap};
use std::collections::HashMap;
use encoding::EncodingRef;

View File

@@ -14,11 +14,10 @@
* limitations under the License.
*/
use crate::{
common::{
reedsolomon::{
get_predefined_genericgf, PredefinedGenericGF, ReedSolomonDecoder, GenericGFRef,
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonDecoder,
},
BitMatrix, CharacterSetECI, DecoderRXingResult, DetectorRXingResult,
},

View File

@@ -278,10 +278,10 @@ impl Detector {
let mut color = true;
self.nb_center_layers = 1;
self.nb_center_layers = 1;
while self.nb_center_layers < 9 {
// for nbCenterLayers in 1..9 {
// for nbCenterLayers in 1..9 {
// for (nbCenterLayers = 1; nbCenterLayers < 9; nbCenterLayers++) {
let pouta = self.get_first_different(&pina, color, 1, -1);
let poutb = self.get_first_different(&pinb, color, 1, 1);
@@ -319,7 +319,7 @@ impl Detector {
color = !color;
self.nb_center_layers+=1;
self.nb_center_layers += 1;
}
if self.nb_center_layers != 5 && self.nb_center_layers != 7 {
@@ -634,8 +634,12 @@ impl Detector {
let i_max = d.floor() as u32; //(int) Math.floor(d);
for _i in 0..i_max {
// for (int i = 0; i < iMax; i++) {
if self.image.get(MathUtils::round(px) as u32, MathUtils::round(py) as u32) != color_model {
if self
.image
.get(MathUtils::round(px) as u32, MathUtils::round(py) as u32)
!= color_model
{
error += 1;
}
px += dx;

View File

@@ -50,7 +50,9 @@ impl BinaryShiftToken {
bit_array.appendBits(bsbc as u32 - 31, 5).unwrap();
}
}
bit_array.appendBits(text[self.binary_shift_start as usize + i].into(), 8).expect("should never fail to append");
bit_array
.appendBits(text[self.binary_shift_start as usize + i].into(), 8)
.expect("should never fail to append");
}
}

View File

@@ -19,7 +19,7 @@ use encoding::Encoding;
use crate::{
common::{
reedsolomon::{
get_predefined_genericgf, PredefinedGenericGF, ReedSolomonEncoder, GenericGFRef,
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonEncoder,
},
BitArray, BitMatrix,
},
@@ -157,7 +157,7 @@ pub fn encode_bytes_with_charset(
let ecc_bits = bits.getSize() as u32 * min_eccpercent / 100 + 11;
let total_size_bits = bits.getSize() as u32 + ecc_bits;
let mut compact;
let mut layers:u32;
let mut layers: u32;
let mut total_bits_in_layer_var;
let mut word_size;
let mut stuffed_bits;

View File

@@ -127,8 +127,8 @@ impl HighLevelEncoder {
char_map[Self::MODE_DIGIT][b'.' as usize] = 13;
let mixed_table = [
'\0', ' ', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}',
'\t', '\n', '\u{000b}', '\u{000c}', '\r', '\u{001b}', '\u{001c}', '\u{001d}', '\u{001e}', '\u{001f}',
'@', '\\', '^', '_', '`', '|', '~', '\u{007f}',
'\t', '\n', '\u{000b}', '\u{000c}', '\r', '\u{001b}', '\u{001c}', '\u{001d}',
'\u{001e}', '\u{001f}', '@', '\\', '^', '_', '`', '|', '~', '\u{007f}',
];
let mut i = 0;
while i < mixed_table.len() {
@@ -245,7 +245,8 @@ impl HighLevelEncoder {
pub fn encode(&self) -> Result<BitArray, Exceptions> {
let mut initial_state = State::new(Token::new(), Self::MODE_UPPER as u32, 0, 0);
if let Some(eci) = CharacterSetECI::getCharacterSetECI(self.charset) {
if eci != CharacterSetECI::ISO8859_1 {//} && eci != CharacterSetECI::Cp1252 {
if eci != CharacterSetECI::ISO8859_1 {
//} && eci != CharacterSetECI::Cp1252 {
initial_state = initial_state.appendFLGn(CharacterSetECI::getValue(&eci))?;
}
} else {
@@ -278,7 +279,7 @@ impl HighLevelEncoder {
b':' if next_char == b' ' => 5,
_ => 0,
};
if pair_code > 0 {
// We have one of the four special PUNCT pairs. Treat them specially.
// Get a new set of states for the two new characters.

View File

@@ -1,15 +1,15 @@
mod aztec_code;
mod token;
mod simple_token;
mod binary_shift_token;
mod state;
mod high_level_encoder;
mod simple_token;
mod state;
mod token;
pub mod encoder;
pub use aztec_code::*;
pub use token::*;
pub use simple_token::*;
pub use binary_shift_token::*;
pub use high_level_encoder::*;
pub use simple_token::*;
pub use state::*;
pub use high_level_encoder::*;
pub use token::*;

View File

@@ -78,7 +78,8 @@ impl State {
let mut bits_added = 3;
/*if eci < 0 {
token.add(0, 3); // 0: FNC1
} else */if eci > 999999 {
} else */
if eci > 999999 {
return Err(Exceptions::IllegalArgumentException(
"ECI code must be between 0 and 999999".to_owned(),
));
@@ -151,15 +152,16 @@ impl State {
bitCount += latch >> 16;
mode = HighLevelEncoder::MODE_UPPER as u32;
}
let deltaBitCount = if self.binary_shift_byte_count == 0 || self.binary_shift_byte_count == 31 {
18
} else {
if self.binary_shift_byte_count == 62 {
9
let deltaBitCount =
if self.binary_shift_byte_count == 0 || self.binary_shift_byte_count == 31 {
18
} else {
8
}
};
if self.binary_shift_byte_count == 62 {
9
} else {
8
}
};
let mut result = State::new(
token,
mode,
@@ -180,7 +182,10 @@ impl State {
return self;
}
let mut token = self.token;
token.addBinaryShift(index - self.binary_shift_byte_count, self.binary_shift_byte_count);
token.addBinaryShift(
index - self.binary_shift_byte_count,
self.binary_shift_byte_count,
);
State::new(token, self.mode, 0, self.bit_count)
}
@@ -218,7 +223,7 @@ impl State {
let mut bit_array = BitArray::new();
// Add each token to the result in forward order
for symbol in symbols.into_iter().rev() {
// for i in (0..symbols.len()).rev() {
// for i in (0..symbols.len()).rev() {
// for (int i = symbols.size() - 1; i >= 0; i--) {
symbol.appendTo(&mut bit_array, text);
}

View File

@@ -36,7 +36,7 @@ impl TokenType {
}
}
#[derive(Debug,Clone,PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Token {
tokens: Vec<TokenType>,
//current_pointer: usize,
@@ -53,13 +53,13 @@ impl Token {
// self.current_pointer -= 1;
// &self.tokens[self.current_pointer]
// }
pub fn add(&mut self, value: i32, bit_count: u32) {
pub fn add(&mut self, value: i32, bit_count: u32) {
//self.current_pointer += 1;
self.tokens
.push(TokenType::Simple(SimpleToken::new(value, bit_count)));
// &self.tokens[self.current_pointer]
}
pub fn addBinaryShift(&mut self, start: u32, byte_count: u32) {
pub fn addBinaryShift(&mut self, start: u32, byte_count: u32) {
//self.current_pointer += 1;
self.tokens
.push(TokenType::BinaryShift(BinaryShiftToken::new(
@@ -78,7 +78,7 @@ impl Iterator for TokenIter {
type Item = TokenType;
fn next(&mut self) -> Option<Self::Item> {
self.src.pop()
self.src.pop()
}
}

View File

@@ -11,8 +11,8 @@ pub use aztec_writer::*;
#[cfg(test)]
mod DecoderTest;
#[cfg(test)]
mod EncoderTest;
#[cfg(test)]
mod DetectorTest;
#[cfg(test)]
mod EncoderTest;
mod shared_test_methods;
mod shared_test_methods;

View File

@@ -5,30 +5,30 @@ use crate::common::BitArray;
use lazy_static::lazy_static;
lazy_static! {
static ref SPACES: Regex =Regex::new("\\s+").unwrap();
static ref DOTX: Regex = Regex::new("[^.X]").unwrap();
static ref SPACES: Regex = Regex::new("\\s+").unwrap();
static ref DOTX: Regex = Regex::new("[^.X]").unwrap();
}
pub fn toBitArray( bits:&str) -> BitArray{
let mut ba_in = BitArray::new();
pub fn toBitArray(bits: &str) -> BitArray {
let mut ba_in = BitArray::new();
let str = DOTX.replace_all(bits, "");
for a_str in str.chars() {
// for (char aStr : str) {
// for (char aStr : str) {
ba_in.appendBit(a_str == 'X');
}
ba_in
}
}
pub fn toBooleanArray( bitArray:&BitArray) ->Vec<bool>{
let mut result = vec![false;bitArray.getSize()];
pub fn toBooleanArray(bitArray: &BitArray) -> Vec<bool> {
let mut result = vec![false; bitArray.getSize()];
for i in 0..result.len() {
// for (int i = 0; i < result.length; i++) {
result[i] = bitArray.get(i);
// for (int i = 0; i < result.length; i++) {
result[i] = bitArray.get(i);
}
result
}
result
}
pub fn stripSpace( s:&str) -> String{
pub fn stripSpace(s: &str) -> String {
SPACES.replace_all(s, "").to_string()
}
}