rename helper methods

This commit is contained in:
Vukašin Stepanović
2023-02-15 12:52:59 +00:00
parent bfcdb397ad
commit 935519ced5
133 changed files with 858 additions and 1044 deletions

View File

@@ -33,7 +33,7 @@ impl OneDimensionalCodeWriter for Code39Writer {
let mut contents = contents.to_owned();
let mut length = contents.chars().count();
if length > 80 {
return Err(Exceptions::illegalArgument(format!(
return Err(Exceptions::illegalArgumentWith(format!(
"Requested contents should be less than 80 digits long, but got {length}"
)));
}
@@ -47,14 +47,14 @@ impl OneDimensionalCodeWriter for Code39Writer {
contents
.chars()
.nth(i)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
.ok_or(Exceptions::indexOutOfBounds)?,
)
.is_none()
{
contents = Self::tryToConvertToExtendedMode(&contents)?;
length = contents.chars().count();
if length > 80 {
return Err(Exceptions::illegalArgument(format!("Requested contents should be less than 80 digits long, but got {length} (extended full ASCII mode)")));
return Err(Exceptions::illegalArgumentWith(format!("Requested contents should be less than 80 digits long, but got {length} (extended full ASCII mode)")));
}
break;
}
@@ -70,7 +70,7 @@ impl OneDimensionalCodeWriter for Code39Writer {
pos += Self::appendPattern(&mut result, pos as usize, &narrowWhite, false);
//append next character to byte matrix
for i in 0..length {
let Some(indexInString) = Code39Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::indexOutOfBoundsEmpty())?) else {
let Some(indexInString) = Code39Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::indexOutOfBounds)?) else {
continue;
};
Self::toIntArray(
@@ -117,56 +117,56 @@ impl Code39Writer {
extendedContent.push('$');
extendedContent.push(
char::from_u32('A' as u32 + (character as u32 - 1))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else if character < ' ' {
extendedContent.push('%');
extendedContent.push(
char::from_u32('A' as u32 + (character as u32 - 27))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else if character <= ',' || character == '/' || character == ':' {
extendedContent.push('/');
extendedContent.push(
char::from_u32('A' as u32 + (character as u32 - 33))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else if character <= '9' {
extendedContent.push(
char::from_u32('0' as u32 + (character as u32 - 48))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else if character <= '?' {
extendedContent.push('%');
extendedContent.push(
char::from_u32('F' as u32 + (character as u32 - 59))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else if character <= 'Z' {
extendedContent.push(
char::from_u32('A' as u32 + (character as u32 - 65))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else if character <= '_' {
extendedContent.push('%');
extendedContent.push(
char::from_u32('K' as u32 + (character as u32 - 91))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else if character <= 'z' {
extendedContent.push('+');
extendedContent.push(
char::from_u32('A' as u32 + (character as u32 - 97))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else if character as u32 <= 127 {
extendedContent.push('%');
extendedContent.push(
char::from_u32('P' as u32 + (character as u32 - 123))
.ok_or(Exceptions::parseEmpty())?,
.ok_or(Exceptions::parse)?,
);
} else {
return Err(Exceptions::illegalArgument(format!(
return Err(Exceptions::illegalArgumentWith(format!(
"Requested content contains a non-encodable character: '{character}'"
)));
}