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:
@@ -154,9 +154,9 @@ const ALOG: [u32; 255] = {
|
||||
*/
|
||||
pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String, Exceptions> {
|
||||
if codewords.chars().count() != symbolInfo.getDataCapacity() as usize {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"The number of codewords does not match the selected symbol".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
let mut sb = String::with_capacity(
|
||||
(symbolInfo.getDataCapacity() + symbolInfo.getErrorCodewords()) as usize,
|
||||
@@ -185,7 +185,7 @@ pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String,
|
||||
codewords
|
||||
.chars()
|
||||
.nth(d)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||
);
|
||||
|
||||
d += blockCount;
|
||||
@@ -198,12 +198,12 @@ pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String,
|
||||
let (char_index, replace_char) = sb
|
||||
.char_indices()
|
||||
.nth(symbolInfo.getDataCapacity() as usize + e)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||
sb.replace_range(
|
||||
char_index..(replace_char.len_utf8()),
|
||||
&ecc.chars()
|
||||
.nth(pos)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
.to_string(),
|
||||
);
|
||||
// sb.setCharAt(symbolInfo.getDataCapacity() + e, ecc.charAt(pos));
|
||||
@@ -228,9 +228,9 @@ fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptio
|
||||
}
|
||||
}
|
||||
if table < 0 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"Illegal number of error correction codewords specified: {numECWords}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
let poly = &FACTORS[table as usize];
|
||||
let mut ecc = vec![0 as char; numECWords];
|
||||
@@ -244,21 +244,21 @@ fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptio
|
||||
^ codewords
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as usize;
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as usize;
|
||||
for k in (1..numECWords).rev() {
|
||||
// for (int k = numECWords - 1; k > 0; k--) {
|
||||
if m != 0 && poly[k] != 0 {
|
||||
ecc[k] = char::from_u32(
|
||||
ecc[k - 1] as u32 ^ ALOG[(LOG[m] + LOG[poly[k] as usize]) as usize % 255],
|
||||
)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||
} else {
|
||||
ecc[k] = ecc[k - 1];
|
||||
}
|
||||
}
|
||||
if m != 0 && poly[0] != 0 {
|
||||
ecc[0] = char::from_u32(ALOG[(LOG[m] + LOG[poly[0] as usize]) as usize % 255])
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||
} else {
|
||||
ecc[0] = 0 as char;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user