Skip to content

Commit

Permalink
clippy --fix && fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hschimke committed Mar 4, 2023
1 parent 8a0744e commit 69c0119
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 68 deletions.
6 changes: 3 additions & 3 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rxing::aztec::AztecReader;
use rxing::common::HybridBinarizer;
use rxing::datamatrix::DataMatrixReader;
use rxing::maxicode::MaxiCodeReader;
use rxing::multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader};
use rxing::oned::rss::expanded::RSSExpandedReader;
use rxing::oned::rss::RSS14Reader;
use rxing::oned::{
Expand All @@ -11,10 +12,9 @@ use rxing::oned::{
};
use rxing::pdf417::PDF417Reader;
use rxing::qrcode::QRCodeReader;
use rxing::MultiFormatReader;
use rxing::{BinaryBitmap, BufferedImageLuminanceSource, Reader};
use std::path::Path;
use rxing::multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader};
use rxing::MultiFormatReader;

fn get_image(
path: impl AsRef<Path>,
Expand Down Expand Up @@ -188,7 +188,7 @@ fn upce_benchmark(c: &mut Criterion) {
fn multi_barcode_benchmark(c: &mut Criterion) {
let mut image = get_image("test_resources/blackbox/multi-1/1.png");
c.bench_function("multi_barcode", |b| {
b.iter( || {
b.iter(|| {
let mut reader = GenericMultipleBarcodeReader::new(MultiFormatReader::default());
let _res = reader.decode_multiple(&mut image);
});
Expand Down
4 changes: 2 additions & 2 deletions src/aztec/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
reedsolomon::{
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonDecoder,
},
BitMatrix, CharacterSet, DecoderRXingResult, DetectorRXingResult, Result, Eci,
BitMatrix, CharacterSet, DecoderRXingResult, DetectorRXingResult, Eci, Result,
},
exceptions::Exceptions,
};
Expand Down Expand Up @@ -182,7 +182,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
eci = eci * 10 + (next_digit - 2);
n -= 1;
}
let charset_eci : Eci= eci.into();
let charset_eci: Eci = eci.into();
if charset_eci == Eci::Unknown {
return Err(Exceptions::format_with("Charset must exist"));
}
Expand Down
2 changes: 1 addition & 1 deletion src/aztec/encoder/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::fmt;

use crate::{
common::{BitArray, CharacterSet, Result, Eci},
common::{BitArray, CharacterSet, Eci, Result},
exceptions::Exceptions,
};

Expand Down
75 changes: 39 additions & 36 deletions src/common/character_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ use crate::Exceptions;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum CharacterSet {
// Enum name is a Java encoding valid for java.lang and java.io
Cp437, //(new int[]{0,2}),
ISO8859_1, //(new int[]{1,3}, "ISO-8859-1"),
ISO8859_2, //(4, "ISO-8859-2"),
ISO8859_3, //(5, "ISO-8859-3"),
ISO8859_4, //(6, "ISO-8859-4"),
ISO8859_5, //(7, "ISO-8859-5"),
ISO8859_6, //(8, "ISO-8859-6"),
ISO8859_7, //(9, "ISO-8859-7"),
ISO8859_8, //(10, "ISO-8859-8"),
ISO8859_9, //(11, "ISO-8859-9"),
ISO8859_10, //(12, "ISO-8859-10"),
ISO8859_11, //(13, "ISO-8859-11"),
Cp437, //(new int[]{0,2}),
ISO8859_1, //(new int[]{1,3}, "ISO-8859-1"),
ISO8859_2, //(4, "ISO-8859-2"),
ISO8859_3, //(5, "ISO-8859-3"),
ISO8859_4, //(6, "ISO-8859-4"),
ISO8859_5, //(7, "ISO-8859-5"),
ISO8859_6, //(8, "ISO-8859-6"),
ISO8859_7, //(9, "ISO-8859-7"),
ISO8859_8, //(10, "ISO-8859-8"),
ISO8859_9, //(11, "ISO-8859-9"),
ISO8859_10, //(12, "ISO-8859-10"),
ISO8859_11, //(13, "ISO-8859-11"),
ISO8859_13, //(15, "ISO-8859-13"),
ISO8859_14, //(16, "ISO-8859-14"),
ISO8859_15, //(17, "ISO-8859-15"),
ISO8859_16, //(18, "ISO-8859-16"),
Shift_JIS, //(20, "Shift_JIS"),
Cp1250, //(21, "windows-1250"),
Cp1251, //(22, "windows-1251"),
Cp1252, //(23, "windows-1252"),
Cp1256, //(24, "windows-1256"),
UTF16BE, //(25, "UTF-16BE", "UnicodeBig"),
UTF8, //(26, "UTF-8"),
ASCII, //(new int[] {27, 170}, "US-ASCII"),
Big5, //(28),
ISO8859_14, //(16, "ISO-8859-14"),
ISO8859_15, //(17, "ISO-8859-15"),
ISO8859_16, //(18, "ISO-8859-16"),
Shift_JIS, //(20, "Shift_JIS"),
Cp1250, //(21, "windows-1250"),
Cp1251, //(22, "windows-1251"),
Cp1252, //(23, "windows-1252"),
Cp1256, //(24, "windows-1256"),
UTF16BE, //(25, "UTF-16BE", "UnicodeBig"),
UTF8, //(26, "UTF-8"),
ASCII, //(new int[] {27, 170}, "US-ASCII"),
Big5, //(28),
GB2312,
GB18030, //(29, "GB2312", "EUC_CN", "GBK"),
EUC_KR, //(30, "EUC-KR");
GB18030, //(29, "GB2312", "EUC_CN", "GBK"),
EUC_KR, //(30, "EUC-KR");
UTF16LE,
UTF32BE,
UTF32LE,
Expand Down Expand Up @@ -278,9 +278,9 @@ impl CharacterSet {
"iso-8859-3" => Some(CharacterSet::ISO8859_3),
"iso-8859-4" => Some(CharacterSet::ISO8859_4),
"iso-8859-5" => Some(CharacterSet::ISO8859_5),
"ISO-8859-6" => Some(CharacterSet::ISO8859_6),
"iso-8859-6" => Some(CharacterSet::ISO8859_6),
"iso-8859-7" => Some(CharacterSet::ISO8859_7),
"ISO-8859-8" => Some(CharacterSet::ISO8859_8),
"iso-8859-8" => Some(CharacterSet::ISO8859_8),
"iso-8859-9" => Some(CharacterSet::ISO8859_9),
"ISO-8859-10" => Some(CharacterSet::ISO8859_10),
"ISO-8859-11" => Some(CharacterSet::ISO8859_11),
Expand All @@ -300,9 +300,9 @@ impl CharacterSet {
"gb2312" => Some(CharacterSet::GB2312),
"gb18030" => Some(CharacterSet::GB18030),
"euc-kr" => Some(CharacterSet::EUC_KR),
"utf-32be"=>Some(CharacterSet::UTF32BE) ,
"utf-32le"=>Some(CharacterSet::UTF32LE) ,
"binary"=>Some(CharacterSet::Binary) ,
"utf-32be" => Some(CharacterSet::UTF32BE),
"utf-32le" => Some(CharacterSet::UTF32LE),
"binary" => Some(CharacterSet::Binary),
"unknown" => Some(CharacterSet::Unknown),
_ => None,
}
Expand All @@ -313,11 +313,14 @@ impl CharacterSet {
use codepage_437::ToCp437;
use codepage_437::CP437_CONTROL;

input.to_cp437(&CP437_CONTROL).map(|data| data.to_vec()).map_err(|e| Exceptions::format_with(format!("{e:?}")))
}else {
self.get_base_encoder()
.encode(input, encoding::EncoderTrap::Strict)
.map_err(|e| Exceptions::format_with(e.to_string()))
input
.to_cp437(&CP437_CONTROL)
.map(|data| data.to_vec())
.map_err(|e| Exceptions::format_with(format!("{e:?}")))
} else {
self.get_base_encoder()
.encode(input, encoding::EncoderTrap::Strict)
.map_err(|e| Exceptions::format_with(e.to_string()))
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/common/eci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Display;

use super::CharacterSet;

#[derive(Copy,Clone,Debug,PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Eci {
Unknown = -1,
Cp437 = 2, // obsolete
Expand Down Expand Up @@ -126,9 +126,9 @@ impl From<CharacterSet> for Eci {
CharacterSet::ISO8859_6 => Eci::ISO8859_6,
CharacterSet::ISO8859_8 => Eci::ISO8859_8,
CharacterSet::ISO8859_10 => Eci::ISO8859_10,
CharacterSet::ISO8859_11 =>Eci::ISO8859_11,
CharacterSet::ISO8859_11 => Eci::ISO8859_11,
CharacterSet::ISO8859_14 => Eci::ISO8859_14,
_=>Eci::Unknown,
_ => Eci::Unknown,
}
}
}
Expand Down Expand Up @@ -176,6 +176,6 @@ impl From<Eci> for CharacterSet {

impl Display for Eci {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"{}", *self as i32)
write!(f, "{}", *self as i32)
}
}
}
6 changes: 4 additions & 2 deletions src/datamatrix/decoder/decoded_bit_stream_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

use crate::{
common::{BitSource, CharacterSet, DecoderRXingResult, ECIStringBuilder, Result, Eci},
common::{BitSource, CharacterSet, DecoderRXingResult, ECIStringBuilder, Eci, Result},
Exceptions,
};

Expand Down Expand Up @@ -751,7 +751,9 @@ fn decodeECISegment(bits: &mut BitSource, result: &mut ECIStringBuilder) -> Resu

let thirdByte = bits.readBits(8)?;

result.appendECI(Eci::from((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1))?;
result.appendECI(Eci::from(
(firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1,
))?;
Ok((firstByte - 192) * 64516 + 16383 + (secondByte - 1) * 254 + thirdByte - 1 > 900)
}

Expand Down
2 changes: 1 addition & 1 deletion src/datamatrix/encoder/minimal_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::{fmt, rc::Rc};

use crate::{
common::{CharacterSet, ECIInput, MinimalECIInput, Result, Eci},
common::{CharacterSet, ECIInput, Eci, MinimalECIInput, Result},
Exceptions,
};

Expand Down
2 changes: 1 addition & 1 deletion src/pdf417/decoder/decoded_bit_stream_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use num::{self, bigint::ToBigUint, BigUint};
use std::rc::Rc;

use crate::{
common::{DecoderRXingResult, ECIStringBuilder, Result, Eci},
common::{DecoderRXingResult, ECIStringBuilder, Eci, Result},
pdf417::PDF417RXingResultMetadata,
Exceptions,
};
Expand Down
13 changes: 4 additions & 9 deletions src/pdf417/encoder/pdf_417_high_level_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use std::{any::TypeId, fmt::Display, str::FromStr};

use crate::{
common::{CharacterSet, ECIInput, MinimalECIInput, Result, Eci},
common::{CharacterSet, ECIInput, Eci, MinimalECIInput, Result},
Exceptions,
};

Expand Down Expand Up @@ -802,7 +802,7 @@ fn encodingECI(eci: Eci, sb: &mut String) -> Result<()> {
if (0..900).contains(&(eci as i32)) {
sb.push(char::from_u32(ECI_CHARSET).ok_or(Exceptions::PARSE)?);
sb.push(char::from_u32(eci as u32).ok_or(Exceptions::PARSE)?);
} else if (eci as i32 )< 810900 {
} else if (eci as i32) < 810900 {
sb.push(char::from_u32(ECI_GENERAL_PURPOSE).ok_or(Exceptions::PARSE)?);
sb.push(char::from_u32(((eci as i32) / 900 - 1) as u32).ok_or(Exceptions::PARSE)?);
sb.push(char::from_u32(((eci as i32) % 900) as u32).ok_or(Exceptions::PARSE)?);
Expand Down Expand Up @@ -908,13 +908,8 @@ mod PDF417EncoderTestCase {

#[test]
fn testEncodeNumeric() {
let encoded = encodeHighLevel(
"1234",
Compaction::NUMERIC,
Some(CharacterSet::UTF8),
false,
)
.expect("encode");
let encoded = encodeHighLevel("1234", Compaction::NUMERIC, Some(CharacterSet::UTF8), false)
.expect("encode");
assert_eq!("\u{039f}\u{001A}\u{0386}\u{C}\u{01b2}", encoded);
// converted \f to \u{0046}
}
Expand Down
4 changes: 2 additions & 2 deletions src/qrcode/decoder/decoded_bit_stream_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

use crate::{
common::{BitSource, CharacterSet, DecoderRXingResult, Result, StringUtils, Eci},
common::{BitSource, CharacterSet, DecoderRXingResult, Eci, Result, StringUtils},
DecodingHintDictionary, Exceptions,
};

Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn decode(
Mode::ECI => {
// Count doesn't apply to ECI
let value = parseECIValue(&mut bits)?;
currentCharacterSetECI = CharacterSet::from(Eci::from(value)).into();//CharacterSet::get_character_set_by_eci(value).ok();
currentCharacterSetECI = CharacterSet::from(Eci::from(value)).into(); //CharacterSet::get_character_set_by_eci(value).ok();
if currentCharacterSetECI.is_none() {
return Err(Exceptions::format_with(format!(
"Value of {value} not valid"
Expand Down
8 changes: 2 additions & 6 deletions src/qrcode/encoder/qrcode_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::{
common::{
reedsolomon::{get_predefined_genericgf, PredefinedGenericGF, ReedSolomonEncoder},
BitArray, CharacterSet, Result, Eci,
BitArray, CharacterSet, Eci, Result,
},
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions,
Expand Down Expand Up @@ -716,11 +716,7 @@ pub fn appendAlphanumericBytes(content: &str, bits: &mut BitArray) -> Result<()>
Ok(())
}

pub fn append8BitBytes(
content: &str,
bits: &mut BitArray,
encoding: CharacterSet,
) -> Result<()> {
pub fn append8BitBytes(content: &str, bits: &mut BitArray, encoding: CharacterSet) -> Result<()> {
let bytes = encoding
.encode(content)
.map_err(|e| Exceptions::writer_with(format!("error {e}")))?;
Expand Down

0 comments on commit 69c0119

Please sign in to comment.