mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
refactor to use exception helper factories
This commit is contained in:
@@ -32,14 +32,14 @@ impl OneDimensionalCodeWriter for ITFWriter {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
let length = contents.chars().count();
|
||||
if length % 2 != 0 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"The length of the input should be even".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
if length > 80 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"Requested contents should be less than 80 digits long, but got {length}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
|
||||
Self::checkNumeric(contents)?;
|
||||
@@ -51,15 +51,15 @@ impl OneDimensionalCodeWriter for ITFWriter {
|
||||
let one = contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
||||
.ok_or(Exceptions::parseEmpty())? as usize;
|
||||
let two = contents
|
||||
.chars()
|
||||
.nth(i + 1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
||||
.ok_or(Exceptions::parseEmpty())? as usize;
|
||||
let mut encoding = [0; 10];
|
||||
for j in 0..5 {
|
||||
encoding[2 * j] = PATTERNS[one][j];
|
||||
|
||||
Reference in New Issue
Block a user