diff --git a/src/aztec/EncoderTest.rs b/src/aztec/EncoderTest.rs index 00a5763..b69f38a 100644 --- a/src/aztec/EncoderTest.rs +++ b/src/aztec/EncoderTest.rs @@ -23,7 +23,8 @@ use crate::{ encoder::HighLevelEncoder, shared_test_methods::{stripSpace, toBitArray, toBooleanArray}, }, - BarcodeFormat, EncodeHintType, EncodeHintValue, Point, common::CharacterSetECI, + common::CharacterSetECI, + BarcodeFormat, EncodeHintType, EncodeHintValue, Point, }; use super::{encoder::aztec_encoder, AztecWriter}; @@ -137,8 +138,8 @@ X X X X X X X X X X X X X #[test] fn testAztecWriter() { let shift_jis: CharacterSetECI = - CharacterSetECI::getCharacterSetECIByName("Shift_JIS").expect("must exist"); - + CharacterSetECI::getCharacterSetECIByName("Shift_JIS").expect("must exist"); + testWriter("Espa\u{00F1}ol", None, 25, true, 1); // Without ECI (implicit ISO-8859-1) testWriter("Espa\u{00F1}ol", Some(ISO_8859_1), 25, true, 1); // Explicit ISO-8859-1 testWriter("\u{20AC} 1 sample data.", Some(WINDOWS_1252), 25, true, 2); // ISO-8859-1 can't encode Euro; Windows-1252 can @@ -817,7 +818,9 @@ fn testStuffBits(wordSize: usize, bits: &str, expected: &str) { fn testHighLevelEncodeStringUtf8(s: &str, expectedBits: &str) { let bits = HighLevelEncoder::with_charset( - CharacterSetECI::UTF8.encode(s).expect("should encode to bytes"), + CharacterSetECI::UTF8 + .encode(s) + .expect("should encode to bytes"), CharacterSetECI::UTF8, ) .encode() @@ -838,7 +841,9 @@ fn testHighLevelEncodeStringUtf8(s: &str, expectedBits: &str) { fn testHighLevelEncodeString(s: &str, expectedBits: &str) { let bits = HighLevelEncoder::new( - CharacterSetECI::ISO8859_1.encode(s).expect("should encode to bytes"), + CharacterSetECI::ISO8859_1 + .encode(s) + .expect("should encode to bytes"), ) .encode() .expect("high level ok"); @@ -857,7 +862,9 @@ fn testHighLevelEncodeString(s: &str, expectedBits: &str) { fn testHighLevelEncodeStringCount(s: &str, expectedReceivedBits: u32) { let bits = HighLevelEncoder::new( - CharacterSetECI::ISO8859_1.encode(s).expect("should encode to bytes"), + CharacterSetECI::ISO8859_1 + .encode(s) + .expect("should encode to bytes"), ) .encode() .expect("high level ok"); diff --git a/src/aztec/aztec_writer.rs b/src/aztec/aztec_writer.rs index 7bfa320..24f183a 100644 --- a/src/aztec/aztec_writer.rs +++ b/src/aztec/aztec_writer.rs @@ -17,7 +17,7 @@ use std::collections::HashMap; use crate::{ - common::{BitMatrix, Result, CharacterSetECI}, + common::{BitMatrix, CharacterSetECI, Result}, exceptions::Exceptions, BarcodeFormat, EncodeHintType, EncodeHintValue, Writer, }; diff --git a/src/aztec/decoder.rs b/src/aztec/decoder.rs index 14863fb..48cf998 100644 --- a/src/aztec/decoder.rs +++ b/src/aztec/decoder.rs @@ -113,7 +113,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result { // Intermediary buffer of decoded bytes, which is decoded into a string and flushed // when character encoding changes (ECI) or input ends. let mut decoded_bytes: Vec = Vec::new(); - + let mut encdr: CharacterSetECI = CharacterSetECI::ISO8859_1; let mut index = 0; @@ -159,10 +159,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result { let mut n = read_code(corrected_bits, index, 3); index += 3; // flush bytes, FLG changes state - result.push_str( - &encdr - .decode(&decoded_bytes)?, - ); + result.push_str(&encdr.decode(&decoded_bytes)?); decoded_bytes.clear(); match n { @@ -206,7 +203,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result { } } else { // Though stored as a table of strings for convenience, codes actually represent 1 or 2 *bytes*. - + let b = str.as_bytes(); //let b = str.getBytes(StandardCharsets.US_ASCII); //decodedBytes.write(b, 0, b.length); diff --git a/src/aztec/encoder/aztec_encoder.rs b/src/aztec/encoder/aztec_encoder.rs index 99e9265..cef5c04 100644 --- a/src/aztec/encoder/aztec_encoder.rs +++ b/src/aztec/encoder/aztec_encoder.rs @@ -19,7 +19,7 @@ use crate::{ reedsolomon::{ get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonEncoder, }, - BitArray, BitMatrix, Result, CharacterSetECI, + BitArray, BitMatrix, CharacterSetECI, Result, }, exceptions::Exceptions, }; diff --git a/src/aztec/encoder/high_level_encoder.rs b/src/aztec/encoder/high_level_encoder.rs index 3fa495a..29bf492 100644 --- a/src/aztec/encoder/high_level_encoder.rs +++ b/src/aztec/encoder/high_level_encoder.rs @@ -14,10 +14,7 @@ * limitations under the License. */ -use crate::{ - common::{BitArray, CharacterSetECI, Result}, - exceptions::Exceptions, -}; +use crate::common::{BitArray, CharacterSetECI, Result}; use super::{State, Token}; @@ -243,10 +240,10 @@ impl HighLevelEncoder { pub fn encode(&self) -> Result { let mut initial_state = State::new(Token::new(), Self::MODE_UPPER as u32, 0, 0); //if let Some(eci) = CharacterSetECI::getCharacterSetECI(self.charset) { - if self.charset != CharacterSetECI::ISO8859_1 { - //} && eci != CharacterSetECI::Cp1252 { - initial_state = initial_state.appendFLGn(self.charset.getValue())?; - } + if self.charset != CharacterSetECI::ISO8859_1 { + //} && eci != CharacterSetECI::Cp1252 { + initial_state = initial_state.appendFLGn(self.charset.getValue())?; + } // } else { // return Err(Exceptions::illegal_argument_with( // "No ECI code for character set", diff --git a/src/aztec/encoder/state.rs b/src/aztec/encoder/state.rs index 1a20425..73150a7 100644 --- a/src/aztec/encoder/state.rs +++ b/src/aztec/encoder/state.rs @@ -17,7 +17,7 @@ use std::fmt; use crate::{ - common::{BitArray, Result, CharacterSetECI}, + common::{BitArray, CharacterSetECI, Result}, exceptions::Exceptions, }; diff --git a/src/client/result/VCardResultParser.rs b/src/client/result/VCardResultParser.rs index 290b95a..dd85017 100644 --- a/src/client/result/VCardResultParser.rs +++ b/src/client/result/VCardResultParser.rs @@ -20,7 +20,7 @@ use regex::Regex; use once_cell::sync::Lazy; -use crate::{RXingResult, common::CharacterSetECI}; +use crate::{common::CharacterSetECI, RXingResult}; use uriparse::URI; @@ -405,9 +405,7 @@ fn maybeAppendFragment(fragmentBuffer: &mut Vec, charset: &str, result: &mut fragment = String::from_utf8(fragmentBytes).unwrap_or_else(|_| String::default()); // fragment = new String(fragmentBytes, StandardCharsets.UTF_8); } else if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(charset) { - fragment = if let Ok(encoded_result) = - enc.decode(&fragmentBytes) - { + fragment = if let Ok(encoded_result) = enc.decode(&fragmentBytes) { encoded_result } else { String::from_utf8(fragmentBytes).unwrap_or_else(|_| String::default()) diff --git a/src/common/StringUtilsTestCase.rs b/src/common/StringUtilsTestCase.rs index 882ae3c..78cf3e0 100644 --- a/src/common/StringUtilsTestCase.rs +++ b/src/common/StringUtilsTestCase.rs @@ -40,19 +40,14 @@ fn test_random() { // } assert_eq!( CharacterSetECI::UTF8, - StringUtils::guessCharset(&bytes, &HashMap::new()) - .unwrap() + StringUtils::guessCharset(&bytes, &HashMap::new()).unwrap() ); } #[test] fn test_short_shift_jis1() { // 金魚 - do_test( - &[0x8b, 0xe0, 0x8b, 0x9b], - CharacterSetECI::SJIS, - "SJIS", - ); + do_test(&[0x8b, 0xe0, 0x8b, 0x9b], CharacterSetECI::SJIS, "SJIS"); } #[test] @@ -87,7 +82,7 @@ fn test_utf16_be() { do_test( &[0xFE, 0xFF, 0x8c, 0x03, 0x53, 0x8b, 0x67, 0xdc], CharacterSetECI::UnicodeBigUnmarked, - &CharacterSetECI::UnicodeBigUnmarked.getCharsetName(), + CharacterSetECI::UnicodeBigUnmarked.getCharsetName(), ); } @@ -97,7 +92,7 @@ fn test_utf16_le() { do_test( &[0xFF, 0xFE, 0x03, 0x8c, 0x8b, 0x53, 0xdc, 0x67], CharacterSetECI::UTF16LE, - &CharacterSetECI::UTF16LE.getCharsetName(), + CharacterSetECI::UTF16LE.getCharsetName(), ); } diff --git a/src/common/character_set_eci.rs b/src/common/character_set_eci.rs index 25af1fe..8dbeffe 100644 --- a/src/common/character_set_eci.rs +++ b/src/common/character_set_eci.rs @@ -17,7 +17,7 @@ use encoding::EncodingRef; use crate::common::Result; -use crate::{Exceptions}; +use crate::Exceptions; /** * Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1 @@ -51,11 +51,11 @@ pub enum CharacterSetECI { Cp1256, //(24, "windows-1256"), UnicodeBigUnmarked, //(25, "UTF-16BE", "UnicodeBig"), UTF16LE, - UTF8, //(26, "UTF-8"), - ASCII, //(new int[] {27, 170}, "US-ASCII"), - Big5, //(28), - GB18030, //(29, "GB2312", "EUC_CN", "GBK"), - EUC_KR, //(30, "EUC-KR"); + UTF8, //(26, "UTF-8"), + ASCII, //(new int[] {27, 170}, "US-ASCII"), + Big5, //(28), + GB18030, //(29, "GB2312", "EUC_CN", "GBK"), + EUC_KR, //(30, "EUC-KR"); } impl CharacterSetECI { // private static final Map VALUE_TO_ECI = new HashMap<>(); @@ -126,7 +126,7 @@ impl CharacterSetECI { } } - pub fn getCharset(&self, ) -> EncodingRef { + pub fn getCharset(&self) -> EncodingRef { let name = match self { // CharacterSetECI::Cp437 => "CP437", CharacterSetECI::Cp437 => "cp437", @@ -161,8 +161,8 @@ impl CharacterSetECI { encoding::label::encoding_from_whatwg_label(name).unwrap() } - pub fn getCharsetName(&self, ) -> &'static str { - match self { + pub fn getCharsetName(&self) -> &'static str { + match self { // CharacterSetECI::Cp437 => "CP437", CharacterSetECI::Cp437 => "cp437", CharacterSetECI::ISO8859_1 => "iso-8859-1", @@ -193,7 +193,6 @@ impl CharacterSetECI { CharacterSetECI::GB18030 => "gb2312", CharacterSetECI::EUC_KR => "euc-kr", } - } /** @@ -317,25 +316,33 @@ impl CharacterSetECI { } pub fn encode(&self, input: &str) -> Result> { - self.getCharset().encode(input, encoding::EncoderTrap::Strict).map_err(|e| Exceptions::format_with(e.to_string())) + self.getCharset() + .encode(input, encoding::EncoderTrap::Strict) + .map_err(|e| Exceptions::format_with(e.to_string())) } pub fn encode_replace(&self, input: &str) -> Result> { - self.getCharset().encode(input, encoding::EncoderTrap::Replace).map_err(|e| Exceptions::format_with(e.to_string())) + self.getCharset() + .encode(input, encoding::EncoderTrap::Replace) + .map_err(|e| Exceptions::format_with(e.to_string())) } - pub fn decode(&self, input:&[u8]) -> Result { + pub fn decode(&self, input: &[u8]) -> Result { if self == &CharacterSetECI::Cp437 { use codepage_437::BorrowFromCp437; use codepage_437::CP437_CONTROL; Ok(String::borrow_from_cp437(&input, &CP437_CONTROL)) - }else { - self.getCharset().decode(input, encoding::DecoderTrap::Strict).map_err(|e| Exceptions::format_with(e.to_string())) + } else { + self.getCharset() + .decode(input, encoding::DecoderTrap::Strict) + .map_err(|e| Exceptions::format_with(e.to_string())) } } - pub fn decode_replace(&self, input:&[u8]) -> Result { - self.getCharset().decode(input, encoding::DecoderTrap::Replace).map_err(|e| Exceptions::format_with(e.to_string())) + pub fn decode_replace(&self, input: &[u8]) -> Result { + self.getCharset() + .decode(input, encoding::DecoderTrap::Replace) + .map_err(|e| Exceptions::format_with(e.to_string())) } } diff --git a/src/common/eci_encoder_set.rs b/src/common/eci_encoder_set.rs index 0b4d9a9..c5dcf14 100644 --- a/src/common/eci_encoder_set.rs +++ b/src/common/eci_encoder_set.rs @@ -112,9 +112,7 @@ impl ECIEncoderSet { for encoder in &neededEncoders { // for (CharsetEncoder encoder : neededEncoders) { let c = stringToEncode.get(i).unwrap(); - if (fnc1.is_some() && c == fnc1.as_ref().unwrap()) - || encoder.encode(c).is_ok() - { + if (fnc1.is_some() && c == fnc1.as_ref().unwrap()) || encoder.encode(c).is_ok() { canEncode = true; break; } @@ -125,12 +123,7 @@ impl ECIEncoderSet { // for encoder in ENCODERS { let encoder = ENCODERS.get(i_encoder).unwrap(); // for (CharsetEncoder encoder : ENCODERS) { - if encoder - .encode( - stringToEncode.get(i).unwrap() - ) - .is_ok() - { + if encoder.encode(stringToEncode.get(i).unwrap()).is_ok() { //Good, we found an encoder that can encode the character. We add him to the list and continue scanning //the input neededEncoders.push(*encoder); diff --git a/src/common/eci_string_builder.rs b/src/common/eci_string_builder.rs index 7491b96..e06fdff 100644 --- a/src/common/eci_string_builder.rs +++ b/src/common/eci_string_builder.rs @@ -136,9 +136,7 @@ impl ECIStringBuilder { } else if !self.current_bytes.is_empty() { let bytes = std::mem::take(&mut self.current_bytes); self.current_bytes.clear(); - let encoded_value = encoder - .decode(&bytes) - .unwrap(); + let encoded_value = encoder.decode(&bytes).unwrap(); self.result.push_str(&encoded_value); } } else { diff --git a/src/common/minimal_eci_input.rs b/src/common/minimal_eci_input.rs index 51e586d..f7c80bd 100644 --- a/src/common/minimal_eci_input.rs +++ b/src/common/minimal_eci_input.rs @@ -21,7 +21,7 @@ use unicode_segmentation::UnicodeSegmentation; use crate::common::Result; use crate::Exceptions; -use super::{ECIEncoderSet, ECIInput, CharacterSetECI}; +use super::{CharacterSetECI, ECIEncoderSet, ECIInput}; //* approximated (latch + 2 codewords) pub const COST_PER_ECI: usize = 3; diff --git a/src/common/string_utils.rs b/src/common/string_utils.rs index f601c50..2d2f623 100644 --- a/src/common/string_utils.rs +++ b/src/common/string_utils.rs @@ -16,8 +16,6 @@ use crate::{DecodeHintType, DecodeHintValue, DecodingHintDictionary}; -use once_cell::sync::Lazy; - use super::CharacterSetECI; /** @@ -50,8 +48,7 @@ const ASSUME_SHIFT_JIS: bool = false; // static SHIFT_JIS: &'static str = "SJIS"; // static GB2312: &'static str = "GB2312"; -pub static SHIFT_JIS_CHARSET: CharacterSetECI = - CharacterSetECI::SJIS; +pub static SHIFT_JIS_CHARSET: CharacterSetECI = CharacterSetECI::SJIS; // private static final boolean ASSUME_SHIFT_JIS = // SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) || @@ -74,7 +71,7 @@ impl StringUtils { } else if c == CharacterSetECI::ISO8859_1 { Some("ISO8859_1") } else { - Some(&c.getCharsetName()) + Some(c.getCharsetName()) } } @@ -92,7 +89,7 @@ impl StringUtils { hints.get(&DecodeHintType::CHARACTER_SET) { // if let DecodeHintValue::CharacterSet(cs_name) = hint { - return CharacterSetECI::getCharacterSetECIByName(cs_name) + return CharacterSetECI::getCharacterSetECIByName(cs_name); // } } // if hints.contains_key(&DecodeHintType::CHARACTER_SET) { @@ -260,6 +257,6 @@ impl StringUtils { return Some(CharacterSetECI::UTF8); } // Otherwise, we take a wild guess with platform encoding - Some(CharacterSetECI::UTF8) + Some(CharacterSetECI::UTF8) } } diff --git a/src/datamatrix/data_matrix_writer.rs b/src/datamatrix/data_matrix_writer.rs index 4409fb4..708f810 100644 --- a/src/datamatrix/data_matrix_writer.rs +++ b/src/datamatrix/data_matrix_writer.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use crate::{ - common::{BitMatrix, Result, CharacterSetECI}, + common::{BitMatrix, CharacterSetECI, Result}, qrcode::encoder::ByteMatrix, BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer, }; @@ -122,7 +122,8 @@ impl Writer for DataMatrixWriter { hints.get(&EncodeHintType::CHARACTER_SET) else { return Err(Exceptions::illegal_argument_with("charset does not exist")) }; - charset = CharacterSetECI::getCharacterSetECIByName(char_set_name);//encoding::label::encoding_from_whatwg_label(char_set_name); + charset = CharacterSetECI::getCharacterSetECIByName(char_set_name); + //encoding::label::encoding_from_whatwg_label(char_set_name); // charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString()); } encoded = minimal_encoder::encodeHighLevelWithDetails( diff --git a/src/datamatrix/decoder/decoded_bit_stream_parser.rs b/src/datamatrix/decoder/decoded_bit_stream_parser.rs index 9048601..786f062 100644 --- a/src/datamatrix/decoder/decoded_bit_stream_parser.rs +++ b/src/datamatrix/decoder/decoded_bit_stream_parser.rs @@ -15,7 +15,7 @@ */ use crate::{ - common::{BitSource, DecoderRXingResult, ECIStringBuilder, Result, CharacterSetECI}, + common::{BitSource, CharacterSetECI, DecoderRXingResult, ECIStringBuilder, Result}, Exceptions, }; @@ -727,12 +727,7 @@ fn decodeBase256Segment( *byte = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8; codewordPosition += 1; } - result.append_string( - - &CharacterSetECI::ISO8859_1 - .decode(&bytes) - ?, - ); + result.append_string(&CharacterSetECI::ISO8859_1.decode(&bytes)?); byteSegments.push(bytes); Ok(()) diff --git a/src/datamatrix/encoder/encoder_context.rs b/src/datamatrix/encoder/encoder_context.rs index 121ec92..9b19fb7 100644 --- a/src/datamatrix/encoder/encoder_context.rs +++ b/src/datamatrix/encoder/encoder_context.rs @@ -16,7 +16,7 @@ use std::rc::Rc; -use crate::common::{Result, CharacterSetECI}; +use crate::common::{CharacterSetECI, Result}; use crate::{Dimension, Exceptions}; use super::{SymbolInfo, SymbolInfoLookup, SymbolShapeHint}; @@ -57,14 +57,10 @@ impl<'a> EncoderContext<'_> { // } // sb.append(ch); // } - let sb = if let Ok(encoded_bytes) = - ISO_8859_1_ENCODER.encode(msg) - { - ISO_8859_1_ENCODER - .decode(&encoded_bytes) - .map_err(|e| { - Exceptions::parse_with(format!("round trip decode should always work: {e}")) - })? + let sb = if let Ok(encoded_bytes) = ISO_8859_1_ENCODER.encode(msg) { + ISO_8859_1_ENCODER.decode(&encoded_bytes).map_err(|e| { + Exceptions::parse_with(format!("round trip decode should always work: {e}")) + })? } else { return Err(Exceptions::illegal_argument_with( "Message contains characters outside ISO-8859-1 encoding.", diff --git a/src/datamatrix/encoder/high_level_encode_test_case.rs b/src/datamatrix/encoder/high_level_encode_test_case.rs index f8c1244..09895b5 100644 --- a/src/datamatrix/encoder/high_level_encode_test_case.rs +++ b/src/datamatrix/encoder/high_level_encode_test_case.rs @@ -18,7 +18,10 @@ use std::rc::Rc; use once_cell::sync::Lazy; -use crate::{datamatrix::encoder::{SymbolInfo, SymbolShapeHint}, common::CharacterSetECI}; +use crate::{ + common::CharacterSetECI, + datamatrix::encoder::{SymbolInfo, SymbolShapeHint}, +}; use super::{high_level_encoder, minimal_encoder, symbol_info, SymbolInfoLookup}; diff --git a/src/datamatrix/encoder/high_level_encoder.rs b/src/datamatrix/encoder/high_level_encoder.rs index 5606d7e..a0dd06b 100644 --- a/src/datamatrix/encoder/high_level_encoder.rs +++ b/src/datamatrix/encoder/high_level_encoder.rs @@ -16,7 +16,7 @@ use std::rc::Rc; -use crate::common::{Result, CharacterSetECI}; +use crate::common::{CharacterSetECI, Result}; use crate::{Dimension, Exceptions}; use super::{ diff --git a/src/datamatrix/encoder/minimal_encoder.rs b/src/datamatrix/encoder/minimal_encoder.rs index 1d5dd06..3cf89b2 100755 --- a/src/datamatrix/encoder/minimal_encoder.rs +++ b/src/datamatrix/encoder/minimal_encoder.rs @@ -17,7 +17,7 @@ use std::{fmt, rc::Rc}; use crate::{ - common::{ECIInput, MinimalECIInput, Result, CharacterSetECI}, + common::{CharacterSetECI, ECIInput, MinimalECIInput, Result}, Exceptions, }; @@ -171,10 +171,7 @@ pub fn encodeHighLevelWithDetails( msg = &msg[high_level_encoder::MACRO_06_HEADER.chars().count()..(msg.chars().count() - 2)]; } Ok(ISO_8859_1_ENCODER - .decode( - &encode(msg, priorityCharset, fnc1, shape, macroId)? - - ) + .decode(&encode(msg, priorityCharset, fnc1, shape, macroId)?) .expect("should decode")) // return new String(encode(msg, priorityCharset, fnc1, shape, macroId), StandardCharsets.ISO_8859_1); } diff --git a/src/pdf417/encoder/pdf_417.rs b/src/pdf417/encoder/pdf_417.rs index 3ee462b..070f59d 100644 --- a/src/pdf417/encoder/pdf_417.rs +++ b/src/pdf417/encoder/pdf_417.rs @@ -18,7 +18,7 @@ * This file has been modified from its original form in Barcode4J. */ -use crate::common::{Result, CharacterSetECI}; +use crate::common::{CharacterSetECI, Result}; use crate::Exceptions; use super::{ diff --git a/src/pdf417/encoder/pdf_417_high_level_encoder.rs b/src/pdf417/encoder/pdf_417_high_level_encoder.rs index 7aef5f5..dd9717d 100644 --- a/src/pdf417/encoder/pdf_417_high_level_encoder.rs +++ b/src/pdf417/encoder/pdf_417_high_level_encoder.rs @@ -197,16 +197,17 @@ pub fn encodeHighLevel( input = Box::new(NoECIInput::new(msg.to_owned())); if encoding.is_none() { encoding = Some(DEFAULT_ENCODING); - } else if &DEFAULT_ENCODING - != encoding.as_ref().ok_or(Exceptions::ILLEGAL_STATE)? - { + } else if &DEFAULT_ENCODING != encoding.as_ref().ok_or(Exceptions::ILLEGAL_STATE)? { // if let Some(eci) = // CharacterSetECI::getCharacterSetECI(encoding.ok_or(Exceptions::ILLEGAL_STATE)?) // { // encodingECI(CharacterSetECI::getValue(&eci) as i32, &mut sb)?; // } - encodingECI(CharacterSetECI::getValue(&encoding.ok_or(Exceptions::ILLEGAL_STATE)?) as i32, &mut sb)?; + encodingECI( + CharacterSetECI::getValue(&encoding.ok_or(Exceptions::ILLEGAL_STATE)?) as i32, + &mut sb, + )?; } } @@ -778,12 +779,7 @@ fn determineConsecutiveBinaryCount( } if let Some(encoder) = encoding { - let can_encode = encoder - .encode( - &input.charAt(idx)?.to_string() - - ) - .is_ok(); + let can_encode = encoder.encode(&input.charAt(idx)?.to_string()).is_ok(); if !can_encode { if TypeId::of::() != TypeId::of::() { @@ -866,7 +862,10 @@ impl Display for NoECIInput { */ #[cfg(test)] mod PDF417EncoderTestCase { - use crate::{pdf417::encoder::{pdf_417_high_level_encoder::encodeHighLevel, Compaction}, common::CharacterSetECI}; + use crate::{ + common::CharacterSetECI, + pdf417::encoder::{pdf_417_high_level_encoder::encodeHighLevel, Compaction}, + }; #[test] fn testEncodeAuto() { diff --git a/src/pdf417/encoder/pdf_417_high_level_encoder_test_adapter.rs b/src/pdf417/encoder/pdf_417_high_level_encoder_test_adapter.rs index ee37383..7554081 100644 --- a/src/pdf417/encoder/pdf_417_high_level_encoder_test_adapter.rs +++ b/src/pdf417/encoder/pdf_417_high_level_encoder_test_adapter.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use crate::common::{Result, CharacterSetECI}; +use crate::common::{CharacterSetECI, Result}; use super::{pdf_417_high_level_encoder, Compaction}; diff --git a/src/pdf417/pdf_417_writer.rs b/src/pdf417/pdf_417_writer.rs index 9f81929..77510c4 100644 --- a/src/pdf417/pdf_417_writer.rs +++ b/src/pdf417/pdf_417_writer.rs @@ -17,7 +17,7 @@ use std::collections::HashMap; use crate::{ - common::{BitMatrix, Result, CharacterSetECI}, + common::{BitMatrix, CharacterSetECI, Result}, BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer, }; diff --git a/src/qrcode/decoder/decoded_bit_stream_parser.rs b/src/qrcode/decoder/decoded_bit_stream_parser.rs index f84dbd5..b8682c8 100644 --- a/src/qrcode/decoder/decoded_bit_stream_parser.rs +++ b/src/qrcode/decoder/decoded_bit_stream_parser.rs @@ -203,8 +203,7 @@ fn decodeHanziSegment(bits: &mut BitSource, result: &mut String, count: usize) - count -= 1; } - let gb_encoder = - CharacterSetECI::GB18030; + let gb_encoder = CharacterSetECI::GB18030; let encode_string = gb_encoder .decode(&buffer) .map_err(|e| Exceptions::parse_with(format!("unable to decode buffer {buffer:?}: {e}")))?; @@ -321,13 +320,9 @@ fn decodeByteSegment( // ) }; - let encode_string = - encoding - .decode(&readBytes) - .map_err(|e| { - Exceptions::parse_with(format!("unable to decode buffer {readBytes:?}: {e}")) - })? - ; + let encode_string = encoding.decode(&readBytes).map_err(|e| { + Exceptions::parse_with(format!("unable to decode buffer {readBytes:?}: {e}")) + })?; result.push_str(&encode_string); byteSegments.push(readBytes); diff --git a/src/qrcode/encoder/EncoderTestCase.rs b/src/qrcode/encoder/EncoderTestCase.rs index 13a754e..abcfe6b 100644 --- a/src/qrcode/encoder/EncoderTestCase.rs +++ b/src/qrcode/encoder/EncoderTestCase.rs @@ -28,8 +28,7 @@ use once_cell::sync::Lazy; use super::QRCode; -static SHIFT_JIS_CHARSET: Lazy = - Lazy::new(|| CharacterSetECI::SJIS); +static SHIFT_JIS_CHARSET: Lazy = Lazy::new(|| CharacterSetECI::SJIS); /** * @author satorux@google.com (Satoru Takabayashi) - creator diff --git a/src/qrcode/encoder/minimal_encoder.rs b/src/qrcode/encoder/minimal_encoder.rs index 1c03bdf..703ffec 100644 --- a/src/qrcode/encoder/minimal_encoder.rs +++ b/src/qrcode/encoder/minimal_encoder.rs @@ -17,7 +17,7 @@ use std::{fmt, rc::Rc}; use crate::{ - common::{BitArray, ECIEncoderSet, Result, CharacterSetECI}, + common::{BitArray, CharacterSetECI, ECIEncoderSet, Result}, qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef}, Exceptions, }; @@ -1042,7 +1042,7 @@ impl fmt::Display for RXingResultNode { result.push('('); if self.mode == Mode::ECI { result.push_str( - &self.encoders + self.encoders .getCharset(self.charsetEncoderIndex) .ok_or(fmt::Error)? .getCharsetName(), diff --git a/src/qrcode/encoder/qrcode_encoder.rs b/src/qrcode/encoder/qrcode_encoder.rs index abfdaad..753290d 100644 --- a/src/qrcode/encoder/qrcode_encoder.rs +++ b/src/qrcode/encoder/qrcode_encoder.rs @@ -32,8 +32,7 @@ use crate::{ use super::{mask_util, matrix_util, BlockPair, ByteMatrix, MinimalEncoder, QRCode}; -static SHIFT_JIS_CHARSET: CharacterSetECI = - CharacterSetECI::SJIS; +static SHIFT_JIS_CHARSET: CharacterSetECI = CharacterSetECI::SJIS; // The original table is defined in the table 5 of JISX0510:2004 (p.19). const ALPHANUMERIC_TABLE: [i8; 96] = [ @@ -97,8 +96,7 @@ pub fn encode_with_hints( let mut has_encoding_hint = hints.contains_key(&EncodeHintType::CHARACTER_SET); if has_encoding_hint { if let Some(EncodeHintValue::CharacterSet(v)) = hints.get(&EncodeHintType::CHARACTER_SET) { - encoding = - Some(CharacterSetECI::getCharacterSetECIByName(v).ok_or(Exceptions::WRITER)?) + encoding = Some(CharacterSetECI::getCharacterSetECIByName(v).ok_or(Exceptions::WRITER)?) } } @@ -122,9 +120,7 @@ pub fn encode_with_hints( //Switch to default encoding let encoding = if let Some(encoding) = encoding { encoding - } else if let Ok(_encs) = - DEFAULT_BYTE_MODE_ENCODING.encode(content) - { + } else if let Ok(_encs) = DEFAULT_BYTE_MODE_ENCODING.encode(content) { DEFAULT_BYTE_MODE_ENCODING } else { has_encoding_hint = true; @@ -720,7 +716,11 @@ pub fn appendAlphanumericBytes(content: &str, bits: &mut BitArray) -> Result<()> Ok(()) } -pub fn append8BitBytes(content: &str, bits: &mut BitArray, encoding: CharacterSetECI) -> Result<()> { +pub fn append8BitBytes( + content: &str, + bits: &mut BitArray, + encoding: CharacterSetECI, +) -> Result<()> { let bytes = encoding .encode(content) .map_err(|e| Exceptions::writer_with(format!("error {e}")))?; diff --git a/tests/common/pdf_417_multiimage_span.rs b/tests/common/pdf_417_multiimage_span.rs index a0a00ea..5c7d465 100644 --- a/tests/common/pdf_417_multiimage_span.rs +++ b/tests/common/pdf_417_multiimage_span.rs @@ -24,7 +24,7 @@ use std::{ }; use rxing::{ - common::{HybridBinarizer, Result, CharacterSetECI}, + common::{CharacterSetECI, HybridBinarizer, Result}, multi::MultipleBarcodeReader, pdf417::PDF417RXingResultMetadata, BarcodeFormat, Binarizer, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType, @@ -644,7 +644,9 @@ impl PDF417MultiImageSpanAbstractBlackBoxTest if ext == "bin" { let mut buffer: Vec = Vec::new(); File::open(&file)?.read_to_end(&mut buffer)?; - CharacterSetECI::ISO8859_1.decode_replace(&buffer).expect("decode") + CharacterSetECI::ISO8859_1 + .decode_replace(&buffer) + .expect("decode") } else { read_to_string(&file).expect("ok") }