mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
refactor to use exception helper factories
This commit is contained in:
@@ -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::illegalArgument(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
|
||||
@@ -48,7 +48,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
||||
|
||||
for i in 0..length {
|
||||
// for (int i = 0; i < length; i++) {
|
||||
let Some(indexInString) = Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::IndexOutOfBoundsException(None))?) else {panic!("alphabet")};
|
||||
let Some(indexInString) = Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::indexOutOfBoundsEmpty())?) else {panic!("alphabet")};
|
||||
pos += Self::appendPattern(
|
||||
&mut result,
|
||||
pos,
|
||||
@@ -65,7 +65,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
||||
Code93Reader::ALPHABET_STRING
|
||||
.chars()
|
||||
.nth(check1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||
);
|
||||
|
||||
let check2 = Self::computeChecksumIndex(&contents, 15);
|
||||
@@ -157,14 +157,14 @@ impl Code93Writer {
|
||||
extendedContent.push('a');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + character as u32 - 1)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else if character as u32 <= 31 {
|
||||
// ESC - US: (%)A - (%)E
|
||||
extendedContent.push('b');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + character as u32 - 27)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else if character == ' ' || character == '$' || character == '%' || character == '+' {
|
||||
// space $ % +
|
||||
@@ -174,7 +174,7 @@ impl Code93Writer {
|
||||
extendedContent.push('c');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + character as u32 - '!' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else if character <= '9' {
|
||||
extendedContent.push(character);
|
||||
@@ -186,7 +186,7 @@ impl Code93Writer {
|
||||
extendedContent.push('b');
|
||||
extendedContent.push(
|
||||
char::from_u32('F' as u32 + character as u32 - ';' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else if character == '@' {
|
||||
// @: (%)V
|
||||
@@ -199,7 +199,7 @@ impl Code93Writer {
|
||||
extendedContent.push('b');
|
||||
extendedContent.push(
|
||||
char::from_u32('K' as u32 + character as u32 - '[' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else if character == '`' {
|
||||
// `: (%)W
|
||||
@@ -209,19 +209,19 @@ impl Code93Writer {
|
||||
extendedContent.push('d');
|
||||
extendedContent.push(
|
||||
char::from_u32('A' as u32 + character as u32 - 'a' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else if character as u32 <= 127 {
|
||||
// { - DEL: (%)P - (%)T
|
||||
extendedContent.push('b');
|
||||
extendedContent.push(
|
||||
char::from_u32('P' as u32 + character as u32 - '{' as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"Requested content contains a non-encodable character: '{character}'"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user