refactor to use exception helper factories

This commit is contained in:
Vukašin Stepanović
2023-02-15 10:46:13 +00:00
parent 3e27279dc8
commit 722ce78fd0
132 changed files with 966 additions and 1132 deletions

View File

@@ -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];