mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
chore: clippy fixes, largely removing unecessary return statements
This commit is contained in:
@@ -10,11 +10,11 @@ pub fn calculate_checksum(contents: &str) -> char {
|
||||
|
||||
let remainder = sum % 127;
|
||||
let diff = 127 - remainder;
|
||||
return if diff != 127 {
|
||||
if diff != 127 {
|
||||
diff as u8 as char
|
||||
} else {
|
||||
0 as char
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ascii_to_numeric(contents: &str) -> String {
|
||||
@@ -28,7 +28,7 @@ pub fn ascii_to_numeric(contents: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
return number;
|
||||
number
|
||||
}
|
||||
|
||||
pub fn numeric_to_ascii(contents: &str) -> Result<String> {
|
||||
@@ -45,21 +45,21 @@ pub fn numeric_to_ascii(contents: &str) -> Result<String> {
|
||||
let first = contents.chars().nth(i).unwrap() as u8;
|
||||
let second = contents.chars().nth(i + 1).unwrap() as u8;
|
||||
|
||||
if second == 88 && first >= 48 && first <= 57 {
|
||||
if second == 88 && (48..=57).contains(&first) {
|
||||
ascii.push((17 + first - 48) as char);
|
||||
} else if second >= 48 && second <= 57 && first >= 48 && first <= 57 {
|
||||
} else if (48..=57).contains(&second) && (48..=57).contains(&first) {
|
||||
ascii.push((27 + (first - 48) * 10 + (second - 48)) as char);
|
||||
} else {
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Input contains an invalid character around position {}.",
|
||||
i.to_string()
|
||||
i
|
||||
)));
|
||||
}
|
||||
|
||||
i += 2;
|
||||
}
|
||||
|
||||
return Ok(ascii);
|
||||
Ok(ascii)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -122,14 +122,12 @@ impl OneDReader for TelepenReader {
|
||||
// Narrow white: .
|
||||
pattern[patternLength] = 0;
|
||||
}
|
||||
} else if isBlack {
|
||||
// Wide black: BBB
|
||||
pattern[patternLength] = 3;
|
||||
} else {
|
||||
if isBlack {
|
||||
// Wide black: BBB
|
||||
pattern[patternLength] = 3;
|
||||
} else {
|
||||
// Wide white: ...
|
||||
pattern[patternLength] = 2;
|
||||
}
|
||||
// Wide white: ...
|
||||
pattern[patternLength] = 2;
|
||||
}
|
||||
|
||||
patternLength += 1;
|
||||
@@ -356,7 +354,7 @@ impl TelepenReader {
|
||||
|
||||
j = 0;
|
||||
|
||||
let median = minBar as f32 + maxBar as f32 / 2.0;
|
||||
let median = minBar + maxBar / 2.0;
|
||||
let mut passed = true;
|
||||
|
||||
// First 10 items must be:
|
||||
@@ -410,13 +408,13 @@ impl TelepenReader {
|
||||
i = start + 20;
|
||||
|
||||
while i < self.counterLength {
|
||||
if (self.counters[i] as f32) > (maxBar as f32 * (1.0 + TOLERANCE)) {
|
||||
if (self.counters[i] as f32) > (maxBar * (1.0 + TOLERANCE)) {
|
||||
return Ok((i - 1) as u32);
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
return Ok((self.counterLength - 1) as u32);
|
||||
Ok((self.counterLength - 1) as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
hints.get(&EncodeHintType::TELEPEN_AS_NUMERIC),
|
||||
Some(EncodeHintValue::TelepenAsNumeric(true))
|
||||
) {
|
||||
decodedContents = telepen_common::numeric_to_ascii(&contents)?;
|
||||
decodedContents = telepen_common::numeric_to_ascii(contents)?;
|
||||
}
|
||||
|
||||
// Calculate the checksum character
|
||||
@@ -61,9 +61,9 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
// Content
|
||||
for c in decodedContents.chars() {
|
||||
if c as u32 > 127 {
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Telepen only supports ASCII characters."
|
||||
)));
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"Telepen only supports ASCII characters.".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
binary = self.add_to_binary(c, binary)
|
||||
@@ -129,9 +129,9 @@ impl OneDimensionalCodeWriter for TelepenWriter {
|
||||
resultPosition += 4;
|
||||
}
|
||||
"0" => {
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Invalid bit combination!"
|
||||
)));
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"Invalid bit combination!".to_string(),
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
// B... (B.)* B...
|
||||
@@ -185,7 +185,7 @@ impl TelepenWriter {
|
||||
// of 1s in the 8 bits.
|
||||
bits[7] = oneCount % 2 != 0;
|
||||
|
||||
return bits;
|
||||
bits
|
||||
}
|
||||
|
||||
fn add_to_binary(&self, c: char, mut binary: String) -> String {
|
||||
@@ -196,7 +196,7 @@ impl TelepenWriter {
|
||||
binary.push(if bits[i] { '1' } else { '0' });
|
||||
}
|
||||
|
||||
return binary;
|
||||
binary
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user