mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-28 05:12:34 +00:00
Use thiserror for error handling with less boilerplate
This commit is contained in:
@@ -44,12 +44,12 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
let firstChar = contents
|
||||
.chars()
|
||||
.next()
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?
|
||||
.to_ascii_uppercase();
|
||||
let lastChar = contents
|
||||
.chars()
|
||||
.nth(contents.chars().count() - 1)
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?
|
||||
.to_ascii_uppercase();
|
||||
let startsNormal = CodaBarReader::arrayContains(&START_END_CHARS, firstChar);
|
||||
let endsNormal = CodaBarReader::arrayContains(&START_END_CHARS, lastChar);
|
||||
@@ -57,7 +57,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
let endsAlt = CodaBarReader::arrayContains(&ALT_START_END_CHARS, lastChar);
|
||||
if startsNormal {
|
||||
if !endsNormal {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Invalid start/end guards: {contents}"
|
||||
)));
|
||||
}
|
||||
@@ -65,7 +65,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
contents.to_owned()
|
||||
} else if startsAlt {
|
||||
if !endsAlt {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Invalid start/end guards: {contents}"
|
||||
)));
|
||||
}
|
||||
@@ -74,7 +74,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
} else {
|
||||
// Doesn't start with a guard
|
||||
if endsNormal || endsAlt {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Invalid start/end guards: {contents}"
|
||||
)));
|
||||
}
|
||||
@@ -94,7 +94,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
) {
|
||||
resultLength += 10;
|
||||
} else {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Cannot encode : '{ch}'"
|
||||
)));
|
||||
}
|
||||
@@ -109,7 +109,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
let mut c = contents
|
||||
.chars()
|
||||
.nth(index)
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?
|
||||
.to_ascii_uppercase();
|
||||
if index == 0 || index == contents.chars().count() - 1 {
|
||||
// The start/end chars are not in the CodaBarReader.ALPHABET.
|
||||
|
||||
Reference in New Issue
Block a user