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

@@ -61,7 +61,7 @@ impl Reader for AztecReader {
} else if let Ok(det) = detector.detect(true) {
det
} else {
return Err(Exceptions::notFoundEmpty());
return Err(Exceptions::notFound);
};
let points = detectorRXingResult.getPoints();

View File

@@ -59,7 +59,7 @@ impl Writer for AztecWriter {
if cset_name.to_lowercase() != "iso-8859-1" {
charset = Some(
encoding::label::encoding_from_whatwg_label(cset_name)
.ok_or(Exceptions::illegalArgumentEmpty())?,
.ok_or(Exceptions::illegalArgument)?,
);
}
}
@@ -95,7 +95,7 @@ fn encode(
layers: i32,
) -> Result<BitMatrix, Exceptions> {
if format != BarcodeFormat::AZTEC {
return Err(Exceptions::illegalArgument(format!(
return Err(Exceptions::illegalArgumentWith(format!(
"can only encode AZTEC, but got {format:?}"
)));
}

View File

@@ -164,13 +164,13 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
result.push_str(
&encdr
.decode(&decoded_bytes, encoding::DecoderTrap::Strict)
.map_err(|a| Exceptions::illegalState(a))?,
.map_err(|a| Exceptions::illegalStateWith(a))?,
);
decoded_bytes.clear();
match n {
0 => result.push(29 as char), // translate FNC1 as ASCII 29
7 => return Err(Exceptions::format("FLG(7) is reserved and illegal")), // FLG(7) is reserved and illegal
7 => return Err(Exceptions::formatWith("FLG(7) is reserved and illegal")), // FLG(7) is reserved and illegal
_ => {
// ECI is decimal integer encoded as 1-6 codes in DIGIT mode
let mut eci = 0;
@@ -182,7 +182,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
let next_digit = read_code(corrected_bits, index, 4);
index += 4;
if !(2..=11).contains(&next_digit) {
return Err(Exceptions::format("Not a decimal digit"));
return Err(Exceptions::formatWith("Not a decimal digit"));
// Not a decimal digit
}
eci = eci * 10 + (next_digit - 2);
@@ -190,7 +190,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
}
let charset_eci = CharacterSetECI::getCharacterSetECIByValue(eci);
if charset_eci.is_err() {
return Err(Exceptions::format("Charset must exist"));
return Err(Exceptions::formatWith("Charset must exist"));
}
encdr = CharacterSetECI::getCharset(&charset_eci?);
}
@@ -203,17 +203,8 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
// That's including when that mode is a shift.
// Our test case dlusbs.png for issue #642 exercises that.
latch_table = shift_table; // Latch the current mode, so as to return to Upper after U/S B/S
shift_table = getTable(
str.chars()
.nth(5)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
);
if str
.chars()
.nth(6)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
== 'L'
{
shift_table = getTable(str.chars().nth(5).ok_or(Exceptions::indexOutOfBounds)?);
if str.chars().nth(6).ok_or(Exceptions::indexOutOfBounds)? == 'L' {
latch_table = shift_table;
}
} else {
@@ -234,7 +225,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
if let Ok(str) = encdr.decode(&decoded_bytes, encoding::DecoderTrap::Strict) {
result.push_str(&str);
} else {
return Err(Exceptions::illegalState("bad encoding"));
return Err(Exceptions::illegalStateWith("bad encoding"));
}
// result.push_str(decodedBytes.toString(encoding.name()));
//} catch (UnsupportedEncodingException uee) {
@@ -286,7 +277,7 @@ fn get_character(table: Table, code: u32) -> Result<&'static str, Exceptions> {
Table::Mixed => Ok(MIXED_TABLE[code as usize]),
Table::Digit => Ok(DIGIT_TABLE[code as usize]),
Table::Punct => Ok(PUNCT_TABLE[code as usize]),
_ => Err(Exceptions::illegalState("Bad table")),
_ => Err(Exceptions::illegalStateWith("Bad table")),
}
// switch (table) {
// case UPPER:
@@ -347,7 +338,7 @@ fn correct_bits(
let num_data_codewords = ddata.getNbDatablocks();
let num_codewords = rawbits.len() / codeword_size;
if num_codewords < num_data_codewords as usize {
return Err(Exceptions::format(format!(
return Err(Exceptions::formatWith(format!(
"numCodewords {num_codewords}< numDataCodewords{num_data_codewords}"
)));
}
@@ -380,7 +371,7 @@ fn correct_bits(
// for (int i = 0; i < numDataCodewords; i++) {
// let data_word = data_words[i];
if data_word == &0 || data_word == &mask {
return Err(Exceptions::formatEmpty());
return Err(Exceptions::format);
//throw FormatException.getFormatInstance();
} else if data_word == &1 || data_word == &(mask - 1) {
stuffed_bits += 1;

View File

@@ -127,7 +127,7 @@ impl<'a> Detector<'_> {
|| !self.is_valid(&bulls_eye_corners[2])
|| !self.is_valid(&bulls_eye_corners[3])
{
return Err(Exceptions::notFound("no valid points"));
return Err(Exceptions::notFoundWith("no valid points"));
}
let length = 2 * self.nb_center_layers;
// Get the bits around the bull's eye
@@ -208,7 +208,7 @@ impl<'a> Detector<'_> {
return Ok(shift);
}
}
Err(Exceptions::notFound("rotation failure"))
Err(Exceptions::notFoundWith("rotation failure"))
}
/**
@@ -320,7 +320,7 @@ impl<'a> Detector<'_> {
}
if self.nb_center_layers != 5 && self.nb_center_layers != 7 {
return Err(Exceptions::notFoundEmpty());
return Err(Exceptions::notFound);
}
self.compact = self.nb_center_layers == 5;

View File

@@ -53,7 +53,7 @@ pub const WORD_SIZE: [u32; 33] = [
pub fn encode_simple(data: &str) -> Result<AztecCode, Exceptions> {
let Ok(bytes) = encoding::all::ISO_8859_1
.encode(data, encoding::EncoderTrap::Replace) else {
return Err(Exceptions::illegalArgument(format!("'{data}' cannot be encoded as ISO_8859_1")));
return Err(Exceptions::illegalArgumentWith(format!("'{data}' cannot be encoded as ISO_8859_1")));
};
encode_bytes_simple(&bytes)
}
@@ -75,7 +75,7 @@ pub fn encode(
if let Ok(bytes) = encoding::all::ISO_8859_1.encode(data, encoding::EncoderTrap::Strict) {
encode_bytes(&bytes, minECCPercent, userSpecifiedLayers)
} else {
Err(Exceptions::illegalArgument(format!(
Err(Exceptions::illegalArgumentWith(format!(
"'{data}' cannot be encoded as ISO_8859_1"
)))
}
@@ -102,7 +102,7 @@ pub fn encode_with_charset(
if let Ok(bytes) = charset.encode(data, encoding::EncoderTrap::Strict) {
encode_bytes_with_charset(&bytes, minECCPercent, userSpecifiedLayers, charset)
} else {
Err(Exceptions::illegalArgument(format!(
Err(Exceptions::illegalArgumentWith(format!(
"'{data}' cannot be encoded as ISO_8859_1"
)))
}
@@ -178,7 +178,7 @@ pub fn encode_bytes_with_charset(
MAX_NB_BITS
})
{
return Err(Exceptions::illegalArgument(format!(
return Err(Exceptions::illegalArgumentWith(format!(
"Illegal value {user_specified_layers} for layers"
)));
}
@@ -187,13 +187,13 @@ pub fn encode_bytes_with_charset(
let usable_bits_in_layers = total_bits_in_layer_var - (total_bits_in_layer_var % word_size);
stuffed_bits = stuffBits(&bits, word_size as usize)?;
if stuffed_bits.getSize() as u32 + ecc_bits > usable_bits_in_layers {
return Err(Exceptions::illegalArgument(
return Err(Exceptions::illegalArgumentWith(
"Data to large for user specified layer",
));
}
if compact && stuffed_bits.getSize() as u32 > word_size * 64 {
// Compact format only allows 64 data words, though C4 can hold more words than that
return Err(Exceptions::illegalArgument(
return Err(Exceptions::illegalArgumentWith(
"Data to large for user specified layer",
));
}
@@ -207,7 +207,7 @@ pub fn encode_bytes_with_charset(
loop {
// for (int i = 0; ; i++) {
if i > MAX_NB_BITS {
return Err(Exceptions::illegalArgument(
return Err(Exceptions::illegalArgumentWith(
"Data too large for an Aztec code",
));
}
@@ -482,7 +482,7 @@ fn getGF(wordSize: usize) -> Result<GenericGFRef, Exceptions> {
8 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData8)),
10 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData10)),
12 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData12)),
_ => Err(Exceptions::illegalArgument(format!(
_ => Err(Exceptions::illegalArgumentWith(format!(
"Unsupported word size {wordSize}"
))),
}

View File

@@ -248,7 +248,9 @@ impl HighLevelEncoder {
initial_state = initial_state.appendFLGn(CharacterSetECI::getValue(&eci))?;
}
} else {
return Err(Exceptions::illegalArgument("No ECI code for character set"));
return Err(Exceptions::illegalArgumentWith(
"No ECI code for character set",
));
}
// if self.charset != null {
// CharacterSetECI eci = CharacterSetECI.getCharacterSetECI(charset);

View File

@@ -80,7 +80,7 @@ impl State {
token.add(0, 3); // 0: FNC1
} else */
if eci > 999999 {
return Err(Exceptions::illegalArgument(
return Err(Exceptions::illegalArgumentWith(
"ECI code must be between 0 and 999999",
));
// throw new IllegalArgumentException("ECI code must be between 0 and 999999");
@@ -88,7 +88,7 @@ impl State {
let Ok(eci_digits) = encoding::all::ISO_8859_1
.encode(&format!("{eci}"), encoding::EncoderTrap::Strict)
else {
return Err(Exceptions::illegalArgumentEmpty())
return Err(Exceptions::illegalArgument)
};
// let eciDigits = Integer.toString(eci).getBytes(StandardCharsets.ISO_8859_1);
token.add(eci_digits.len() as i32, 3); // 1-6: number of ECI digits

View File

@@ -31,7 +31,7 @@ impl TokenType {
match self {
TokenType::Simple(a) => a.appendTo(bit_array, text),
TokenType::BinaryShift(a) => a.appendTo(bit_array, text),
TokenType::Empty => Err(Exceptions::illegalState(
TokenType::Empty => Err(Exceptions::illegalStateWith(
"cannot appendTo on Empty final item",
)),
}