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:
@@ -67,14 +67,12 @@ impl ECIInput for MinimalECIInput {
|
||||
*/
|
||||
fn charAt(&self, index: usize) -> Result<char, Exceptions> {
|
||||
if index >= self.length() {
|
||||
return Err(Exceptions::IndexOutOfBoundsException(Some(
|
||||
index.to_string(),
|
||||
)));
|
||||
return Err(Exceptions::indexOutOfBounds(index.to_string()));
|
||||
}
|
||||
if self.isECI(index as u32)? {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"value at {index} is not a character but an ECI"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
if self.isFNC1(index)? {
|
||||
Ok(self.fnc1 as u8 as char)
|
||||
@@ -105,15 +103,15 @@ impl ECIInput for MinimalECIInput {
|
||||
*/
|
||||
fn subSequence(&self, start: usize, end: usize) -> Result<Vec<char>, Exceptions> {
|
||||
if start > end || end > self.length() {
|
||||
return Err(Exceptions::IndexOutOfBoundsException(None));
|
||||
return Err(Exceptions::indexOutOfBoundsEmpty());
|
||||
}
|
||||
let mut result = String::new();
|
||||
for i in start..end {
|
||||
// for (int i = start; i < end; i++) {
|
||||
if self.isECI(i as u32)? {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"value at {i} is not a character but an ECI"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
result.push_str(&self.charAt(i)?.to_string());
|
||||
}
|
||||
@@ -133,7 +131,7 @@ impl ECIInput for MinimalECIInput {
|
||||
*/
|
||||
fn isECI(&self, index: u32) -> Result<bool, Exceptions> {
|
||||
if index >= self.length() as u32 {
|
||||
return Err(Exceptions::IndexOutOfBoundsException(None));
|
||||
return Err(Exceptions::indexOutOfBoundsEmpty());
|
||||
}
|
||||
Ok(self.bytes[index as usize] > 255) // && self.bytes[index as usize] <= u16::MAX)
|
||||
}
|
||||
@@ -158,12 +156,12 @@ impl ECIInput for MinimalECIInput {
|
||||
*/
|
||||
fn getECIValue(&self, index: usize) -> Result<i32, Exceptions> {
|
||||
if index >= self.length() {
|
||||
return Err(Exceptions::IndexOutOfBoundsException(None));
|
||||
return Err(Exceptions::indexOutOfBoundsEmpty());
|
||||
}
|
||||
if !self.isECI(index as u32)? {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"value at {index} is not an ECI but a character"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
Ok((self.bytes[index] as u32 - 256) as i32)
|
||||
}
|
||||
@@ -250,7 +248,7 @@ impl MinimalECIInput {
|
||||
*/
|
||||
pub fn isFNC1(&self, index: usize) -> Result<bool, Exceptions> {
|
||||
if index >= self.length() {
|
||||
return Err(Exceptions::IndexOutOfBoundsException(None));
|
||||
return Err(Exceptions::indexOutOfBoundsEmpty());
|
||||
}
|
||||
Ok(self.bytes[index] == 1000)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user