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

@@ -31,12 +31,12 @@ impl Encoder for ASCIIEncoder {
.getMessage()
.chars()
.nth(context.pos as usize)
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
context
.getMessage()
.chars()
.nth(context.pos as usize + 1)
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
)? as u8);
context.pos += 2;
} else {
@@ -73,9 +73,7 @@ impl Encoder for ASCIIEncoder {
}
_ => {
return Err(Exceptions::IllegalStateException(Some(format!(
"Illegal mode: {newMode}"
))));
return Err(Exceptions::illegalState(format!("Illegal mode: {newMode}")));
}
}
} else if high_level_encoder::isExtendedASCII(c) {
@@ -104,9 +102,9 @@ impl ASCIIEncoder {
let num = (digit1 as u8 - 48) * 10 + (digit2 as u8 - 48);
Ok((num + 130) as char)
} else {
Err(Exceptions::IllegalArgumentException(Some(format!(
Err(Exceptions::illegalArgument(format!(
"not digits: {digit1}{digit2}"
))))
)))
}
}
}