cargo clippy --fix

This commit is contained in:
Henry Schimke
2023-01-27 15:24:24 -06:00
parent 58e6827e89
commit 42d40de755
86 changed files with 196 additions and 335 deletions

View File

@@ -77,8 +77,7 @@ fn test_high_level_decode_string(expectedString: &str, b: &str) {
assert_eq!(
expectedString,
decoder::highLevelDecode(&toBooleanArray(&bits)).expect("highLevelDecode Failed"),
"highLevelDecode() failed for input bits: {}",
b
"highLevelDecode() failed for input bits: {b}"
);
}

View File

@@ -64,7 +64,7 @@ fn test_error_in_parameter_locator_compact() {
#[test]
fn test_error_in_parameter_locator_not_compact() {
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz";
test_error_in_parameter_locator(&format!("{}{}{}", alphabet, alphabet, alphabet));
test_error_in_parameter_locator(&format!("{alphabet}{alphabet}{alphabet}"));
}
#[test]
@@ -165,7 +165,7 @@ fn test_error_in_parameter_locator(data: &str) {
if let Exceptions::NotFoundException(_msg) = res {
// all ok
} else {
panic!("Only Exceptions::NotFoundException allowed, got {}", res);
panic!("Only Exceptions::NotFoundException allowed, got {res}");
}
} else {
let r = Detector::new(&make_larger(&copy, 3)).detect(false);

View File

@@ -617,7 +617,7 @@ fn testBorderCompact4CaseFailed() {
// be error correction
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// encodes as 26 * 5 * 4 = 520 bits of data
let alphabet4 = format!("{}{}{}{}", alphabet, alphabet, alphabet, alphabet);
let alphabet4 = format!("{alphabet}{alphabet}{alphabet}{alphabet}");
aztec_encoder::encode(&alphabet4, 0, -4).expect("encode");
}
@@ -627,7 +627,7 @@ fn testBorderCompact4Case() {
// be error correction
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// encodes as 26 * 5 * 4 = 520 bits of data
let alphabet4 = format!("{}{}{}{}", alphabet, alphabet, alphabet, alphabet);
let alphabet4 = format!("{alphabet}{alphabet}{alphabet}{alphabet}");
// If we just try to encode it normally, it will go to a non-compact 4 layer
let mut aztecCode = aztec_encoder::encode(&alphabet4, 0, aztec_encoder::DEFAULT_AZTEC_LAYERS)
@@ -658,7 +658,7 @@ fn testEncode(data: &str, compact: bool, layers: u32, expected: &str) {
// let mut xored = BitMatrix::parse_strings(&stripSpace(expected), "X ", " ").expect("should parse");
// xored.xor(matrix).expect("should xor");
assert_eq!(expected, matrix.to_string(), "encode({}) failed", data);
assert_eq!(expected, matrix.to_string(), "encode({data}) failed");
}
fn testEncodeDecode(data: &str, compact: bool, layers: u32) {
@@ -814,8 +814,7 @@ fn testStuffBits(wordSize: usize, bits: &str, expected: &str) {
assert_eq!(
stripSpace(expected),
stripSpace(&stuffed.to_string()),
"stuffBits() failed for input string: {}",
bits
"stuffBits() failed for input string: {bits}"
);
}
@@ -838,8 +837,7 @@ fn testHighLevelEncodeStringUtf8(s: &str, expectedBits: &str) {
assert_eq!(
stripSpace(expectedBits),
receivedBits,
"highLevelEncode() failed for input string: {}",
s
"highLevelEncode() failed for input string: {s}"
);
}
@@ -856,8 +854,7 @@ fn testHighLevelEncodeString(s: &str, expectedBits: &str) {
assert_eq!(
stripSpace(expectedBits),
receivedBits,
"highLevelEncode() failed for input string: {}",
s
"highLevelEncode() failed for input string: {s}"
);
assert_eq!(
s,
@@ -888,7 +885,6 @@ fn testHighLevelEncodeStringCount(s: &str, expectedReceivedBits: u32) {
// );
assert_eq!(
expectedReceivedBits as usize, receivedBitCount,
"highLevelEncode() failed for input string: {} with byte count ({}!={})",
s, expectedReceivedBits, receivedBitCount
"highLevelEncode() failed for input string: {s} with byte count ({expectedReceivedBits}!={receivedBitCount})"
);
}

View File

@@ -107,8 +107,7 @@ fn encode(
) -> Result<BitMatrix, Exceptions> {
if format != BarcodeFormat::AZTEC {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"can only encode AZTEC, but got {:?}",
format
"can only encode AZTEC, but got {format:?}"
))));
}
let aztec = if let Some(cset) = charset {

View File

@@ -350,8 +350,7 @@ fn correct_bits(
let num_codewords = rawbits.len() / codeword_size;
if num_codewords < num_data_codewords as usize {
return Err(Exceptions::FormatException(Some(format!(
"numCodewords {}< numDataCodewords{}",
num_codewords, num_data_codewords
"numCodewords {num_codewords}< numDataCodewords{num_data_codewords}"
))));
}
let mut offset = rawbits.len() % codeword_size;

View File

@@ -53,7 +53,7 @@ pub const WORD_SIZE: [u32; 33] = [
pub fn encode_simple(data: &str) -> Result<AztecCode, Exceptions> {
let Ok(bytes) = encoding::all::ISO_8859_1
.encode(data, encoding::EncoderTrap::Replace) else {
return Err(Exceptions::IllegalArgumentException(Some(format!("'{}' cannot be encoded as ISO_8859_1", data))));
return Err(Exceptions::IllegalArgumentException(Some(format!("'{data}' cannot be encoded as ISO_8859_1"))));
};
encode_bytes_simple(&bytes)
}
@@ -76,8 +76,7 @@ pub fn encode(
encode_bytes(&bytes, minECCPercent, userSpecifiedLayers)
} else {
Err(Exceptions::IllegalArgumentException(Some(format!(
"'{}' cannot be encoded as ISO_8859_1",
data
"'{data}' cannot be encoded as ISO_8859_1"
))))
}
}
@@ -104,8 +103,7 @@ pub fn encode_with_charset(
encode_bytes_with_charset(&bytes, minECCPercent, userSpecifiedLayers, charset)
} else {
Err(Exceptions::IllegalArgumentException(Some(format!(
"'{}' cannot be encoded as ISO_8859_1",
data
"'{data}' cannot be encoded as ISO_8859_1"
))))
}
}
@@ -181,8 +179,7 @@ pub fn encode_bytes_with_charset(
})
{
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Illegal value {} for layers",
user_specified_layers
"Illegal value {user_specified_layers} for layers"
))));
}
total_bits_in_layer_var = total_bits_in_layer(layers, compact);
@@ -498,8 +495,7 @@ fn getGF(wordSize: usize) -> Result<GenericGFRef, Exceptions> {
10 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData10)),
12 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData12)),
_ => Err(Exceptions::IllegalArgumentException(Some(format!(
"Unsupported word size {}",
wordSize
"Unsupported word size {wordSize}"
)))),
}
// switch (wordSize) {

View File

