mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
rename helper methods
This commit is contained in:
@@ -34,7 +34,7 @@ impl BitMatrixParser {
|
||||
pub fn new(bitMatrix: &BitMatrix) -> Result<Self, Exceptions> {
|
||||
let dimension = bitMatrix.getHeight();
|
||||
if !(8..=144).contains(&dimension) || (dimension & 0x01) != 0 {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
|
||||
let version = Self::readVersion(bitMatrix)?;
|
||||
@@ -178,7 +178,7 @@ impl BitMatrixParser {
|
||||
}
|
||||
|
||||
if resultOffset != self.version.getTotalCodewords() as usize {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
@@ -456,7 +456,7 @@ impl BitMatrixParser {
|
||||
let symbolSizeColumns = version.getSymbolSizeColumns();
|
||||
|
||||
if bitMatrix.getHeight() != symbolSizeRows {
|
||||
return Err(Exceptions::illegalArgument(
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"Dimension of bitMatrix must match the version size",
|
||||
));
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ impl DataBlock {
|
||||
}
|
||||
|
||||
if rawCodewordsOffset != rawCodewords.len() {
|
||||
return Err(Exceptions::illegalArgumentEmpty());
|
||||
return Err(Exceptions::illegalArgument);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
|
||||
@@ -158,7 +158,7 @@ pub fn decode(bytes: &[u8], is_flipped: bool) -> Result<DecoderRXingResult, Exce
|
||||
isECIencoded = true; // ECI detection only, atm continue decoding as ASCII
|
||||
mode = Mode::ASCII_ENCODE;
|
||||
}
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
_ => return Err(Exceptions::format),
|
||||
}
|
||||
|
||||
if !(mode != Mode::PAD_ENCODE && bits.available() > 0) {
|
||||
@@ -225,14 +225,14 @@ fn decodeAsciiSegment(
|
||||
loop {
|
||||
let mut oneByte = bits.readBits(8)?;
|
||||
match oneByte {
|
||||
0 => return Err(Exceptions::formatEmpty()),
|
||||
0 => return Err(Exceptions::format),
|
||||
1..=128 => {
|
||||
// ASCII data (ASCII value + 1)
|
||||
if upperShift {
|
||||
oneByte += 128;
|
||||
//upperShift = false;
|
||||
}
|
||||
result.append_char(char::from_u32(oneByte - 1).ok_or(Exceptions::parseEmpty())?);
|
||||
result.append_char(char::from_u32(oneByte - 1).ok_or(Exceptions::parse)?);
|
||||
return Ok(Mode::ASCII_ENCODE);
|
||||
}
|
||||
129 => return Ok(Mode::PAD_ENCODE), // Pad
|
||||
@@ -278,7 +278,7 @@ fn decodeAsciiSegment(
|
||||
if !firstCodeword
|
||||
// Must be first ISO 16022:2006 5.6.1
|
||||
{
|
||||
return Err(Exceptions::format(
|
||||
return Err(Exceptions::formatWith(
|
||||
"structured append tag must be first code word",
|
||||
));
|
||||
}
|
||||
@@ -331,7 +331,7 @@ fn decodeAsciiSegment(
|
||||
// Not to be used in ASCII encodation
|
||||
// but work around encoders that end with 254, latch back to ASCII
|
||||
if oneByte != 254 || bits.available() != 0 {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -385,25 +385,22 @@ fn decodeC40Segment(
|
||||
let c40char = C40_BASIC_SET_CHARS[cValue as usize];
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(c40char as u32 + 128)
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
char::from_u32(c40char as u32 + 128).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(c40char);
|
||||
}
|
||||
} else {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 128).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
result.append_char(char::from_u32(cValue + 128).ok_or(Exceptions::parse)?);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(char::from_u32(cValue).ok_or(Exceptions::parseEmpty())?);
|
||||
result.append_char(char::from_u32(cValue).ok_or(Exceptions::parse)?);
|
||||
}
|
||||
shift = 0;
|
||||
}
|
||||
@@ -412,8 +409,7 @@ fn decodeC40Segment(
|
||||
let c40char = C40_SHIFT2_SET_CHARS[cValue as usize];
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(c40char as u32 + 128)
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
char::from_u32(c40char as u32 + 128).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
@@ -432,26 +428,22 @@ fn decodeC40Segment(
|
||||
upperShift = true
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
_ => return Err(Exceptions::format),
|
||||
}
|
||||
}
|
||||
shift = 0;
|
||||
}
|
||||
3 => {
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 224).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
result.append_char(char::from_u32(cValue + 224).ok_or(Exceptions::parse)?);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 96).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
result.append_char(char::from_u32(cValue + 96).ok_or(Exceptions::parse)?);
|
||||
}
|
||||
shift = 0;
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
_ => return Err(Exceptions::format),
|
||||
}
|
||||
}
|
||||
if bits.available() == 0 {
|
||||
@@ -500,25 +492,22 @@ fn decodeTextSegment(
|
||||
let textChar = TEXT_BASIC_SET_CHARS[cValue as usize];
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(textChar as u32 + 128)
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
char::from_u32(textChar as u32 + 128).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(textChar);
|
||||
}
|
||||
} else {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 128).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
result.append_char(char::from_u32(cValue + 128).ok_or(Exceptions::parse)?);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(char::from_u32(cValue).ok_or(Exceptions::parseEmpty())?);
|
||||
result.append_char(char::from_u32(cValue).ok_or(Exceptions::parse)?);
|
||||
}
|
||||
shift = 0;
|
||||
}
|
||||
@@ -529,8 +518,7 @@ fn decodeTextSegment(
|
||||
let textChar = TEXT_SHIFT2_SET_CHARS[cValue as usize];
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(textChar as u32 + 128)
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
char::from_u32(textChar as u32 + 128).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
@@ -549,7 +537,7 @@ fn decodeTextSegment(
|
||||
upperShift = true
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
_ => return Err(Exceptions::format),
|
||||
}
|
||||
}
|
||||
shift = 0;
|
||||
@@ -559,8 +547,7 @@ fn decodeTextSegment(
|
||||
let textChar = TEXT_SHIFT3_SET_CHARS[cValue as usize];
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(textChar as u32 + 128)
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
char::from_u32(textChar as u32 + 128).ok_or(Exceptions::parse)?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
@@ -568,11 +555,11 @@ fn decodeTextSegment(
|
||||
}
|
||||
shift = 0;
|
||||
} else {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
_ => return Err(Exceptions::format),
|
||||
}
|
||||
}
|
||||
if bits.available() == 0 {
|
||||
@@ -638,16 +625,12 @@ fn decodeAnsiX12Segment(
|
||||
_ => {
|
||||
if cValue < 14 {
|
||||
// 0 - 9
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 44).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
result.append_char(char::from_u32(cValue + 44).ok_or(Exceptions::parse)?);
|
||||
} else if cValue < 40 {
|
||||
// A - Z
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 51).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
result.append_char(char::from_u32(cValue + 51).ok_or(Exceptions::parse)?);
|
||||
} else {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -702,7 +685,7 @@ fn decodeEdifactSegment(
|
||||
// no 1 in the leading (6th) bit
|
||||
edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value
|
||||
}
|
||||
result.append_char(char::from_u32(edifactValue).ok_or(Exceptions::parseEmpty())?);
|
||||
result.append_char(char::from_u32(edifactValue).ok_or(Exceptions::parse)?);
|
||||
}
|
||||
|
||||
if bits.available() == 0 {
|
||||
@@ -747,7 +730,7 @@ fn decodeBase256Segment(
|
||||
// Have seen this particular error in the wild, such as at
|
||||
// http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
|
||||
if bits.available() < 8 {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
*byte = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8;
|
||||
codewordPosition += 1;
|
||||
@@ -755,7 +738,7 @@ fn decodeBase256Segment(
|
||||
result.append_string(
|
||||
&encoding::all::ISO_8859_1
|
||||
.decode(&bytes, encoding::DecoderTrap::Strict)
|
||||
.map_err(|e| Exceptions::parse(e))?,
|
||||
.map_err(|e| Exceptions::parseWith(e))?,
|
||||
);
|
||||
byteSegments.push(bytes);
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ impl Version {
|
||||
numColumns: u32,
|
||||
) -> Result<&'static Version, Exceptions> {
|
||||
if (numRows & 0x01) != 0 || (numColumns & 0x01) != 0 {
|
||||
return Err(Exceptions::formatEmpty());
|
||||
return Err(Exceptions::format);
|
||||
}
|
||||
|
||||
for version in VERSIONS.iter() {
|
||||
@@ -114,7 +114,7 @@ impl Version {
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::formatEmpty())
|
||||
Err(Exceptions::format)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user