rename helper methods

This commit is contained in:
Vukašin Stepanović
2023-02-15 12:52:59 +00:00
parent bfcdb397ad
commit 935519ced5
133 changed files with 858 additions and 1044 deletions

View File

@@ -105,7 +105,7 @@ impl Reader for DataMatrixReader {
DECODER.decode(&bits)?
}
} else {
return Err(Exceptions::notFoundEmpty());
return Err(Exceptions::notFound);
};
// 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::notFoundEmpty())
return Err(Exceptions::notFound)
};
let Some(rightBottomBlack) = image.getBottomRightOnBit()else {
return Err(Exceptions::notFoundEmpty())
return Err(Exceptions::notFound)
};
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::notFoundEmpty());
return Err(Exceptions::notFound);
// throw NotFoundException.getNotFoundInstance();
}
@@ -234,12 +234,12 @@ impl DataMatrixReader {
x += 1;
}
if x == width {
return Err(Exceptions::notFoundEmpty());
return Err(Exceptions::notFound);
}
let moduleSize = x - leftTopBlack[0];
if moduleSize == 0 {
return Err(Exceptions::notFoundEmpty());
return Err(Exceptions::notFound);
}
Ok(moduleSize)

View File

@@ -60,17 +60,17 @@ impl Writer for DataMatrixWriter {
hints: &crate::EncodingHintDictionary,
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
if contents.is_empty() {
return Err(Exceptions::illegalArgument("Found empty contents"));
return Err(Exceptions::illegalArgumentWith("Found empty contents"));
}
if format != &BarcodeFormat::DATA_MATRIX {
return Err(Exceptions::illegalArgument(format!(
return Err(Exceptions::illegalArgumentWith(format!(
"Can only encode DATA_MATRIX, but got {format:?}"
)));
}
if width < 0 || height < 0 {
return Err(Exceptions::illegalArgument(format!(
return Err(Exceptions::illegalArgumentWith(format!(
"Requested dimensions can't be negative: {width}x{height}"
)));
}
@@ -121,7 +121,7 @@ impl Writer for DataMatrixWriter {
if hasEncodingHint {
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
hints.get(&EncodeHintType::CHARACTER_SET) else {
return Err(Exceptions::illegalArgument("charset does not exist"))
return Err(Exceptions::illegalArgumentWith("charset does not exist"))
};
charset = encoding::label::encoding_from_whatwg_label(char_set_name);
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
@@ -155,7 +155,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::notFound("symbol info is bad"))
return Err(Exceptions::notFoundWith("symbol info is bad"))
};
//2. step: ECC generation

View File

@@ -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",
));
}

View File

@@ -138,7 +138,7 @@ impl DataBlock {
}
if rawCodewordsOffset != rawCodewords.len() {
return Err(Exceptions::illegalArgumentEmpty());
return Err(Exceptions::illegalArgument);
}
Ok(result)

View File

@@ -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);

View File

@@ -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)
}
/**

View File

@@ -53,7 +53,7 @@ impl<'a> Detector<'_> {
if let Some(point) = self.correctTopRight(&points) {
points[3] = point;
} else {
return Err(Exceptions::notFound("point 4 unfound"));
return Err(Exceptions::notFoundWith("point 4 unfound"));
}
// points[3] = self.correctTopRight(&points);
// if points[3] == null {

View File

@@ -254,7 +254,7 @@ fn Scan(
));
}
Err(Exceptions::notFoundEmpty())
Err(Exceptions::notFound)
}
pub fn detect(
@@ -359,6 +359,6 @@ pub fn detect(
}
// #ifndef __cpp_impl_coroutine
Err(Exceptions::notFoundEmpty())
Err(Exceptions::notFound)
// #endif
}

View File

@@ -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::illegalStateEmpty());
return Err(Exceptions::illegalState);
}
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::illegalStateEmpty());
return Err(Exceptions::illegalState);
}
// re-evaluate and filter out all points too far away. required for the gapSizes calculation.
@@ -264,14 +264,8 @@ impl DMRegressionLine {
// calculate the (expected average) distance of two adjacent pixels
let unitPixelDist = RXingResultPoint::length(RXingResultPoint::bresenhamDirection(
&(*self
.points
.last()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
- *self
.points
.first()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
&(*self.points.last().ok_or(Exceptions::indexOutOfBounds)?
- *self.points.first().ok_or(Exceptions::indexOutOfBounds)?),
)) as f64;
// calculate the width of 2 modules (first black pixel to first black pixel)
@@ -294,11 +288,7 @@ impl DMRegressionLine {
sumFront
+ self.distance(
end,
&self.project(
self.points
.last()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
),
&self.project(self.points.last().ok_or(Exceptions::indexOutOfBounds)?),
) as f64,
);
modSizes[0] = 0.0; // the first element is an invalid sumBack value, would be pop_front() if vector supported this

View File

@@ -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::illegalStateEmpty());
return Err(Exceptions::illegalState);
}
self.p = RXingResultPoint::centered(&pEdge);
@@ -277,7 +277,7 @@ impl<'a> EdgeTracer<'_> {
.points()
.first()
.as_ref()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
.ok_or(Exceptions::indexOutOfBounds)?),
) {
return Ok(false);
}
@@ -307,9 +307,9 @@ impl<'a> EdgeTracer<'_> {
.points()
.last()
.as_ref()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?)
.ok_or(Exceptions::indexOutOfBounds)?)
{
return Err(Exceptions::illegalStateEmpty());
return Err(Exceptions::illegalState);
}
if !line.points().is_empty()
&& &&self.p
@@ -317,7 +317,7 @@ impl<'a> EdgeTracer<'_> {
.points()
.last()
.as_ref()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
.ok_or(Exceptions::indexOutOfBounds)?
{
return Ok(false);
}
@@ -363,7 +363,7 @@ impl<'a> EdgeTracer<'_> {
line.points()
.last()
.as_ref()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
.ok_or(Exceptions::indexOutOfBounds)?,
),
) < 1.0
{
@@ -376,11 +376,7 @@ impl<'a> EdgeTracer<'_> {
} else {
RXingResultPoint::dot(
RXingResultPoint::mainDirection(self.d),
self.p
- line
.points()
.last()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
self.p - line.points().last().ok_or(Exceptions::indexOutOfBounds)?,
)
};
line.add(&self.p)?;
@@ -393,10 +389,7 @@ impl<'a> EdgeTracer<'_> {
}
if !self.updateDirectionFromOrigin(
&(self.p - line.project(&self.p)
+ *line
.points()
.first()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
+ *line.points().first().ok_or(Exceptions::indexOutOfBounds)?),
) {
return Ok(false);
}

View File

@@ -26,7 +26,7 @@ pub fn intersect(
l2: &DMRegressionLine,
) -> Result<RXingResultPoint, Exceptions> {
if !(l1.isValid() && l2.isValid()) {
return Err(Exceptions::illegalStateEmpty());
return Err(Exceptions::illegalState);
}
let d = l1.a * l2.b - l1.b * l2.a;
let x = (l1.c * l2.b - l1.b * l2.c) / d;

View File

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

View File

@@ -53,7 +53,7 @@ impl Encoder for Base256Encoder {
context.updateSymbolInfoWithLength(currentSize);
let mustPad = (context
.getSymbolInfo()
.ok_or(Exceptions::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.getDataCapacity()
- currentSize as u32)
> 0;
@@ -62,27 +62,26 @@ impl Encoder for Base256Encoder {
buffer.replace_range(
0..1,
&char::from_u32(dataCount as u32)
.ok_or(Exceptions::parseEmpty())?
.ok_or(Exceptions::parse)?
.to_string(),
);
} else if dataCount <= 1555 {
buffer.replace_range(
0..1,
&char::from_u32((dataCount as u32 / 250) + 249)
.ok_or(Exceptions::parseEmpty())?
.ok_or(Exceptions::parse)?
.to_string(),
);
let (ci_pos, _) = buffer
.char_indices()
.nth(1)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
.ok_or(Exceptions::indexOutOfBounds)?;
buffer.insert(
ci_pos,
char::from_u32(dataCount as u32 % 250)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
char::from_u32(dataCount as u32 % 250).ok_or(Exceptions::indexOutOfBounds)?,
);
} else {
return Err(Exceptions::illegalState(format!(
return Err(Exceptions::illegalStateWith(format!(
"Message length not in valid ranges: {dataCount}"
)));
}
@@ -92,13 +91,10 @@ impl Encoder for Base256Encoder {
// for (int i = 0, c = buffer.length(); i < c; i++) {
context.writeCodeword(
Self::randomize255State(
buffer
.chars()
.nth(i)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
buffer.chars().nth(i).ok_or(Exceptions::indexOutOfBounds)?,
context.getCodewordCount() as u32 + 1,
)
.ok_or(Exceptions::parseEmpty())? as u8,
.ok_or(Exceptions::parse)? as u8,
);
}
Ok(())

View File

@@ -65,7 +65,7 @@ impl C40Encoder {
context.updateSymbolInfoWithLength(curCodewordCount);
let available = context
.getSymbolInfo()
.ok_or(Exceptions::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.getDataCapacity() as usize
- curCodewordCount;
@@ -140,7 +140,7 @@ impl C40Encoder {
context.updateSymbolInfoWithLength(curCodewordCount);
let available = context
.getSymbolInfo()
.ok_or(Exceptions::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.getDataCapacity() as usize
- curCodewordCount;
let rest = buffer.chars().count() % 3;
@@ -182,7 +182,7 @@ impl C40Encoder {
context: &mut EncoderContext,
buffer: &mut String,
) -> Result<(), Exceptions> {
context.writeCodewords(&Self::encodeToCodewords(buffer).ok_or(Exceptions::formatEmpty())?);
context.writeCodewords(&Self::encodeToCodewords(buffer).ok_or(Exceptions::format)?);
buffer.replace_range(0..3, "");
// buffer.delete(0, 3);
Ok(())
@@ -205,7 +205,7 @@ impl C40Encoder {
context.updateSymbolInfoWithLength(curCodewordCount);
let available = context
.getSymbolInfo()
.ok_or(Exceptions::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.getDataCapacity() as usize
- curCodewordCount;
@@ -234,7 +234,9 @@ impl C40Encoder {
context.writeCodeword(C40_UNLATCH);
}
} else {
return Err(Exceptions::illegalState("Unexpected case. Please report!"));
return Err(Exceptions::illegalStateWith(
"Unexpected case. Please report!",
));
}
context.signalEncoderChange(ASCII_ENCODATION);

View File

@@ -164,7 +164,7 @@ impl DefaultPlacement {
.codewords
.chars()
.nth(pos)
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as u32;
.ok_or(Exceptions::indexOutOfBounds)? as u32;
v &= 1 << (8 - bit);
self.setBit(col as usize, row as usize, v != 0);

View File

@@ -76,7 +76,7 @@ impl EdifactEncoder {
context.updateSymbolInfo();
let mut available = context
.getSymbolInfo()
.ok_or(Exceptions::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.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::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.getDataCapacity()
- context.getCodewordCount() as u32;
}
@@ -95,7 +95,7 @@ impl EdifactEncoder {
}
if count > 4 {
return Err(Exceptions::illegalState("Count must not exceed 4"));
return Err(Exceptions::illegalStateWith("Count must not exceed 4"));
}
let restChars = count - 1;
let encoded = Self::encodeToCodewords(buffer)?;
@@ -106,7 +106,7 @@ impl EdifactEncoder {
context.updateSymbolInfoWithLength(context.getCodewordCount() + restChars);
let available = context
.getSymbolInfo()
.ok_or(Exceptions::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.getDataCapacity()
- context.getCodewordCount() as u32;
if available >= 3 {
@@ -147,30 +147,23 @@ impl EdifactEncoder {
fn encodeToCodewords(sb: &str) -> Result<String, Exceptions> {
let len = sb.chars().count();
if len == 0 {
return Err(Exceptions::illegalState("StringBuilder must not be empty"));
return Err(Exceptions::illegalStateWith(
"StringBuilder must not be empty",
));
}
let c1 = sb
.chars()
.next()
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
let c1 = sb.chars().next().ok_or(Exceptions::indexOutOfBounds)?;
let c2 = if len >= 2 {
sb.chars()
.nth(1)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
sb.chars().nth(1).ok_or(Exceptions::indexOutOfBounds)?
} else {
0 as char
};
let c3 = if len >= 3 {
sb.chars()
.nth(2)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
sb.chars().nth(2).ok_or(Exceptions::indexOutOfBounds)?
} else {
0 as char
};
let c4 = if len >= 4 {
sb.chars()
.nth(3)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
sb.chars().nth(3).ok_or(Exceptions::indexOutOfBounds)?
} else {
0 as char
};
@@ -180,12 +173,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::indexOutOfBoundsEmpty())?);
res.push(char::from_u32(cw1).ok_or(Exceptions::indexOutOfBounds)?);
if len >= 2 {
res.push(char::from_u32(cw2).ok_or(Exceptions::indexOutOfBoundsEmpty())?);
res.push(char::from_u32(cw2).ok_or(Exceptions::indexOutOfBounds)?);
}
if len >= 3 {
res.push(char::from_u32(cw3).ok_or(Exceptions::indexOutOfBoundsEmpty())?);
res.push(char::from_u32(cw3).ok_or(Exceptions::indexOutOfBounds)?);
}
Ok(res)

View File

@@ -63,10 +63,10 @@ impl<'a> EncoderContext<'_> {
ISO_8859_1_ENCODER
.decode(&encoded_bytes, encoding::DecoderTrap::Strict)
.map_err(|e| {
Exceptions::parse(format!("round trip decode should always work: {e}"))
Exceptions::parseWith(format!("round trip decode should always work: {e}"))
})?
} else {
return Err(Exceptions::illegalArgument(
return Err(Exceptions::illegalArgumentWith(
"Message contains characters outside ISO-8859-1 encoding.",
));
};

View File

@@ -154,7 +154,7 @@ 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::illegalArgument(
return Err(Exceptions::illegalArgumentWith(
"The number of codewords does not match the selected symbol",
));
}
@@ -185,7 +185,7 @@ pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String,
codewords
.chars()
.nth(d)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
.ok_or(Exceptions::indexOutOfBounds)?,
);
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::indexOutOfBoundsEmpty())?;
.ok_or(Exceptions::indexOutOfBounds)?;
sb.replace_range(
char_index..(replace_char.len_utf8()),
&ecc.chars()
.nth(pos)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
.ok_or(Exceptions::indexOutOfBounds)?
.to_string(),
);
// sb.setCharAt(symbolInfo.getDataCapacity() + e, ecc.charAt(pos));
@@ -228,7 +228,7 @@ fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptio
}
}
if table < 0 {
return Err(Exceptions::illegalArgument(format!(
return Err(Exceptions::illegalArgumentWith(format!(
"Illegal number of error correction codewords specified: {numECWords}"
)));
}
@@ -244,21 +244,21 @@ fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptio
^ codewords
.chars()
.nth(i)
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as usize;
.ok_or(Exceptions::indexOutOfBounds)? 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::indexOutOfBoundsEmpty())?;
.ok_or(Exceptions::indexOutOfBounds)?;
} 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::indexOutOfBoundsEmpty())?;
.ok_or(Exceptions::indexOutOfBounds)?;
} else {
ecc[0] = 0 as char;
}

View File

@@ -221,18 +221,14 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
if forceC40 {
c40Encoder.encodeMaximalC40(&mut context)?;
encodingMode = context
.getNewEncoding()
.ok_or(Exceptions::illegalStateEmpty())?;
encodingMode = context.getNewEncoding().ok_or(Exceptions::illegalState)?;
context.resetEncoderSignal();
}
while context.hasMoreCharacters() {
encoders[encodingMode].encode(&mut context)?;
if context.getNewEncoding().is_some() {
encodingMode = context
.getNewEncoding()
.ok_or(Exceptions::illegalStateEmpty())?;
encodingMode = context.getNewEncoding().ok_or(Exceptions::illegalState)?;
context.resetEncoderSignal();
}
}
@@ -240,7 +236,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
context.updateSymbolInfo();
let capacity = context
.getSymbolInfo()
.ok_or(Exceptions::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.getDataCapacity();
if len < capacity as usize
&& encodingMode != ASCII_ENCODATION
@@ -611,7 +607,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::illegalArgument(format!(
Err(Exceptions::illegalArgumentWith(format!(
"Illegal character: {c} (0x{c})"
)))
}

View File

@@ -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::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.cachedTotalSize
> edge.cachedTotalSize
{
@@ -635,7 +635,7 @@ fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult, Exceptions> {
}
if minimalJ < 0 {
return Err(Exceptions::illegalState(format!(
return Err(Exceptions::illegalStateWith(format!(
"Internal error: failed to encode \"{input}\""
)));
}
@@ -669,7 +669,7 @@ impl Edge {
previous: Option<Rc<Edge>>,
) -> Result<Self, Exceptions> {
if fromPosition + characterLength > input.length() as u32 {
return Err(Exceptions::formatEmpty());
return Err(Exceptions::format);
}
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::illegalArgumentEmpty());
return Err(Exceptions::illegalArgument);
};
let input = solution.input.clone();
let mut size = 0;

View File

@@ -128,7 +128,7 @@ impl SymbolInfo {
2 | 4 => Ok(2),
16 => Ok(4),
36 => Ok(6),
_ => Err(Exceptions::illegalState(
_ => Err(Exceptions::illegalStateWith(
"Cannot handle this number of data regions",
)),
}
@@ -140,7 +140,7 @@ impl SymbolInfo {
4 => Ok(2),
16 => Ok(4),
36 => Ok(6),
_ => Err(Exceptions::illegalState(
_ => Err(Exceptions::illegalStateWith(
"Cannot handle this number of data regions",
)),
}
@@ -310,7 +310,7 @@ impl<'a> SymbolInfoLookup<'a> {
}
}
if fail {
return Err(Exceptions::illegalArgument(format!(
return Err(Exceptions::illegalArgumentWith(format!(
"Can't find a symbol arrangement that matches the message. Data codewords: {dataCodewords}"
)));
}

View File

@@ -81,7 +81,7 @@ impl X12Encoder {
context.updateSymbolInfo();
let available = context
.getSymbolInfo()
.ok_or(Exceptions::illegalStateEmpty())?
.ok_or(Exceptions::illegalState)?
.getDataCapacity()
- context.getCodewordCount() as u32;
let count = buffer.chars().count();