@@ -86,7 +86,7 @@ impl State {
// throw new IllegalArgumentException("ECI code must be between 0 and 999999");
} else {
let eci_digits = encoding::all::ISO_8859_1
.encode(&format!("{}", eci), encoding::EncoderTrap::Strict)
.encode(&format!("{eci}"), encoding::EncoderTrap::Strict)
.unwrap();
// let eciDigits = Integer.toString(eci).getBytes(StandardCharsets.ISO_8859_1);
token.add(eci_digits.len() as i32, 3); // 1-6: number of ECI digits

View File

@@ -89,7 +89,7 @@ fn matchMultipleValuePrefix(prefix: &str, rawText: &str) -> Vec<String> {
for i in 1..=3 {
// for (int i = 1; i <= 3; i++) {
let value = ResultParser::matchSinglePrefixedField(
&format!("{}{}:", prefix, i),
&format!("{prefix}{i}:"),
rawText,
'\r',
true,

View File

@@ -123,6 +123,6 @@ fn buildName(firstName: &str, lastName: &str) -> String {
} else if lastName.is_empty() {
firstName.to_owned()
} else {
format!("{} {}", firstName, lastName)
format!("{firstName} {lastName}")
}
}

View File

@@ -196,8 +196,7 @@ impl CalendarParsedRXingResult {
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%SZ") {
Ok(dtm) => Ok(dtm.with_timezone(&Utc).timestamp()),
Err(e) => Err(Exceptions::ParseException(Some(format!(
"couldn't parse string: {}",
e
"couldn't parse string: {e}"
)))),
};
// let dtm = DateTime::parse_from_str(&when, "%Y%m%dT%H%M%S").unwrap().with_timezone(&Utc);
@@ -219,16 +218,14 @@ impl CalendarParsedRXingResult {
Ok(time_zone) => time_zone,
Err(e) => {
return Err(Exceptions::ParseException(Some(format!(
"couldn't parse timezone '{}': {}",
tz_part, e
"couldn't parse timezone '{tz_part}': {e}"
))))
}
};
return match Utc.datetime_from_str(time_part, "%Y%m%dT%H%M%S") {
Ok(dtm) => Ok(dtm.with_timezone(&tz_parsed).timestamp()),
Err(e) => Err(Exceptions::ParseException(Some(format!(
"couldn't parse string: {}",
e
"couldn't parse string: {e}"
)))),
};
}
@@ -238,8 +235,7 @@ impl CalendarParsedRXingResult {
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%S") {
Ok(dtm) => Ok(dtm.timestamp()),
Err(e) => Err(Exceptions::ParseException(Some(format!(
"couldn't parse local time: {}",
e
"couldn't parse local time: {e}"
)))),
};
}
@@ -300,8 +296,7 @@ impl CalendarParsedRXingResult {
Ok(dtm.timestamp())
} else {
Err(Exceptions::ParseException(Some(format!(
"Couldn't parse {}",
dateTimeString
"Couldn't parse {dateTimeString}"
))))
}
// DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);

View File

@@ -78,7 +78,7 @@ fn testRSSExpanded() {
let ev = epr_res.getUncommonAIs().get(k).unwrap();
assert_eq!(v, ev);
} else {
panic!("key not found {}", k)
panic!("key not found {k}")
}
}
// assert_eq!(&uncommonAIs, epr_res.getUncommonAIs());

View File

@@ -49,7 +49,7 @@ fn doTest(contents: &str, number: &str, title: &str) {
if let ParsedClientResult::TelResult(telRXingResult) = result {
assert_eq!(number, telRXingResult.getNumber());
assert_eq!(title, telRXingResult.getTitle());
assert_eq!(format!("tel:{}", number), telRXingResult.getTelURI());
assert_eq!(format!("tel:{number}"), telRXingResult.getTelURI());
} else {
panic!("wrong return type, expected TelResult");
}

View File

@@ -36,7 +36,7 @@ pub fn parse(theRXingResult: &crate::RXingResult) -> Option<ParsedClientResult>
}
// Normalize "TEL:" to "tel:"
let telURI = if let Some(stripped) = rawText.strip_prefix("TEL:") {
format!("tel:{}", stripped)
format!("tel:{stripped}")
} else {
rawText.clone()
};

View File

@@ -182,7 +182,7 @@ pub fn matchVCardPrefixedField(
// At start or after newline, match prefix, followed by optional metadata
// (led by ;) ultimately ending in colon
let matcher_primary = Regex::new(&format!("(?:^|\\n)(?i:{})(?:;([^:]*))?:", prefix)).unwrap();
let matcher_primary = Regex::new(&format!("(?:^|\\n)(?i:{prefix})(?:;([^:]*))?:")).unwrap();
// let matcher_primary = Regex::new(&format!("(?:^|\n){}(.*)", prefix)).unwrap();
//let lower_case_raw_text = rawText.to_lowercase();

View File

@@ -134,7 +134,7 @@ fn matchSingleVCardPrefixedField(prefix: &str, rawText: &str) -> String {
"".to_owned()
};
let root_time = values.last().unwrap().clone();
format!("{}{}", root_time, tz_mod)
format!("{root_time}{tz_mod}")
}
} else {
"".to_owned()

View File

@@ -45,12 +45,12 @@ fn test_get_next_set1() {
let array = BitArray::with_size(32);
for i in 0..array.getSize() {
// for (int i = 0; i < array.getSize(); i++) {
assert_eq!(32, array.getNextSet(i), "{}", i);
assert_eq!(32, array.getNextSet(i), "{i}");
}
let array = BitArray::with_size(33);
for i in 0..array.getSize() {
// for (int i = 0; i < array.getSize(); i++) {
assert_eq!(33, array.getNextSet(i), "{}", i);
assert_eq!(33, array.getNextSet(i), "{i}");
}
}
@@ -60,13 +60,13 @@ fn test_get_next_set2() {
array.set(31);
for i in 0..array.getSize() {
// for (int i = 0; i < array.getSize(); i++) {
assert_eq!(if i <= 31 { 31 } else { 33 }, array.getNextSet(i), "{}", i);
assert_eq!(if i <= 31 { 31 } else { 33 }, array.getNextSet(i), "{i}");
}
array = BitArray::with_size(33);
array.set(32);
for i in 0..array.getSize() {
// for (int i = 0; i < array.getSize(); i++) {
assert_eq!(32, array.getNextSet(i), "{}", i);
assert_eq!(32, array.getNextSet(i), "{i}");
}
}
@@ -85,7 +85,7 @@ fn test_get_next_set3() {
} else {
expected = 63;
}
assert_eq!(expected, array.getNextSet(i), "{}", i);
assert_eq!(expected, array.getNextSet(i), "{i}");
}
}
@@ -104,7 +104,7 @@ fn test_get_next_set4() {
} else {
expected = 63;
}
assert_eq!(expected, array.getNextSet(i), "{}", i);
assert_eq!(expected, array.getNextSet(i), "{i}");
}
}

View File

@@ -393,7 +393,7 @@ impl fmt::Display for BitArray {
}
_str.push_str(if self.get(i) { "X" } else { "." });
}
write!(f, "{}", _str)
write!(f, "{_str}")
}
}

View File

@@ -367,7 +367,7 @@ fn test_rotate_180(width: u32, height: u32) {
// for (int y = 0; y < height; y++) {
for x in 0..width {
// for (int x = 0; x < width; x++) {
assert_eq!(expected.get(x, y), input.get(x, y), "({},{})", x, y);
assert_eq!(expected.get(x, y), input.get(x, y), "({x},{y})");
}
}
}

View File

