mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
refactor to use exception helper factories
This commit is contained in:
@@ -105,7 +105,7 @@ impl Reader for DataMatrixReader {
|
||||
DECODER.decode(&bits)?
|
||||
}
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFoundEmpty());
|
||||
};
|
||||
|
||||
// decoderRXingResult = DECODER.decode(detectorRXingResult.getBits())?;
|
||||
@@ -181,10 +181,10 @@ impl DataMatrixReader {
|
||||
*/
|
||||
fn extractPureBits(&self, image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
||||
let Some(leftTopBlack) = image.getTopLeftOnBit() else {
|
||||
return Err(Exceptions::NotFoundException(None))
|
||||
return Err(Exceptions::notFoundEmpty())
|
||||
};
|
||||
let Some(rightBottomBlack) = image.getBottomRightOnBit()else {
|
||||
return Err(Exceptions::NotFoundException(None))
|
||||
return Err(Exceptions::notFoundEmpty())
|
||||
};
|
||||
|
||||
let moduleSize = Self::moduleSize(&leftTopBlack, image)?;
|
||||
@@ -197,7 +197,7 @@ impl DataMatrixReader {
|
||||
let matrixWidth = (right as i32 - left as i32 + 1) / moduleSize as i32;
|
||||
let matrixHeight = (bottom as i32 - top as i32 + 1) / moduleSize as i32;
|
||||
if matrixWidth <= 0 || matrixHeight <= 0 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFoundEmpty());
|
||||
// throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
@@ -234,12 +234,12 @@ impl DataMatrixReader {
|
||||
x += 1;
|
||||
}
|
||||
if x == width {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFoundEmpty());
|
||||
}
|
||||
|
||||
let moduleSize = x - leftTopBlack[0];
|
||||
if moduleSize == 0 {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
return Err(Exceptions::notFoundEmpty());
|
||||
}
|
||||
|
||||
Ok(moduleSize)
|
||||
|
||||
@@ -60,21 +60,21 @@ impl Writer for DataMatrixWriter {
|
||||
hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||
if contents.is_empty() {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"Found empty contents".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
|
||||
if format != &BarcodeFormat::DATA_MATRIX {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"Can only encode DATA_MATRIX, but got {format:?}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
|
||||
if width < 0 || height < 0 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"Requested dimensions can't be negative: {width}x{height}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
|
||||
// Try to get force shape & min / max size
|
||||
@@ -123,7 +123,7 @@ impl Writer for DataMatrixWriter {
|
||||
if hasEncodingHint {
|
||||
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
|
||||
hints.get(&EncodeHintType::CHARACTER_SET) else {
|
||||
return Err(Exceptions::IllegalArgumentException(Some("charset does not exist".to_owned())))
|
||||
return Err(Exceptions::illegalArgument("charset does not exist".to_owned()))
|
||||
};
|
||||
charset = encoding::label::encoding_from_whatwg_label(char_set_name);
|
||||
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
|
||||
@@ -157,7 +157,7 @@ impl Writer for DataMatrixWriter {
|
||||
|
||||
let symbol_lookup = SymbolInfoLookup::new();
|
||||
let Some(symbolInfo) = symbol_lookup.lookup_with_codewords_shape_size_fail(encoded.chars().count() as u32, *shape, &minSize, &maxSize, true)? else {
|
||||
return Err(Exceptions::NotFoundException(Some("symbol info is bad".to_owned())))
|
||||
return Err(Exceptions::notFound("symbol info is bad".to_owned()))
|
||||
};
|
||||
|
||||
//2. step: ECC generation
|
||||
|
||||
@@ -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::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
|
||||
let version = Self::readVersion(bitMatrix)?;
|
||||
@@ -178,7 +178,7 @@ impl BitMatrixParser {
|
||||
}
|
||||
|
||||
if resultOffset != self.version.getTotalCodewords() as usize {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
@@ -456,9 +456,9 @@ impl BitMatrixParser {
|
||||
let symbolSizeColumns = version.getSymbolSizeColumns();
|
||||
|
||||
if bitMatrix.getHeight() != symbolSizeRows {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"Dimension of bitMatrix must match the version size".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
|
||||
let dataRegionSizeRows = version.getDataRegionSizeRows();
|
||||
|
||||
@@ -138,7 +138,7 @@ impl DataBlock {
|
||||
}
|
||||
|
||||
if rawCodewordsOffset != rawCodewords.len() {
|
||||
return Err(Exceptions::IllegalArgumentException(None));
|
||||
return Err(Exceptions::illegalArgumentEmpty());
|
||||
}
|
||||
|
||||
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::FormatException(None)),
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
}
|
||||
|
||||
if !(mode != Mode::PAD_ENCODE && bits.available() > 0) {
|
||||
@@ -225,16 +225,14 @@ fn decodeAsciiSegment(
|
||||
loop {
|
||||
let mut oneByte = bits.readBits(8)?;
|
||||
match oneByte {
|
||||
0 => return Err(Exceptions::FormatException(None)),
|
||||
0 => return Err(Exceptions::formatEmpty()),
|
||||
1..=128 => {
|
||||
// ASCII data (ASCII value + 1)
|
||||
if upperShift {
|
||||
oneByte += 128;
|
||||
//upperShift = false;
|
||||
}
|
||||
result.append_char(
|
||||
char::from_u32(oneByte - 1).ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
result.append_char(char::from_u32(oneByte - 1).ok_or(Exceptions::parseEmpty())?);
|
||||
return Ok(Mode::ASCII_ENCODE);
|
||||
}
|
||||
129 => return Ok(Mode::PAD_ENCODE), // Pad
|
||||
@@ -280,9 +278,9 @@ fn decodeAsciiSegment(
|
||||
if !firstCodeword
|
||||
// Must be first ISO 16022:2006 5.6.1
|
||||
{
|
||||
return Err(Exceptions::FormatException(Some(
|
||||
return Err(Exceptions::format(
|
||||
"structured append tag must be first code word".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
parse_structured_append(bits, &mut sai)?;
|
||||
firstFNC1Position = 5;
|
||||
@@ -333,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::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -388,26 +386,24 @@ fn decodeC40Segment(
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(c40char as u32 + 128)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(c40char);
|
||||
}
|
||||
} else {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 128).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(cValue + 128).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(
|
||||
char::from_u32(cValue).ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
result.append_char(char::from_u32(cValue).ok_or(Exceptions::parseEmpty())?);
|
||||
}
|
||||
shift = 0;
|
||||
}
|
||||
@@ -417,7 +413,7 @@ fn decodeC40Segment(
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(c40char as u32 + 128)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
@@ -436,7 +432,7 @@ fn decodeC40Segment(
|
||||
upperShift = true
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::FormatException(None)),
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
}
|
||||
}
|
||||
shift = 0;
|
||||
@@ -444,18 +440,18 @@ fn decodeC40Segment(
|
||||
3 => {
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 224).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(cValue + 224).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 96).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(cValue + 96).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
}
|
||||
shift = 0;
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::FormatException(None)),
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
}
|
||||
}
|
||||
if bits.available() == 0 {
|
||||
@@ -505,26 +501,24 @@ fn decodeTextSegment(
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(textChar as u32 + 128)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(textChar);
|
||||
}
|
||||
} else {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 128).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(cValue + 128).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result.append_char(
|
||||
char::from_u32(cValue).ok_or(Exceptions::ParseException(None))?,
|
||||
);
|
||||
result.append_char(char::from_u32(cValue).ok_or(Exceptions::parseEmpty())?);
|
||||
}
|
||||
shift = 0;
|
||||
}
|
||||
@@ -536,7 +530,7 @@ fn decodeTextSegment(
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(textChar as u32 + 128)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
@@ -555,7 +549,7 @@ fn decodeTextSegment(
|
||||
upperShift = true
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::FormatException(None)),
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
}
|
||||
}
|
||||
shift = 0;
|
||||
@@ -566,7 +560,7 @@ fn decodeTextSegment(
|
||||
if upperShift {
|
||||
result.append_char(
|
||||
char::from_u32(textChar as u32 + 128)
|
||||
.ok_or(Exceptions::ParseException(None))?,
|
||||
.ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
upperShift = false;
|
||||
} else {
|
||||
@@ -574,11 +568,11 @@ fn decodeTextSegment(
|
||||
}
|
||||
shift = 0;
|
||||
} else {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
_ => return Err(Exceptions::FormatException(None)),
|
||||
_ => return Err(Exceptions::formatEmpty()),
|
||||
}
|
||||
}
|
||||
if bits.available() == 0 {
|
||||
@@ -645,15 +639,15 @@ fn decodeAnsiX12Segment(
|
||||
if cValue < 14 {
|
||||
// 0 - 9
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 44).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(cValue + 44).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else if cValue < 40 {
|
||||
// A - Z
|
||||
result.append_char(
|
||||
char::from_u32(cValue + 51).ok_or(Exceptions::ParseException(None))?,
|
||||
char::from_u32(cValue + 51).ok_or(Exceptions::parseEmpty())?,
|
||||
);
|
||||
} else {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -708,8 +702,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::ParseException(None))?);
|
||||
result.append_char(char::from_u32(edifactValue).ok_or(Exceptions::parseEmpty())?);
|
||||
}
|
||||
|
||||
if bits.available() == 0 {
|
||||
@@ -746,7 +739,7 @@ fn decodeBase256Segment(
|
||||
// We're seeing NegativeArraySizeException errors from users.
|
||||
// but we shouldn't in rust because it's unsigned
|
||||
// if count < 0 {
|
||||
// return Err(Exceptions::FormatException(None));
|
||||
// return Err(Exceptions::formatEmpty());
|
||||
// }
|
||||
|
||||
let mut bytes = vec![0u8; count as usize];
|
||||
@@ -754,7 +747,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::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
*byte = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8;
|
||||
codewordPosition += 1;
|
||||
@@ -762,7 +755,7 @@ fn decodeBase256Segment(
|
||||
result.append_string(
|
||||
&encoding::all::ISO_8859_1
|
||||
.decode(&bytes, encoding::DecoderTrap::Strict)
|
||||
.map_err(|e| Exceptions::ParseException(Some(e.to_string())))?,
|
||||
.map_err(|e| Exceptions::parse(e.to_string()))?,
|
||||
);
|
||||
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::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
|
||||
for version in VERSIONS.iter() {
|
||||
@@ -114,7 +114,7 @@ impl Version {
|
||||
}
|
||||
}
|
||||
|
||||
Err(Exceptions::FormatException(None))
|
||||
Err(Exceptions::formatEmpty())
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,9 +53,7 @@ impl<'a> Detector<'_> {
|
||||
if let Some(point) = self.correctTopRight(&points) {
|
||||
points[3] = point;
|
||||
} else {
|
||||
return Err(Exceptions::NotFoundException(Some(
|
||||
"point 4 unfound".to_owned(),
|
||||
)));
|
||||
return Err(Exceptions::notFound("point 4 unfound".to_owned()));
|
||||
}
|
||||
// points[3] = self.correctTopRight(&points);
|
||||
// if points[3] == null {
|
||||
|
||||
@@ -254,7 +254,7 @@ fn Scan(
|
||||
));
|
||||
}
|
||||
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFoundEmpty())
|
||||
}
|
||||
|
||||
pub fn detect(
|
||||
@@ -359,6 +359,6 @@ pub fn detect(
|
||||
}
|
||||
|
||||
// #ifndef __cpp_impl_coroutine
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
Err(Exceptions::notFoundEmpty())
|
||||
// #endif
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ impl RegressionLine for DMRegressionLine {
|
||||
|
||||
fn add(&mut self, p: &RXingResultPoint) -> Result<(), Exceptions> {
|
||||
if self.direction_inward == RXingResultPoint::default() {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
return Err(Exceptions::illegalStateEmpty());
|
||||
}
|
||||
self.points.push(*p);
|
||||
if self.points.len() == 1 {
|
||||
@@ -241,7 +241,7 @@ impl DMRegressionLine {
|
||||
end: &RXingResultPoint,
|
||||
) -> Result<f64, Exceptions> {
|
||||
if self.points.len() <= 3 {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
return Err(Exceptions::illegalStateEmpty());
|
||||
}
|
||||
|
||||
// re-evaluate and filter out all points too far away. required for the gapSizes calculation.
|
||||
@@ -267,11 +267,11 @@ impl DMRegressionLine {
|
||||
&(*self
|
||||
.points
|
||||
.last()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
- *self
|
||||
.points
|
||||
.first()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
|
||||
)) as f64;
|
||||
|
||||
// calculate the width of 2 modules (first black pixel to first black pixel)
|
||||
@@ -297,7 +297,7 @@ impl DMRegressionLine {
|
||||
&self.project(
|
||||
self.points
|
||||
.last()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||
),
|
||||
) as f64,
|
||||
);
|
||||
|
||||
@@ -199,7 +199,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
if self.whiteAt(&pEdge) {
|
||||
// if we are not making any progress, we still have another endless loop bug
|
||||
if self.p == RXingResultPoint::centered(&pEdge) {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
return Err(Exceptions::illegalStateEmpty());
|
||||
}
|
||||
self.p = RXingResultPoint::centered(&pEdge);
|
||||
|
||||
@@ -277,7 +277,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
.points()
|
||||
.first()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
|
||||
) {
|
||||
return Ok(false);
|
||||
}
|
||||
@@ -307,9 +307,9 @@ impl<'a> EdgeTracer<'_> {
|
||||
.points()
|
||||
.last()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?)
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?)
|
||||
{
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
return Err(Exceptions::illegalStateEmpty());
|
||||
}
|
||||
if !line.points().is_empty()
|
||||
&& &&self.p
|
||||
@@ -317,7 +317,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
.points()
|
||||
.last()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
@@ -363,7 +363,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
line.points()
|
||||
.last()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||
),
|
||||
) < 1.0
|
||||
{
|
||||
@@ -380,7 +380,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
- line
|
||||
.points()
|
||||
.last()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||
)
|
||||
};
|
||||
line.add(&self.p)?;
|
||||
@@ -396,7 +396,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
+ *line
|
||||
.points()
|
||||
.first()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
|
||||
) {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn intersect(
|
||||
l2: &DMRegressionLine,
|
||||
) -> Result<RXingResultPoint, Exceptions> {
|
||||
if !(l1.isValid() && l2.isValid()) {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
return Err(Exceptions::illegalStateEmpty());
|
||||
}
|
||||
let d = l1.a * l2.b - l1.b * l2.a;
|
||||
let x = (l1.c * l2.b - l1.b * l2.c) / d;
|
||||
|
||||
@@ -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}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ impl Encoder for Base256Encoder {
|
||||
context.updateSymbolInfoWithLength(currentSize);
|
||||
let mustPad = (context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity()
|
||||
- currentSize as u32)
|
||||
> 0;
|
||||
@@ -62,29 +62,29 @@ impl Encoder for Base256Encoder {
|
||||
buffer.replace_range(
|
||||
0..1,
|
||||
&char::from_u32(dataCount as u32)
|
||||
.ok_or(Exceptions::ParseException(None))?
|
||||
.ok_or(Exceptions::parseEmpty())?
|
||||
.to_string(),
|
||||
);
|
||||
} else if dataCount <= 1555 {
|
||||
buffer.replace_range(
|
||||
0..1,
|
||||
&char::from_u32((dataCount as u32 / 250) + 249)
|
||||
.ok_or(Exceptions::ParseException(None))?
|
||||
.ok_or(Exceptions::parseEmpty())?
|
||||
.to_string(),
|
||||
);
|
||||
let (ci_pos, _) = buffer
|
||||
.char_indices()
|
||||
.nth(1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||
buffer.insert(
|
||||
ci_pos,
|
||||
char::from_u32(dataCount as u32 % 250)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||
);
|
||||
} else {
|
||||
return Err(Exceptions::IllegalStateException(Some(format!(
|
||||
return Err(Exceptions::illegalState(format!(
|
||||
"Message length not in valid ranges: {dataCount}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
let c = buffer.chars().count();
|
||||
@@ -95,10 +95,10 @@ impl Encoder for Base256Encoder {
|
||||
buffer
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||
context.getCodewordCount() as u32 + 1,
|
||||
)
|
||||
.ok_or(Exceptions::ParseException(None))? as u8,
|
||||
.ok_or(Exceptions::parseEmpty())? as u8,
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -65,7 +65,7 @@ impl C40Encoder {
|
||||
context.updateSymbolInfoWithLength(curCodewordCount);
|
||||
let available = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity() as usize
|
||||
- curCodewordCount;
|
||||
|
||||
@@ -140,7 +140,7 @@ impl C40Encoder {
|
||||
context.updateSymbolInfoWithLength(curCodewordCount);
|
||||
let available = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity() as usize
|
||||
- curCodewordCount;
|
||||
let rest = buffer.chars().count() % 3;
|
||||
@@ -182,9 +182,7 @@ impl C40Encoder {
|
||||
context: &mut EncoderContext,
|
||||
buffer: &mut String,
|
||||
) -> Result<(), Exceptions> {
|
||||
context.writeCodewords(
|
||||
&Self::encodeToCodewords(buffer).ok_or(Exceptions::FormatException(None))?,
|
||||
);
|
||||
context.writeCodewords(&Self::encodeToCodewords(buffer).ok_or(Exceptions::formatEmpty())?);
|
||||
buffer.replace_range(0..3, "");
|
||||
// buffer.delete(0, 3);
|
||||
Ok(())
|
||||
@@ -207,7 +205,7 @@ impl C40Encoder {
|
||||
context.updateSymbolInfoWithLength(curCodewordCount);
|
||||
let available = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity() as usize
|
||||
- curCodewordCount;
|
||||
|
||||
@@ -236,9 +234,9 @@ impl C40Encoder {
|
||||
context.writeCodeword(C40_UNLATCH);
|
||||
}
|
||||
} else {
|
||||
return Err(Exceptions::IllegalStateException(Some(
|
||||
return Err(Exceptions::illegalState(
|
||||
"Unexpected case. Please report!".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
context.signalEncoderChange(ASCII_ENCODATION);
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ impl DefaultPlacement {
|
||||
.codewords
|
||||
.chars()
|
||||
.nth(pos)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as u32;
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as u32;
|
||||
v &= 1 << (8 - bit);
|
||||
self.setBit(col as usize, row as usize, v != 0);
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ impl EdifactEncoder {
|
||||
context.updateSymbolInfo();
|
||||
let mut available = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity()
|
||||
- context.getCodewordCount() as u32;
|
||||
let remaining = context.getRemainingCharacters();
|
||||
@@ -85,7 +85,7 @@ impl EdifactEncoder {
|
||||
context.updateSymbolInfoWithLength(context.getCodewordCount() + 1);
|
||||
available = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity()
|
||||
- context.getCodewordCount() as u32;
|
||||
}
|
||||
@@ -95,9 +95,9 @@ impl EdifactEncoder {
|
||||
}
|
||||
|
||||
if count > 4 {
|
||||
return Err(Exceptions::IllegalStateException(Some(
|
||||
return Err(Exceptions::illegalState(
|
||||
"Count must not exceed 4".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
let restChars = count - 1;
|
||||
let encoded = Self::encodeToCodewords(buffer)?;
|
||||
@@ -108,7 +108,7 @@ impl EdifactEncoder {
|
||||
context.updateSymbolInfoWithLength(context.getCodewordCount() + restChars);
|
||||
let available = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity()
|
||||
- context.getCodewordCount() as u32;
|
||||
if available >= 3 {
|
||||
@@ -149,32 +149,32 @@ impl EdifactEncoder {
|
||||
fn encodeToCodewords(sb: &str) -> Result<String, Exceptions> {
|
||||
let len = sb.chars().count();
|
||||
if len == 0 {
|
||||
return Err(Exceptions::IllegalStateException(Some(
|
||||
return Err(Exceptions::illegalState(
|
||||
"StringBuilder must not be empty".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
let c1 = sb
|
||||
.chars()
|
||||
.next()
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||
let c2 = if len >= 2 {
|
||||
sb.chars()
|
||||
.nth(1)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
} else {
|
||||
0 as char
|
||||
};
|
||||
let c3 = if len >= 3 {
|
||||
sb.chars()
|
||||
.nth(2)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
} else {
|
||||
0 as char
|
||||
};
|
||||
let c4 = if len >= 4 {
|
||||
sb.chars()
|
||||
.nth(3)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
} else {
|
||||
0 as char
|
||||
};
|
||||
@@ -184,12 +184,12 @@ impl EdifactEncoder {
|
||||
let cw2 = (v >> 8) & 255;
|
||||
let cw3 = v & 255;
|
||||
let mut res = String::with_capacity(3);
|
||||
res.push(char::from_u32(cw1).ok_or(Exceptions::IndexOutOfBoundsException(None))?);
|
||||
res.push(char::from_u32(cw1).ok_or(Exceptions::indexOutOfBoundsEmpty())?);
|
||||
if len >= 2 {
|
||||
res.push(char::from_u32(cw2).ok_or(Exceptions::IndexOutOfBoundsException(None))?);
|
||||
res.push(char::from_u32(cw2).ok_or(Exceptions::indexOutOfBoundsEmpty())?);
|
||||
}
|
||||
if len >= 3 {
|
||||
res.push(char::from_u32(cw3).ok_or(Exceptions::IndexOutOfBoundsException(None))?);
|
||||
res.push(char::from_u32(cw3).ok_or(Exceptions::indexOutOfBoundsEmpty())?);
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
|
||||
@@ -63,14 +63,12 @@ impl<'a> EncoderContext<'_> {
|
||||
ISO_8859_1_ENCODER
|
||||
.decode(&encoded_bytes, encoding::DecoderTrap::Strict)
|
||||
.map_err(|e| {
|
||||
Exceptions::ParseException(Some(format!(
|
||||
"round trip decode should always work: {e}"
|
||||
)))
|
||||
Exceptions::parse(format!("round trip decode should always work: {e}"))
|
||||
})?
|
||||
} else {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"Message contains characters outside ISO-8859-1 encoding.".to_owned(),
|
||||
)));
|
||||
));
|
||||
};
|
||||
Ok(Self {
|
||||
symbol_lookup: Rc::new(SymbolInfoLookup::new()),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
|
||||
c40Encoder.encodeMaximalC40(&mut context)?;
|
||||
encodingMode = context
|
||||
.getNewEncoding()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?;
|
||||
.ok_or(Exceptions::illegalStateEmpty())?;
|
||||
context.resetEncoderSignal();
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
|
||||
if context.getNewEncoding().is_some() {
|
||||
encodingMode = context
|
||||
.getNewEncoding()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?;
|
||||
.ok_or(Exceptions::illegalStateEmpty())?;
|
||||
context.resetEncoderSignal();
|
||||
}
|
||||
}
|
||||
@@ -240,7 +240,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
|
||||
context.updateSymbolInfo();
|
||||
let capacity = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity();
|
||||
if len < capacity as usize
|
||||
&& encodingMode != ASCII_ENCODATION
|
||||
@@ -611,7 +611,7 @@ pub fn determineConsecutiveDigitCount(msg: &str, startpos: u32) -> u32 {
|
||||
pub fn illegalCharacter(c: char) -> Result<(), Exceptions> {
|
||||
// let hex = Integer.toHexString(c);
|
||||
// hex = "0000".substring(0, 4 - hex.length()) + hex;
|
||||
Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
Err(Exceptions::illegalArgument(format!(
|
||||
"Illegal character: {c} (0x{c})"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ fn addEdge(edges: &mut [Vec<Option<Rc<Edge>>>], edge: Rc<Edge>) -> Result<(), Ex
|
||||
if edges[vertexIndex][edge.getEndMode()?.ordinal()].is_none()
|
||||
|| edges[vertexIndex][edge.getEndMode()?.ordinal()]
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.cachedTotalSize
|
||||
> edge.cachedTotalSize
|
||||
{
|
||||
@@ -635,9 +635,9 @@ fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult, Exceptions> {
|
||||
}
|
||||
|
||||
if minimalJ < 0 {
|
||||
return Err(Exceptions::IllegalStateException(Some(format!(
|
||||
return Err(Exceptions::illegalState(format!(
|
||||
"Internal error: failed to encode \"{input}\""
|
||||
))));
|
||||
)));
|
||||
}
|
||||
RXingResult::new(edges[inputLength][minimalJ as usize].clone())
|
||||
}
|
||||
@@ -669,7 +669,7 @@ impl Edge {
|
||||
previous: Option<Rc<Edge>>,
|
||||
) -> Result<Self, Exceptions> {
|
||||
if fromPosition + characterLength > input.length() as u32 {
|
||||
return Err(Exceptions::FormatException(None));
|
||||
return Err(Exceptions::formatEmpty());
|
||||
}
|
||||
|
||||
let mut size = if let Some(previous) = previous.clone() {
|
||||
@@ -1276,7 +1276,7 @@ impl RXingResult {
|
||||
let solution = if let Some(edge) = solution {
|
||||
edge
|
||||
} else {
|
||||
return Err(Exceptions::IllegalArgumentException(None));
|
||||
return Err(Exceptions::illegalArgumentEmpty());
|
||||
};
|
||||
let input = solution.input.clone();
|
||||
let mut size = 0;
|
||||
|
||||
@@ -128,9 +128,9 @@ impl SymbolInfo {
|
||||
2 | 4 => Ok(2),
|
||||
16 => Ok(4),
|
||||
36 => Ok(6),
|
||||
_ => Err(Exceptions::IllegalStateException(Some(
|
||||
_ => Err(Exceptions::illegalState(
|
||||
"Cannot handle this number of data regions".to_owned(),
|
||||
))),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,9 +140,9 @@ impl SymbolInfo {
|
||||
4 => Ok(2),
|
||||
16 => Ok(4),
|
||||
36 => Ok(6),
|
||||
_ => Err(Exceptions::IllegalStateException(Some(
|
||||
_ => Err(Exceptions::illegalState(
|
||||
"Cannot handle this number of data regions".to_owned(),
|
||||
))),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,9 +310,9 @@ impl<'a> SymbolInfoLookup<'a> {
|
||||
}
|
||||
}
|
||||
if fail {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"Can't find a symbol arrangement that matches the message. Data codewords: {dataCodewords}"
|
||||
))));
|
||||
)));
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ impl X12Encoder {
|
||||
context.updateSymbolInfo();
|
||||
let available = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
.getDataCapacity()
|
||||
- context.getCodewordCount() as u32;
|
||||
let count = buffer.chars().count();
|
||||
|
||||
Reference in New Issue
Block a user