@@ -94,7 +94,7 @@ impl ECIStringBuilder {
* @param value int to append as a string
*/
pub fn append(&mut self, value: i32) {
self.append_string(&format!("{}", value));
self.append_string(&format!("{value}"));
}
/**

View File

@@ -79,8 +79,7 @@ impl ECIInput for MinimalECIInput {
}
if self.isECI(index as u32)? {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"value at {} is not a character but an ECI",
index
"value at {index} is not a character but an ECI"
))));
}
if self.isFNC1(index)? {
@@ -119,8 +118,7 @@ impl ECIInput for MinimalECIInput {
// for (int i = start; i < end; i++) {
if self.isECI(i as u32)? {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"value at {} is not a character but an ECI",
i
"value at {i} is not a character but an ECI"
))));
}
result.push_str(&self.charAt(i)?.to_string());
@@ -170,8 +168,7 @@ impl ECIInput for MinimalECIInput {
}
if !self.isECI(index as u32)? {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"value at {} is not an ECI but a character",
index
"value at {index} is not an ECI but a character"
))));
}
Ok((self.bytes[index] as u32 - 256) as i32)
@@ -352,7 +349,7 @@ impl MinimalECIInput {
}
}
if minimalJ < 0 {
panic!("internal error: failed to encode \"{}\"", stringToEncode);
panic!("internal error: failed to encode \"{stringToEncode}\"");
}
let mut intsAL: Vec<u16> = Vec::new();
let mut current = edges[inputLength][minimalJ as usize].clone();
@@ -508,6 +505,6 @@ impl fmt::Display for MinimalECIInput {
result.push(self.charAt(i).unwrap());
}
}
write!(f, "{}", result)
write!(f, "{result}")
}
}

View File

@@ -398,13 +398,11 @@ public static void corrupt(int[] received, int howMany, Random random, int max)
fn test_encode_decode_random(field: GenericGFRef, dataSize: usize, ecSize: usize) {
assert!(
dataSize > 0 && dataSize <= field.getSize() - 3,
"Invalid data size for {}",
field
"Invalid data size for {field}"
);
assert!(
ecSize > 0 && ecSize + dataSize <= field.getSize(),
"Invalid ECC size for {}",
field
"Invalid ECC size for {field}"
);
let mut encoder = ReedSolomonEncoder::new(field);
let mut message = vec![0; dataSize + ecSize];
@@ -427,7 +425,7 @@ fn test_encode_decode_random(field: GenericGFRef, dataSize: usize, ecSize: usize
message[0..dataWords.len()].clone_from_slice(&dataWords[..]);
//System.arraycopy(dataWords, 0, message, 0, dataWords.len());
if let Err(err) = encoder.encode(&mut message, ecWords.len()) {
panic!("{:#?}", err);
panic!("{err:#?}");
}
ecWords[0..ecSize].clone_from_slice(&message[dataSize..dataSize + ecSize]);
//System.arraycopy(message, dataSize, ecWords, 0, ecSize);

View File

@@ -319,7 +319,7 @@ impl fmt::Display for GenericGFPoly {
result.push('a');
} else {
result.push_str("a^");
result.push_str(&format!("{}", alpha_power));
result.push_str(&format!("{alpha_power}"));
}
}
}
@@ -328,11 +328,11 @@ impl fmt::Display for GenericGFPoly {
result.push('x');
} else {
result.push_str("x^");
result.push_str(&format!("{}", degree));
result.push_str(&format!("{degree}"));
}
}
}
}
write!(f, "{}", result)
write!(f, "{result}")
}
}

View File

@@ -204,8 +204,7 @@ impl ReedSolomonDecoder {
if r.getDegree() >= rLast.getDegree() {
return Err(Exceptions::ReedSolomonException(Some(format!(
"Division algorithm failed to reduce polynomial? r: {}, rLast: {}",
r, rLast
"Division algorithm failed to reduce polynomial? r: {r}, rLast: {rLast}"
))));
}
}

View File

@@ -67,15 +67,13 @@ impl Writer for DataMatrixWriter {
if format != &BarcodeFormat::DATA_MATRIX {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Can only encode DATA_MATRIX, but got {:?}",
format
"Can only encode DATA_MATRIX, but got {format:?}"
))));
}
if width < 0 || height < 0 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested dimensions can't be negative: {}x{}",
width, height
"Requested dimensions can't be negative: {width}x{height}"
))));
}

View File

@@ -218,7 +218,7 @@ fn decodeAsciiSegment(
result.append_char('0');
}
//result.append_char(char::from_u32(value).unwrap());
result.append_string(&format!("{}", value));
result.append_string(&format!("{value}"));
} else {
match oneByte {
230=> // Latch to C40 encodation

View File

@@ -74,8 +74,7 @@ impl Encoder for ASCIIEncoder {
_ => {
return Err(Exceptions::IllegalStateException(Some(format!(
"Illegal mode: {}",
newMode
"Illegal mode: {newMode}"
))));
}
}
@@ -106,8 +105,7 @@ impl ASCIIEncoder {
Ok((num + 130) as char)
} else {
Err(Exceptions::IllegalArgumentException(Some(format!(
"not digits: {}{}",
digit1, digit2
"not digits: {digit1}{digit2}"
))))
}
}

View File

@@ -66,8 +66,7 @@ impl Encoder for Base256Encoder {
buffer.insert(ci_pos, char::from_u32(dataCount as u32 % 250).unwrap());
} else {
return Err(Exceptions::IllegalStateException(Some(format!(
"Message length not in valid ranges: {}",
dataCount
"Message length not in valid ranges: {dataCount}"
))));
}
}

View File

@@ -275,7 +275,7 @@ mod test_placement {
let actual = placement.toBitFieldStringArray();
for i in 0..actual.len() {
// for (int i = 0; i < actual.length; i++) {
assert_eq!(expected[i], actual[i], "Row {}", i);
assert_eq!(expected[i], actual[i], "Row {i}");
}
}

View File

@@ -221,8 +221,7 @@ fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptio
}
if table < 0 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Illegal number of error correction codewords specified: {}",
numECWords
"Illegal number of error correction codewords specified: {numECWords}"
))));
}
let poly = &FACTORS[table as usize];

View File

@@ -603,7 +603,6 @@ pub fn illegalCharacter(c: char) -> Result<(), Exceptions> {
// let hex = Integer.toHexString(c);
// hex = "0000".substring(0, 4 - hex.length()) + hex;
Err(Exceptions::IllegalArgumentException(Some(format!(
"Illegal character: {} (0x{})",
c, c
"Illegal character: {c} (0x{c})"
))))
}

View File

@@ -640,8 +640,7 @@ fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult, Exceptions> {
if minimalJ < 0 {
return Err(Exceptions::IllegalStateException(Some(format!(
"Internal error: failed to encode \"{}\"",
input
"Internal error: failed to encode \"{input}\""
))));
}
RXingResult::new(edges[inputLength][minimalJ as usize].clone())

View File

@@ -346,8 +346,7 @@ impl<'a> SymbolInfoLookup<'a> {
}
if fail {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Can't find a symbol arrangement that matches the message. Data codewords: {}",
dataCodewords
"Can't find a symbol arrangement that matches the message. Data codewords: {dataCodewords}"
))));
}
Ok(None)

View File

@@ -22,29 +22,29 @@ impl fmt::Display for Exceptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Exceptions::IllegalArgumentException(Some(a)) => {
write!(f, "IllegalArgumentException - {}", a)
write!(f, "IllegalArgumentException - {a}")
}
Exceptions::UnsupportedOperationException(Some(a)) => {
write!(f, "UnsupportedOperationException - {}", a)
write!(f, "UnsupportedOperationException - {a}")
}
Exceptions::IllegalStateException(Some(a)) => {
write!(f, "IllegalStateException - {}", a)
write!(f, "IllegalStateException - {a}")
}
Exceptions::ArithmeticException(Some(a)) => write!(f, "ArithmeticException - {}", a),
Exceptions::NotFoundException(Some(a)) => write!(f, "NotFoundException - {}", a),
Exceptions::FormatException(Some(a)) => write!(f, "FormatException - {}", a),
Exceptions::ChecksumException(Some(a)) => write!(f, "ChecksumException - {}", a),
Exceptions::ReaderException(Some(a)) => write!(f, "ReaderException - {}", a),
Exceptions::WriterException(Some(a)) => write!(f, "WriterException - {}", a),
Exceptions::ReedSolomonException(Some(a)) => write!(f, "ReedSolomonException - {}", a),
Exceptions::ArithmeticException(Some(a)) => write!(f, "ArithmeticException - {a}"),
Exceptions::NotFoundException(Some(a)) => write!(f, "NotFoundException - {a}"),
Exceptions::FormatException(Some(a)) => write!(f, "FormatException - {a}"),
Exceptions::ChecksumException(Some(a)) => write!(f, "ChecksumException - {a}"),
Exceptions::ReaderException(Some(a)) => write!(f, "ReaderException - {a}"),
Exceptions::WriterException(Some(a)) => write!(f, "WriterException - {a}"),
Exceptions::ReedSolomonException(Some(a)) => write!(f, "ReedSolomonException - {a}"),
Exceptions::IndexOutOfBoundsException(Some(a)) => {
write!(f, "IndexOutOfBoundsException - {}", a)
write!(f, "IndexOutOfBoundsException - {a}")
}
Exceptions::RuntimeException(Some(a)) => write!(f, "RuntimeException - {}", a),
Exceptions::ParseException(Some(a)) => write!(f, "ParseException - {}", a),
Exceptions::RuntimeException(Some(a)) => write!(f, "RuntimeException - {a}"),
Exceptions::ParseException(Some(a)) => write!(f, "ParseException - {a}"),
Exceptions::IllegalArgumentException(None) => write!(f, "IllegalArgumentException"),

View File

@@ -134,7 +134,7 @@ pub fn detect_in_file_with_hints(
hints: &mut DecodingHintDictionary,
) -> Result<RXingResult, Exceptions> {
let Ok(img) = image::open(file_name) else {
return Err(Exceptions::IllegalArgumentException(Some(format!("file '{}' not found or cannot be opened", file_name))));
return Err(Exceptions::IllegalArgumentException(Some(format!("file '{file_name}' not found or cannot be opened"))));
};
let mut multi_format_reader = MultiFormatReader::default();
@@ -255,8 +255,7 @@ pub fn save_image(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Excepti
match image.save(file_name) {
Ok(_) => Ok(()),
Err(err) => Err(Exceptions::IllegalArgumentException(Some(format!(
"could not save file '{}': {}",
file_name, err
"could not save file '{file_name}': {err}"
)))),
}
}
@@ -303,8 +302,7 @@ pub fn save_file(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exceptio
}() {
Ok(_) => Ok(()),
Err(_) => Err(Exceptions::IllegalArgumentException(Some(format!(
"could not write to '{}'",
file_name
"could not write to '{file_name}'"
)))),
}
}

View File

@@ -61,11 +61,8 @@ const POSTCODE_3_BYTES: [[u8; 6]; 6] = [
static SETS: Lazy<[String; 5]> = Lazy::new(|| {
[
format!("\rABCDEFGHIJKLMNOPQRSTUVWXYZ{}{}{}{}{} {}\"#$%&'()*+,-./0123456789:{}{}{}{}{}" , ECI , FS , GS , RS , NS , PAD ,
SHIFTB , SHIFTC , SHIFTD , SHIFTE , LATCHB),
format!("`abcdefghijklmnopqrstuvwxyz{}{}{}{}{}{{{}}}~\u{007F};<=>?[\\]^_ ,./:@!|{}{}{}{}{}{}{}{}{}" , ECI , FS , GS , RS , NS ,PAD ,
PAD , TWOSHIFTA , THREESHIFTA , PAD ,
SHIFTA , SHIFTC , SHIFTD , SHIFTE , LATCHA),
format!("\rABCDEFGHIJKLMNOPQRSTUVWXYZ{ECI}{FS}{GS}{RS}{NS} {PAD}\"#$%&'()*+,-./0123456789:{SHIFTB}{SHIFTC}{SHIFTD}{SHIFTE}{LATCHB}" ),
format!("`abcdefghijklmnopqrstuvwxyz{ECI}{FS}{GS}{RS}{NS}{{{PAD}}}~\u{007F};<=>?[\\]^_ ,./:@!|{PAD}{TWOSHIFTA}{THREESHIFTA}{PAD}{SHIFTA}{SHIFTC}{SHIFTD}{SHIFTE}{LATCHA}" ),
format!("\u{00C0}\u{00C1}\u{00C2}\u{00C3}\u{00C4}\u{00C5}\u{00C6}\u{00C7}\u{00C8}\u{00C9}\u{00CA}\u{00CB}\u{00CC}\u{00CD}\u{00CE}\u{00CF}\u{00D0}\u{00D1}\u{00D2}\u{00D3}\u{00D4}\u{00D5}\u{00D6}\u{00D7}\u{00D8}\u{00D9}\u{00DA}{}{}{}{}{}{}{}{}{}{}{}{}" ,
ECI , FS , GS , RS , NS ,
"\u{00DB}\u{00DC}\u{00DD}\u{00DE}\u{00DF}\u{00AA}\u{00AC}\u{00B1}\u{00B2}\u{00B3}\u{00B5}\u{00B9}\u{00BA}\u{00BC}\u{00BD}\u{00BE}\u{0080}\u{0081}\u{0082}\u{0083}\u{0084}\u{0085}\u{0086}\u{0087}\u{0088}\u{0089}" ,
@@ -93,7 +90,7 @@ pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions>
}
// NumberFormat df = new DecimalFormat("0000000000".substring(0, ps2Length));
// postcode = df.format(pc);
format!("{:0>ps2Length$}", pc)
format!("{pc:0>ps2Length$}")
} else {
getPostCode3(bytes)
};
@@ -106,12 +103,12 @@ pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions>
if result.starts_with(&format!("[)>{}{}{}", RS, "01", GS)) {
result.insert_str(
9,
&format!("{}{}{}{}{}{}", postcode, GS, country, GS, service, GS),
&format!("{postcode}{GS}{country}{GS}{service}{GS}"),
);
} else {
result.insert_str(
0,
&format!("{}{}{}{}{}{}", postcode, GS, country, GS, service, GS),
&format!("{postcode}{GS}{country}{GS}{service}{GS}"),
);
}
}
@@ -226,7 +223,7 @@ fn getMessage(bytes: &[u8], start: u32, len: u32) -> String {
i += 1;
nsval += bytes[i as usize] as u32;
// sb.append(new DecimalFormat("000000000").format(nsval));},
sb.push_str(&format!("{:0>9}", nsval));
sb.push_str(&format!("{nsval:0>9}"));
}
LOCK => {
shift = -1;

View File

@@ -140,11 +140,12 @@ impl<'a> Circle<'_> {
// find semi-major and semi-minor axi
let mut lengths = [(0, 0.0, [(0.0_f32, 0.0); 2]); 72];
let mut circle_points = Vec::new();
for i_rotation in 0..72 {
// for i_rotation in 0..72 {
for (i_rotation, length_set) in lengths.iter_mut().enumerate(){
let rotation = i_rotation as f32 * 5.0;
let (length, points) = self.find_width_at_degree(rotation);
circle_points.extend_from_slice(&points);
lengths[i_rotation] = (length, rotation, points);
*length_set = (length, rotation, points);
}
lengths.sort_by_key(|e| e.0);
let major_axis = lengths.last().unwrap();
@@ -352,12 +353,12 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
target_height.round() as u32,
0.0,
0.0,
target_width as f32 ,
target_width ,
0.0,
target_width as f32,
target_height as f32,
target_width,
target_height,
0.0,
target_height as f32,
target_height,
tl.0,
tl.1,
tr.0,

View File

@@ -72,8 +72,7 @@ impl Writer for MultiFormatWriter {
BarcodeFormat::AZTEC => Box::<AztecWriter>::default(),
_ => {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"No encoder available for format {:?}",
format
"No encoder available for format {format:?}"
))))
}
};

View File

@@ -37,7 +37,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, crate::Exceptions> {
let contents = if contents.chars().count() < 2 {
// Can't have a start/end guard, so tentatively add default guards
format!("{}{}{}", DEFAULT_GUARD, contents, DEFAULT_GUARD)
format!("{DEFAULT_GUARD}{contents}{DEFAULT_GUARD}")
} else {
// Verify input and calculate decoded length.
let firstChar = contents.chars().next().unwrap().to_ascii_uppercase();
@@ -53,8 +53,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
if startsNormal {
if !endsNormal {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Invalid start/end guards: {}",
contents
"Invalid start/end guards: {contents}"
))));
}
// else already has valid start/end
@@ -62,8 +61,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
} else if startsAlt {
if !endsAlt {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Invalid start/end guards: {}",
contents
"Invalid start/end guards: {contents}"
))));
}
// else already has valid start/end
@@ -72,12 +70,11 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
// Doesn't start with a guard
if endsNormal || endsAlt {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Invalid start/end guards: {}",
contents
"Invalid start/end guards: {contents}"
))));
}
// else doesn't end with guard either, so add a default
format!("{}{}{}", DEFAULT_GUARD, contents, DEFAULT_GUARD)
format!("{DEFAULT_GUARD}{contents}{DEFAULT_GUARD}")
}
};
@@ -95,8 +92,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
resultLength += 10;
} else {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Cannot encode : '{}'",
ch
"Cannot encode : '{ch}'"
))));
}
}

View File

@@ -356,7 +356,7 @@ impl OneDReader for Code128Reader {
resultObject.putMetadata(
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER,
RXingResultMetadataValue::SymbologyIdentifier(format!("]C{}", symbologyModifier)),
RXingResultMetadataValue::SymbologyIdentifier(format!("]C{symbologyModifier}")),
);
Ok(resultObject)

View File

@@ -96,8 +96,7 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
// Check length
if !(1..=80).contains(&length) {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Contents length should be between 1 and 80 characters, but got {}",
length
"Contents length should be between 1 and 80 characters, but got {length}"
))));
}
@@ -111,8 +110,7 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
"C" => forcedCodeSet = CODE_CODE_C as i32,
_ => {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Unsupported code set hint: {}",
codeSetHint
"Unsupported code set hint: {codeSetHint}"
))))
}
}
@@ -133,8 +131,7 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
// no full Latin-1 character set available at the moment
// shift and manual code change are not supported
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Bad character in input: ASCII value={}",
c
"Bad character in input: ASCII value={c}"
))));
}
}
@@ -149,8 +146,7 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
{
if c > 95 && c <= 127 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Bad character in input for forced code set A: ASCII value={}",
c
"Bad character in input for forced code set A: ASCII value={c}"
))));
}
}
@@ -159,8 +155,7 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
{
if c <= 32 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Bad character in input for forced code set B: ASCII value={}",
c
"Bad character in input for forced code set B: ASCII value={c}"
))));
}
}
@@ -174,8 +169,7 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
|| ch == ESCAPE_FNC_4
{
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Bad character in input for forced code set C: ASCII value={}",
c
"Bad character in input for forced code set C: ASCII value={c}"
))));
}
}

View File

@@ -311,7 +311,7 @@ fn testEncodeSwitchBetweenCodesetsAAndB() {
fn testEncode(toEncode: &str, expected: &str) {
let result = encode(toEncode, false, toEncode).expect("encode");
let actual = bit_matrix_test_case::matrix_to_string(&result);
assert_eq!(expected, actual, "{}", toEncode);
assert_eq!(expected, actual, "{toEncode}");
let width = result.getWidth();
let result = encode(toEncode, true, toEncode).expect("encode");

View File

@@ -34,8 +34,7 @@ impl OneDimensionalCodeWriter for Code39Writer {
let mut length = contents.chars().count();
if length > 80 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested contents should be less than 80 digits long, but got {}",
length
"Requested contents should be less than 80 digits long, but got {length}"
))));
}
@@ -50,7 +49,7 @@ impl OneDimensionalCodeWriter for Code39Writer {
contents = Self::tryToConvertToExtendedMode(&contents)?;
length = contents.chars().count();
if length > 80 {
return Err(Exceptions::IllegalArgumentException(Some(format!("Requested contents should be less than 80 digits long, but got {} (extended full ASCII mode)",length))));
return Err(Exceptions::IllegalArgumentException(Some(format!("Requested contents should be less than 80 digits long, but got {length} (extended full ASCII mode)"))));
}
break;
}
@@ -156,8 +155,7 @@ impl Code39Writer {
.push(char::from_u32('P' as u32 + (character as u32 - 123)).unwrap());
} else {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested content contains a non-encodable character: '{}'",
character
"Requested content contains a non-encodable character: '{character}'"
))));
}
}
@@ -249,8 +247,7 @@ mod Code39WriterTestCase {
assert_eq!(
expected,
bit_matrix_test_case::matrix_to_string(&result),
"{}",
input
"{input}"
);
}
}

View File

@@ -35,7 +35,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
let mut contents = Self::convertToExtended(contents)?;
let length = contents.chars().count();
if length > 80 {
return Err(Exceptions::IllegalArgumentException(Some(format!("Requested contents should be less than 80 digits long after converting to extended encoding, but got {}" , length))));
return Err(Exceptions::IllegalArgumentException(Some(format!("Requested contents should be less than 80 digits long after converting to extended encoding, but got {length}" ))));
}
//length of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar
@@ -197,8 +197,7 @@ impl Code93Writer {
.push(char::from_u32('P' as u32 + character as u32 - '{' as u32).unwrap());
} else {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested content contains a non-encodable character: '{}'",
character
"Requested content contains a non-encodable character: '{character}'"
))));
}
}

View File

@@ -61,8 +61,7 @@ impl OneDimensionalCodeWriter for EAN13Writer {
}
_ => {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested contents should be 12 or 13 digits long, but got {}",
length
"Requested contents should be 12 or 13 digits long, but got {length}"
))))
}
}

View File

@@ -71,8 +71,7 @@ impl OneDimensionalCodeWriter for EAN8Writer {
// }},
_ => {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested contents should be 7 or 8 digits long, but got {}",
length
"Requested contents should be 7 or 8 digits long, but got {length}"
))))
}
}

View File

@@ -38,8 +38,7 @@ impl OneDimensionalCodeWriter for ITFWriter {
}
if length > 80 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested contents should be less than 80 digits long, but got {}",
length
"Requested contents should be less than 80 digits long, but got {length}"
))));
}

View File

@@ -173,15 +173,13 @@ impl Writer for L {
if width < 0 || height < 0 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Negative size is not allowed. Input: {}x{}",
width, height
"Negative size is not allowed. Input: {width}x{height}"
))));
}
if let Some(supportedFormats) = self.getSupportedWriteFormats() {
if !supportedFormats.contains(format) {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Can only encode {:?}, but got {:?}",
supportedFormats, format
"Can only encode {supportedFormats:?}, but got {format:?}"
))));
}
}

View File

@@ -150,7 +150,6 @@ pub fn createDecoder<'a>(
}
Err(Exceptions::IllegalStateException(Some(format!(
"unknown decoder: {}",
information
"unknown decoder: {information}"
))))
}

View File

@@ -83,8 +83,7 @@ mod AI013103DecoderTest {
#[test]
fn test0131031() {
let data = format!(
"{}{}{}",
HEADER, COMPRESSED_GTIN900123456798908, COMPRESSED15BIT_WEIGHT1750
"{HEADER}{COMPRESSED_GTIN900123456798908}{COMPRESSED15BIT_WEIGHT1750}"
);
let expected = "(01)90012345678908(3103)001750";
assertCorrectBinaryString(&data, expected);
@@ -93,8 +92,7 @@ mod AI013103DecoderTest {
#[test]
fn test0131032() {
let data = format!(
"{}{}{}",
HEADER, COMPRESSED_GTIN900000000000008, COMPRESSED15BIT_WEIGHT0
"{HEADER}{COMPRESSED_GTIN900000000000008}{COMPRESSED15BIT_WEIGHT0}"
);
let expected = "(01)90000000000003(3103)000000";
assertCorrectBinaryString(&data, expected);
@@ -104,8 +102,7 @@ mod AI013103DecoderTest {
#[should_panic]
fn test013103invalid() {
let data = format!(
"{}{}{}..",
HEADER, COMPRESSED_GTIN900123456798908, COMPRESSED15BIT_WEIGHT1750
"{HEADER}{COMPRESSED_GTIN900123456798908}{COMPRESSED15BIT_WEIGHT1750}.."
);
assertCorrectBinaryString(&data, "");
}

View File

@@ -35,8 +35,7 @@ const HEADER: &str = "..X.X";
#[test]
fn test0132021() {
let data = format!(
"{}{}{}",
HEADER, COMPRESSED_GTIN900123456798908, COMPRESSED15BIT_WEIGHT1750
"{HEADER}{COMPRESSED_GTIN900123456798908}{COMPRESSED15BIT_WEIGHT1750}"
);
let expected = "(01)90012345678908(3202)001750";
@@ -46,8 +45,7 @@ fn test0132021() {
#[test]
fn test0132031() {
let data = format!(
"{}{}{}",
HEADER, COMPRESSED_GTIN900123456798908, COMPRESSED15BIT_WEIGHT11750
"{HEADER}{COMPRESSED_GTIN900123456798908}{COMPRESSED15BIT_WEIGHT11750}"
);
let expected = "(01)90012345678908(3203)001750";

View File

@@ -151,11 +151,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01310X1XendDate() {
let data = format!(
"{}{}{}{}",
HEADER310X11,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_END
"{HEADER310X11}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_END}"
);
let expected = "(01)90012345678908(3100)001750";
@@ -165,11 +161,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01310X111() {
let data = format!(
"{}{}{}{}",
HEADER310X11,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_MARCH12TH2010
"{HEADER310X11}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_MARCH12TH2010}"
);
let expected = "(01)90012345678908(3100)001750(11)100312";
@@ -179,11 +171,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01320X111() {
let data = format!(
"{}{}{}{}",
HEADER320X11,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_MARCH12TH2010
"{HEADER320X11}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_MARCH12TH2010}"
);
let expected = "(01)90012345678908(3200)001750(11)100312";
@@ -193,11 +181,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01310X131() {
let data = format!(
"{}{}{}{}",
HEADER310X13,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_MARCH12TH2010
"{HEADER310X13}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_MARCH12TH2010}"
);
let expected = "(01)90012345678908(3100)001750(13)100312";
@@ -207,11 +191,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01320X131() {
let data = format!(
"{}{}{}{}",
HEADER320X13,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_MARCH12TH2010
"{HEADER320X13}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_MARCH12TH2010}"
);
let expected = "(01)90012345678908(3200)001750(13)100312";
@@ -221,11 +201,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01310X151() {
let data = format!(
"{}{}{}{}",
HEADER310X15,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_MARCH12TH2010
"{HEADER310X15}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_MARCH12TH2010}"
);
let expected = "(01)90012345678908(3100)001750(15)100312";
@@ -235,11 +211,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01320X151() {
let data = format!(
"{}{}{}{}",
HEADER320X15,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_MARCH12TH2010
"{HEADER320X15}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_MARCH12TH2010}"
);
let expected = "(01)90012345678908(3200)001750(15)100312";
@@ -249,11 +221,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01310X171() {
let data = format!(
"{}{}{}{}",
HEADER310X17,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_MARCH12TH2010
"{HEADER310X17}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_MARCH12TH2010}"
);
let expected = "(01)90012345678908(3100)001750(17)100312";
@@ -263,11 +231,7 @@ mod AI013X0X1XDecoderTest {
#[test]
fn test01320X171() {
let data = format!(
"{}{}{}{}",
HEADER320X17,
COMPRESSED_GTIN900123456798908,
COMPRESSED20BIT_WEIGHT1750,
COMPRESSED_DATE_MARCH12TH2010
"{HEADER320X17}{COMPRESSED_GTIN900123456798908}{COMPRESSED20BIT_WEIGHT1750}{COMPRESSED_DATE_MARCH12TH2010}"
);
let expected = "(01)90012345678908(3200)001750(17)100312";

View File

@@ -70,8 +70,7 @@ mod AnyAIDecoderTest {
#[test]
fn testAnyAIDecoder1() {
let data = format!(
"{}{}{}{}{}{}{}",
HEADER, NUMERIC10, NUMERIC12, NUMERIC2ALPHA, ALPHA_A, ALPHA2NUMERIC, NUMERIC12
"{HEADER}{NUMERIC10}{NUMERIC12}{NUMERIC2ALPHA}{ALPHA_A}{ALPHA2NUMERIC}{NUMERIC12}"
);
let expected = "(10)12A12";
@@ -81,8 +80,7 @@ mod AnyAIDecoderTest {
#[test]
fn testAnyAIDecoder2() {
let data = format!(
"{}{}{}{}{}{}{}",
HEADER, NUMERIC10, NUMERIC12, NUMERIC2ALPHA, ALPHA_A, ALPHA2ISOIEC646, I646_B
"{HEADER}{NUMERIC10}{NUMERIC12}{NUMERIC2ALPHA}{ALPHA_A}{ALPHA2ISOIEC646}{I646_B}"
);
let expected = "(10)12AB";
@@ -92,17 +90,7 @@ mod AnyAIDecoderTest {
#[test]
fn testAnyAIDecoder3() {
let data = format!(
"{}{}{}{}{}{}{}{}{}{}",
HEADER,
NUMERIC10,
NUMERIC2ALPHA,
ALPHA2ISOIEC646,
I646_B,
I646_C,
ISOIEC6462ALPHA,
ALPHA_A,
ALPHA2NUMERIC,
NUMERIC10
"{HEADER}{NUMERIC10}{NUMERIC2ALPHA}{ALPHA2ISOIEC646}{I646_B}{I646_C}{ISOIEC6462ALPHA}{ALPHA_A}{ALPHA2NUMERIC}{NUMERIC10}"
);
let expected = "(10)BCA10";
@@ -111,7 +99,7 @@ mod AnyAIDecoderTest {
#[test]
fn testAnyAIDecodernumericFNC1secondDigit() {
let data = format!("{}{}{}", HEADER, NUMERIC10, NUMERIC1_FNC1);
let data = format!("{HEADER}{NUMERIC10}{NUMERIC1_FNC1}");
let expected = "(10)1";
assertCorrectBinaryString(&data, expected);
@@ -120,8 +108,7 @@ mod AnyAIDecoderTest {
#[test]
fn testAnyAIDecoderalphaFNC1() {
let data = format!(
"{}{}{}{}{}",
HEADER, NUMERIC10, NUMERIC2ALPHA, ALPHA_A, ALPHA_FNC1
"{HEADER}{NUMERIC10}{NUMERIC2ALPHA}{ALPHA_A}{ALPHA_FNC1}"
);
let expected = "(10)A";
@@ -131,8 +118,7 @@ mod AnyAIDecoderTest {
#[test]
fn testAnyAIDecoder646FNC1() {
let data = format!(
"{}{}{}{}{}{}{}",
HEADER, NUMERIC10, NUMERIC2ALPHA, ALPHA_A, ISOIEC6462ALPHA, I646_B, I646_FNC1
"{HEADER}{NUMERIC10}{NUMERIC2ALPHA}{ALPHA_A}{ISOIEC6462ALPHA}{I646_B}{I646_FNC1}"
);
let expected = "(10)AB";

View File

@@ -215,13 +215,13 @@ fn processFixedAI(
.take(fieldSize)
.collect(); //rawInformation.substring(aiSize, aiSize + fieldSize);
let remaining: String = rawInformation.chars().skip(aiSize + fieldSize).collect(); // rawInformation.substring(aiSize + fieldSize);
let result = format!("({}){}", ai, field);
let result = format!("({ai}){field}");
let parsedAI = parseFieldsInGeneralPurpose(&remaining)?;
Ok(if parsedAI.is_empty() {
result
} else {
format!("{}{}", result, parsedAI)
format!("{result}{parsedAI}")
})
}
@@ -237,13 +237,13 @@ fn processVariableAI(
.min(aiSize + variableFieldSize);
let field: String = rawInformation.chars().skip(aiSize).take(maxSize).collect(); // (aiSize, maxSize);
let remaining: String = rawInformation.chars().skip(maxSize).collect();
let result = format!("({}){}", ai, field); //'(' + ai + ')' + field;
let result = format!("({ai}){field}"); //'(' + ai + ')' + field;
let parsedAI = parseFieldsInGeneralPurpose(&remaining)?;
Ok(if parsedAI.is_empty() {
result
} else {
format!("{}{}", result, parsedAI)
format!("{result}{parsedAI}")
})
}

View File

@@ -445,8 +445,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
62 => '/',
_ => {
return Err(Exceptions::IllegalStateException(Some(format!(
"Decoding invalid alphanumeric value: {}",
sixBitValue
"Decoding invalid alphanumeric value: {sixBitValue}"
))))
}
};

View File

@@ -68,7 +68,7 @@ impl Display for ExpandedRow {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{{ ")?;
for p in &self.pairs {
write!(f, "{}", p)?;
write!(f, "{p}")?;
}
write!(f, " }}") //{:?} }} " , self.pairs )
}

View File

@@ -171,7 +171,7 @@ fn testDecodeRow2binary22() {
}
fn assertCorrectImage2binary(fileName: &str, expected: &str) {
let path = format!("test_resources/blackbox/rssexpanded-1/{}", fileName);
let path = format!("test_resources/blackbox/rssexpanded-1/{fileName}");
let image = image::open(path).expect("file exists");
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(

View File

@@ -68,7 +68,7 @@ fn testDecodeRow2result2() {
}
fn assertCorrectImage2result(fileName: &str, expected: ExpandedProductParsedRXingResult) {
let path = format!("test_resources/blackbox/rssexpanded-1/{}", fileName);
let path = format!("test_resources/blackbox/rssexpanded-1/{fileName}");
let image = image::open(path).expect("image must exist");
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(

View File

@@ -181,7 +181,7 @@ fn testDecodeRow2string32() {
}
fn assertCorrectImage2string(fileName: &str, expected: &str) {
let path = format!("test_resources/blackbox/rssexpanded-1/{}", fileName);
let path = format!("test_resources/blackbox/rssexpanded-1/{fileName}");
let image = image::open(path).expect("load image");
let binaryMap = BinaryBitmap::new(Rc::new(GlobalHistogramBinarizer::new(Box::new(

View File

@@ -172,8 +172,7 @@ fn testDecodeDataCharacter() {
fn readImage(fileName: &str) -> image::DynamicImage {
image::open(format!(
"test_resources/blackbox/rssexpanded-1/{}",
fileName
"test_resources/blackbox/rssexpanded-1/{fileName}"
))
.unwrap()
// Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);

View File

@@ -31,7 +31,7 @@ use image::DynamicImage;
use crate::{common::GlobalHistogramBinarizer, BinaryBitmap, BufferedImageLuminanceSource};
fn getBufferedImage(fileName: &str) -> DynamicImage {
let path = format!("test_resources/blackbox/rssexpandedstacked-2/{}", fileName);
let path = format!("test_resources/blackbox/rssexpandedstacked-2/{fileName}");
image::open(path).expect("load image")
}

View File

@@ -49,13 +49,12 @@ impl Writer for UPCAWriter {
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
if format != &BarcodeFormat::UPC_A {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Can only encode UPC-A, but got {:?}",
format
"Can only encode UPC-A, but got {format:?}"
))));
}
// Transform a UPC-A code into the equivalent EAN-13 code and write it that way
self.0.encode_with_hints(
&format!("0{}", contents),
&format!("0{contents}"),
&BarcodeFormat::EAN_13,
width,
height,

View File

@@ -69,8 +69,7 @@ impl OneDimensionalCodeWriter for UPCEWriter {
// }},
_ => {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested contents should be 7 or 8 digits long, but got {}",
length
"Requested contents should be 7 or 8 digits long, but got {length}"
))))
}
}

View File

@@ -209,11 +209,11 @@ impl UPCEANExtension5Support {
let unitsString = (rawAmount / 100).to_string();
let hundredths = rawAmount % 100;
let hundredthsString = if hundredths < 10 {
format!("0{}", hundredths)
format!("0{hundredths}")
} else {
hundredths.to_string()
};
Some(format!("{}{}.{}", currency, unitsString, hundredthsString))
Some(format!("{currency}{unitsString}.{hundredthsString}"))
}
}

View File

@@ -304,7 +304,7 @@ pub trait UPCEANReader: OneDReader {
decodeRXingResult.putMetadata(
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER,
RXingResultMetadataValue::SymbologyIdentifier(format!("]E{}", symbologyIdentifier)),
RXingResultMetadataValue::SymbologyIdentifier(format!("]E{symbologyIdentifier}")),
);
Ok(decodeRXingResult)

View File

@@ -652,7 +652,7 @@ impl Display for DetectionRXingResult {
// try (Formatter formatter = new Formatter()) {
for codewordsRow in 0..rowIndicatorColumn.as_ref().unwrap().getCodewords().len() {
// for (int codewordsRow = 0; codewordsRow < rowIndicatorColumn.getCodewords().length; codewordsRow++) {
write!(f, "CW {0:3}", codewordsRow)?;
write!(f, "CW {codewordsRow:3}")?;
// formatter.format("CW %3d:", codewordsRow);
for barcodeColumn in 0..self.barcodeColumnCount + 2 {
// for (int barcodeColumn = 0; barcodeColumn < barcodeColumnCount + 2; barcodeColumn++) {

View File

@@ -133,7 +133,7 @@ impl Display for DetectionRXingResultColumn {
for codeword in &self.codewords {
// for (Codeword codeword : codewords) {
if codeword.is_none() {
writeln!(f, "{:3}: | ", row)?;
writeln!(f, "{row:3}: | ")?;
row += 1;
continue;
}

View File

@@ -41,8 +41,7 @@ impl TryFrom<&String> for Compaction {
}
}
Err(Exceptions::FormatException(Some(format!(
"Compaction must be 0-3 (inclusivie). Found: {}",
value
"Compaction must be 0-3 (inclusivie). Found: {value}"
))))
}
}

View File

@@ -247,7 +247,7 @@ impl PDF417 {
//4. step: low-level encoding
let mut barcode_matrix = BarcodeMatrix::new(rows as usize, cols as usize);
self.encodeLowLevel(
&format!("{}{}", dataCodewords, ec),
&format!("{dataCodewords}{ec}"),
cols,
rows,
errorCorrectionLevel,

View File

@@ -806,8 +806,7 @@ fn encodingECI(eci: i32, sb: &mut String) -> Result<(), Exceptions> {
sb.push(char::from_u32((810900 - eci) as u32).unwrap());
} else {
return Err(Exceptions::WriterException(Some(format!(
"ECI number not in valid range from 0..811799, but was {}",
eci
"ECI number not in valid range from 0..811799, but was {eci}"
))));
}
Ok(())

View File

@@ -60,8 +60,7 @@ impl Writer for PDF417Writer {
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
if format != &BarcodeFormat::PDF_417 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Can only encode PDF_417, but got {}",
format
"Can only encode PDF_417, but got {format}"
))));
}

View File

@@ -252,7 +252,7 @@ impl LuminanceSource for PlanarYUVLuminanceSource {
fn getRow(&self, y: usize) -> Vec<u8> {
if y >= self.getHeight() {
//throw new IllegalArgumentException("Requested row is outside the image: " + y);
panic!("Requested row is outside the image: {}", y);
panic!("Requested row is outside the image: {y}");
}
let width = self.getWidth();

View File

@@ -37,8 +37,7 @@ impl BitMatrixParser {
let dimension = bit_matrix.getHeight();
if dimension < 21 || (dimension & 0x03) != 1 {
Err(Exceptions::FormatException(Some(format!(
"{} < 21 || ({} % 0x03) != 1",
dimension, dimension
"{dimension} < 21 || ({dimension} % 0x03) != 1"
))))
} else {
Ok(Self {

View File

@@ -231,8 +231,7 @@ impl TryFrom<u8> for DataMask {
6 => Ok(DataMask::DATA_MASK_110),
7 => Ok(DataMask::DATA_MASK_111),
_ => Err(Exceptions::IllegalArgumentException(Some(format!(
"{} is not between 0 and 7",
value
"{value} is not between 0 and 7"
)))),
}
}

View File

@@ -98,7 +98,7 @@ fn testMask(mask: DataMask, dimension: u32, condition: MaskCondition) {
// for (int i = 0; i < dimension; i++) {
for j in 0..dimension {
// for (int j = 0; j < dimension; j++) {
assert_eq!(condition(i, j), bits.get(j, i), "({},{})", i, j);
assert_eq!(condition(i, j), bits.get(j, i), "({i},{j})");
}
}
}

View File

@@ -96,8 +96,7 @@ pub fn decode(
currentCharacterSetECI = Some(CharacterSetECI::getCharacterSetECIByValue(value)?);
if currentCharacterSetECI.is_none() {
return Err(Exceptions::FormatException(Some(format!(
"Value of {} not valid",
value
"Value of {value} not valid"
))));
}
}

View File

@@ -48,8 +48,7 @@ impl ErrorCorrectionLevel {
2 => Ok(Self::H),
3 => Ok(Self::Q),
_ => Err(Exceptions::IllegalArgumentException(Some(format!(
"{} is not a valid bit selection",
bits
"{bits} is not a valid bit selection"
)))),
}
}
@@ -111,8 +110,7 @@ impl FromStr for ErrorCorrectionLevel {
}
return Err(Exceptions::IllegalArgumentException(Some(format!(
"could not parse {} into an ec level",
s
"could not parse {s} into an ec level"
))));
}
}

View File

@@ -69,8 +69,7 @@ impl Mode {
Ok(Self::HANZI)
}
_ => Err(Exceptions::IllegalArgumentException(Some(format!(
"{} is not valid",
bits
"{bits} is not valid"
)))),
}
}

View File

@@ -110,7 +110,7 @@ impl fmt::Display for ByteMatrix {
}
result.push('\n');
}
write!(f, "{}", result)
write!(f, "{result}")
}
}

View File

@@ -186,8 +186,7 @@ pub fn getDataMaskBit(maskPattern: u32, x: u32, y: u32) -> Result<bool, Exceptio
}
_ => {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Invalid mask pattern: {}",
maskPattern
"Invalid mask pattern: {maskPattern}"
))))
}
};

View File

@@ -161,8 +161,7 @@ impl MinimalEncoder {
&self.ecLevel,
) {
return Err(Exceptions::WriterException(Some(format!(
"Data too big for version {}",
version
"Data too big for version {version}"
))));
}
Ok(result)
@@ -270,8 +269,7 @@ impl MinimalEncoder {
Mode::BYTE => Ok(3),
Mode::KANJI => Ok(0),
_ => Err(Exceptions::IllegalArgumentException(Some(format!(
"Illegal mode {:?}",
mode
"Illegal mode {mode:?}"
)))),
}
// switch (mode) {
@@ -956,7 +954,7 @@ impl fmt::Display for RXingResultList {
result.push_str(&current.to_string());
previous = Some(current);
}
write!(f, "{}", result)
write!(f, "{result}")
}
}
@@ -1141,6 +1139,6 @@ impl fmt::Display for RXingResultNode {
}
result.push(')');
write!(f, "{}", result)
write!(f, "{result}")
}
}

View File

@@ -134,7 +134,7 @@ impl fmt::Display for QRCode {
}
result.push_str(">>\n");
write!(f, "{}", result)
write!(f, "{result}")
}
}

View File

@@ -430,8 +430,7 @@ pub fn terminateBits(num_data_bytes: u32, bits: &mut BitArray) -> Result<(), Exc
let capacity = num_data_bytes * 8;
if bits.getSize() > capacity as usize {
return Err(Exceptions::WriterException(Some(format!(
"data bits cannot fit in the QR Code{} > ",
capacity
"data bits cannot fit in the QR Code{capacity} > "
))));
// throw new WriterException("data bits cannot fit in the QR Code" + bits.getSize() + " > " +
// capacity);
@@ -701,8 +700,7 @@ pub fn appendBytes(
Mode::BYTE => append8BitBytes(content, bits, encoding),
Mode::KANJI => appendKanjiBytes(content, bits),
_ => Err(Exceptions::WriterException(Some(format!(
"Invalid mode: {:?}",
mode
"Invalid mode: {mode:?}"
)))),
}
// switch (mode) {

View File

@@ -66,16 +66,14 @@ impl Writer for QRCodeWriter {
if format != &BarcodeFormat::QR_CODE {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Can only encode QR_CODE, but got {:?}",
format
"Can only encode QR_CODE, but got {format:?}"
))));
// throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if width < 0 || height < 0 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
"Requested dimensions are too small: {}x{}",
width, height
"Requested dimensions are too small: {width}x{height}"
))));
// throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
// height);

View File

@@ -40,7 +40,7 @@ pub struct RGBLuminanceSource {
impl LuminanceSource for RGBLuminanceSource {
fn getRow(&self, y: usize) -> Vec<u8> {
if y >= self.getHeight() {
panic!("Requested row is outside the image: {}", y);
panic!("Requested row is outside the image: {y}");
}
let width = self.getWidth();

View File

@@ -263,7 +263,7 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
misread_counts[x] += 1;
}
} else {
log::fine(format!("could not read at rotation {}", rotation));
log::fine(format!("could not read at rotation {rotation}"));
}
// try {
// if (decode(bitmap, rotation, expectedText, expectedMetadata, false)) {
@@ -287,7 +287,7 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
try_harder_misread_counts[x] += 1;
}
} else {
log::fine(format!("could not read at rotation {} w/TH", rotation));
log::fine(format!("could not read at rotation {rotation} w/TH"));
}
// try {
// if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) {
@@ -393,8 +393,7 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
);
assert!(
try_harder_counts[x] >= test_rxing_result.get_try_harder_count() as usize,
"Try harder, {}",
label,
"Try harder, {label}",
);
let label = format!(
"Rotation {} degrees: Too many images misread",
@@ -408,8 +407,7 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
assert!(
try_harder_misread_counts[x]
<= test_rxing_result.get_max_try_harder_misreads() as usize,
"Try harder, {}",
label
"Try harder, {label}"
);
}
}
@@ -468,8 +466,7 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
let result_text = result.getText();
if expected_text != result_text {
log::info(format!(
"Content mismatch: expected '{}' but got '{}'{}",
expected_text, result_text, suffix
"Content mismatch: expected '{expected_text}' but got '{result_text}'{suffix}"
));
return Ok(false);
}
@@ -481,8 +478,7 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
let actual_value = result_metadata.get(key);
if actual_value.is_none() || !(value == actual_value.unwrap()) {
log::info(format!(
"Metadata mismatch for key '{:?}': expected '{:?}' but got '{:?}'",
key, value, actual_value
"Metadata mismatch for key '{key:?}': expected '{value:?}' but got '{actual_value:?}'"
));
return Ok(false);
}
@@ -607,6 +603,6 @@ mod log {
}
fn prn(level: &str, data: String) {
println!("{} :: {}", level, data)
println!("{level} :: {data}")
}
}

View File

@@ -149,7 +149,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
for (name, files) in &image_files {
// for (Entry<String,List<Path>> testImageGroup : imageFiles.entrySet()) {
log::fine(format!("Starting Image Group {}", name));
log::fine(format!("Starting Image Group {name}"));
let file_base_name = name; //testImageGroup.getKey();
// let expectedText : String;
@@ -408,7 +408,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
misread_counts[x] += 1;
}
} else {
log::fine(format!("could not read at rotation {}", rotation));
log::fine(format!("could not read at rotation {rotation}"));
}
// try {
// if (decode(bitmap, rotation, expectedText, expectedMetadata, false)) {
@@ -432,7 +432,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
try_harder_misread_counts[x] += 1;
}
} else {
log::fine(format!("could not read at rotation {} w/TH", rotation));
log::fine(format!("could not read at rotation {rotation} w/TH"));
}
// try {
// if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) {
@@ -538,8 +538,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
);
assert!(
try_harder_counts[x] >= test_rxing_result.get_try_harder_count() as usize,
"Try harder, {}",
label,
"Try harder, {label}",
);
let label = format!(
"Rotation {} degrees: Too many images misread",
@@ -553,8 +552,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
assert!(
try_harder_misread_counts[x]
<= test_rxing_result.get_max_try_harder_misreads() as usize,
"Try harder, {}",
label
"Try harder, {label}"
);
}
}
@@ -613,8 +611,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
let result_text = result.getText();
if expected_text != result_text {
log::info(format!(
"Content mismatch: expected '{}' but got '{}'{}",
expected_text, result_text, suffix
"Content mismatch: expected '{expected_text}' but got '{result_text}'{suffix}"
));
return Ok(false);
}
@@ -626,8 +623,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
let actual_value = result_metadata.get(key);
if actual_value.is_none() || !(value == actual_value.unwrap()) {
log::info(format!(
"Metadata mismatch for key '{:?}': expected '{:?}' but got '{:?}'",
key, value, actual_value
"Metadata mismatch for key '{key:?}': expected '{value:?}' but got '{actual_value:?}'"
));
return Ok(false);
}
@@ -804,6 +800,6 @@ mod log {
}
fn prn(level: &str, data: String) {
println!("{} :: {}", level, data)
println!("{level} :: {data}")
}
}