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:
@@ -61,7 +61,7 @@ impl Reader for AztecReader {
|
|||||||
} else if let Ok(det) = detector.detect(true) {
|
} else if let Ok(det) = detector.detect(true) {
|
||||||
det
|
det
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
};
|
};
|
||||||
|
|
||||||
let points = detectorRXingResult.getPoints();
|
let points = detectorRXingResult.getPoints();
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ impl Writer for AztecWriter {
|
|||||||
if cset_name.to_lowercase() != "iso-8859-1" {
|
if cset_name.to_lowercase() != "iso-8859-1" {
|
||||||
charset = Some(
|
charset = Some(
|
||||||
encoding::label::encoding_from_whatwg_label(cset_name)
|
encoding::label::encoding_from_whatwg_label(cset_name)
|
||||||
.ok_or(Exceptions::IllegalArgumentException(None))?,
|
.ok_or(Exceptions::illegalArgumentEmpty())?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,9 +95,9 @@ fn encode(
|
|||||||
layers: i32,
|
layers: i32,
|
||||||
) -> Result<BitMatrix, Exceptions> {
|
) -> Result<BitMatrix, Exceptions> {
|
||||||
if format != BarcodeFormat::AZTEC {
|
if format != BarcodeFormat::AZTEC {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"can only encode AZTEC, but got {format:?}"
|
"can only encode AZTEC, but got {format:?}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
let aztec = if let Some(cset) = charset {
|
let aztec = if let Some(cset) = charset {
|
||||||
// dbg!(cset.name(), cset.whatwg_name());
|
// dbg!(cset.name(), cset.whatwg_name());
|
||||||
|
|||||||
@@ -164,16 +164,16 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
|||||||
result.push_str(
|
result.push_str(
|
||||||
&encdr
|
&encdr
|
||||||
.decode(&decoded_bytes, encoding::DecoderTrap::Strict)
|
.decode(&decoded_bytes, encoding::DecoderTrap::Strict)
|
||||||
.map_err(|a| Exceptions::IllegalStateException(Some(a.to_string())))?,
|
.map_err(|a| Exceptions::illegalState(a.to_string()))?,
|
||||||
);
|
);
|
||||||
|
|
||||||
decoded_bytes.clear();
|
decoded_bytes.clear();
|
||||||
match n {
|
match n {
|
||||||
0 => result.push(29 as char), // translate FNC1 as ASCII 29
|
0 => result.push(29 as char), // translate FNC1 as ASCII 29
|
||||||
7 => {
|
7 => {
|
||||||
return Err(Exceptions::FormatException(Some(
|
return Err(Exceptions::format(
|
||||||
"FLG(7) is reserved and illegal".to_owned(),
|
"FLG(7) is reserved and illegal".to_owned(),
|
||||||
)))
|
))
|
||||||
} // FLG(7) is reserved and illegal
|
} // FLG(7) is reserved and illegal
|
||||||
_ => {
|
_ => {
|
||||||
// ECI is decimal integer encoded as 1-6 codes in DIGIT mode
|
// ECI is decimal integer encoded as 1-6 codes in DIGIT mode
|
||||||
@@ -186,18 +186,15 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
|||||||
let next_digit = read_code(corrected_bits, index, 4);
|
let next_digit = read_code(corrected_bits, index, 4);
|
||||||
index += 4;
|
index += 4;
|
||||||
if !(2..=11).contains(&next_digit) {
|
if !(2..=11).contains(&next_digit) {
|
||||||
return Err(Exceptions::FormatException(Some(
|
return Err(Exceptions::format("Not a decimal digit".to_owned()));
|
||||||
"Not a decimal digit".to_owned(),
|
// Not a decimal digit
|
||||||
))); // Not a decimal digit
|
|
||||||
}
|
}
|
||||||
eci = eci * 10 + (next_digit - 2);
|
eci = eci * 10 + (next_digit - 2);
|
||||||
n -= 1;
|
n -= 1;
|
||||||
}
|
}
|
||||||
let charset_eci = CharacterSetECI::getCharacterSetECIByValue(eci);
|
let charset_eci = CharacterSetECI::getCharacterSetECIByValue(eci);
|
||||||
if charset_eci.is_err() {
|
if charset_eci.is_err() {
|
||||||
return Err(Exceptions::FormatException(Some(
|
return Err(Exceptions::format("Charset must exist".to_owned()));
|
||||||
"Charset must exist".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
encdr = CharacterSetECI::getCharset(&charset_eci?);
|
encdr = CharacterSetECI::getCharset(&charset_eci?);
|
||||||
}
|
}
|
||||||
@@ -213,12 +210,12 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
|||||||
shift_table = getTable(
|
shift_table = getTable(
|
||||||
str.chars()
|
str.chars()
|
||||||
.nth(5)
|
.nth(5)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
);
|
);
|
||||||
if str
|
if str
|
||||||
.chars()
|
.chars()
|
||||||
.nth(6)
|
.nth(6)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
== 'L'
|
== 'L'
|
||||||
{
|
{
|
||||||
latch_table = shift_table;
|
latch_table = shift_table;
|
||||||
@@ -241,9 +238,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
|||||||
if let Ok(str) = encdr.decode(&decoded_bytes, encoding::DecoderTrap::Strict) {
|
if let Ok(str) = encdr.decode(&decoded_bytes, encoding::DecoderTrap::Strict) {
|
||||||
result.push_str(&str);
|
result.push_str(&str);
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalStateException(Some(
|
return Err(Exceptions::illegalState("bad encoding".to_owned()));
|
||||||
"bad encoding".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
// result.push_str(decodedBytes.toString(encoding.name()));
|
// result.push_str(decodedBytes.toString(encoding.name()));
|
||||||
//} catch (UnsupportedEncodingException uee) {
|
//} catch (UnsupportedEncodingException uee) {
|
||||||
@@ -295,9 +290,7 @@ fn get_character(table: Table, code: u32) -> Result<&'static str, Exceptions> {
|
|||||||
Table::Mixed => Ok(MIXED_TABLE[code as usize]),
|
Table::Mixed => Ok(MIXED_TABLE[code as usize]),
|
||||||
Table::Digit => Ok(DIGIT_TABLE[code as usize]),
|
Table::Digit => Ok(DIGIT_TABLE[code as usize]),
|
||||||
Table::Punct => Ok(PUNCT_TABLE[code as usize]),
|
Table::Punct => Ok(PUNCT_TABLE[code as usize]),
|
||||||
_ => Err(Exceptions::IllegalStateException(Some(
|
_ => Err(Exceptions::illegalState("Bad table".to_owned())),
|
||||||
"Bad table".to_owned(),
|
|
||||||
))),
|
|
||||||
}
|
}
|
||||||
// switch (table) {
|
// switch (table) {
|
||||||
// case UPPER:
|
// case UPPER:
|
||||||
@@ -358,9 +351,9 @@ fn correct_bits(
|
|||||||
let num_data_codewords = ddata.getNbDatablocks();
|
let num_data_codewords = ddata.getNbDatablocks();
|
||||||
let num_codewords = rawbits.len() / codeword_size;
|
let num_codewords = rawbits.len() / codeword_size;
|
||||||
if num_codewords < num_data_codewords as usize {
|
if num_codewords < num_data_codewords as usize {
|
||||||
return Err(Exceptions::FormatException(Some(format!(
|
return Err(Exceptions::format(format!(
|
||||||
"numCodewords {num_codewords}< numDataCodewords{num_data_codewords}"
|
"numCodewords {num_codewords}< numDataCodewords{num_data_codewords}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
let mut offset = rawbits.len() % codeword_size;
|
let mut offset = rawbits.len() % codeword_size;
|
||||||
|
|
||||||
@@ -391,7 +384,7 @@ fn correct_bits(
|
|||||||
// for (int i = 0; i < numDataCodewords; i++) {
|
// for (int i = 0; i < numDataCodewords; i++) {
|
||||||
// let data_word = data_words[i];
|
// let data_word = data_words[i];
|
||||||
if data_word == &0 || data_word == &mask {
|
if data_word == &0 || data_word == &mask {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
//throw FormatException.getFormatInstance();
|
//throw FormatException.getFormatInstance();
|
||||||
} else if data_word == &1 || data_word == &(mask - 1) {
|
} else if data_word == &1 || data_word == &(mask - 1) {
|
||||||
stuffed_bits += 1;
|
stuffed_bits += 1;
|
||||||
|
|||||||
@@ -127,9 +127,7 @@ impl<'a> Detector<'_> {
|
|||||||
|| !self.is_valid(&bulls_eye_corners[2])
|
|| !self.is_valid(&bulls_eye_corners[2])
|
||||||
|| !self.is_valid(&bulls_eye_corners[3])
|
|| !self.is_valid(&bulls_eye_corners[3])
|
||||||
{
|
{
|
||||||
return Err(Exceptions::NotFoundException(Some(
|
return Err(Exceptions::notFound("no valid points".to_owned()));
|
||||||
"no valid points".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
let length = 2 * self.nb_center_layers;
|
let length = 2 * self.nb_center_layers;
|
||||||
// Get the bits around the bull's eye
|
// Get the bits around the bull's eye
|
||||||
@@ -210,9 +208,7 @@ impl<'a> Detector<'_> {
|
|||||||
return Ok(shift);
|
return Ok(shift);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(Some(
|
Err(Exceptions::notFound("rotation failure".to_owned()))
|
||||||
"rotation failure".to_owned(),
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -324,7 +320,7 @@ impl<'a> Detector<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.nb_center_layers != 5 && self.nb_center_layers != 7 {
|
if self.nb_center_layers != 5 && self.nb_center_layers != 7 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.compact = self.nb_center_layers == 5;
|
self.compact = self.nb_center_layers == 5;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ pub const WORD_SIZE: [u32; 33] = [
|
|||||||
pub fn encode_simple(data: &str) -> Result<AztecCode, Exceptions> {
|
pub fn encode_simple(data: &str) -> Result<AztecCode, Exceptions> {
|
||||||
let Ok(bytes) = encoding::all::ISO_8859_1
|
let Ok(bytes) = encoding::all::ISO_8859_1
|
||||||
.encode(data, encoding::EncoderTrap::Replace) else {
|
.encode(data, encoding::EncoderTrap::Replace) else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!("'{data}' cannot be encoded as ISO_8859_1"))));
|
return Err(Exceptions::illegalArgument(format!("'{data}' cannot be encoded as ISO_8859_1")));
|
||||||
};
|
};
|
||||||
encode_bytes_simple(&bytes)
|
encode_bytes_simple(&bytes)
|
||||||
}
|
}
|
||||||
@@ -75,9 +75,9 @@ pub fn encode(
|
|||||||
if let Ok(bytes) = encoding::all::ISO_8859_1.encode(data, encoding::EncoderTrap::Strict) {
|
if let Ok(bytes) = encoding::all::ISO_8859_1.encode(data, encoding::EncoderTrap::Strict) {
|
||||||
encode_bytes(&bytes, minECCPercent, userSpecifiedLayers)
|
encode_bytes(&bytes, minECCPercent, userSpecifiedLayers)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::IllegalArgumentException(Some(format!(
|
Err(Exceptions::illegalArgument(format!(
|
||||||
"'{data}' cannot be encoded as ISO_8859_1"
|
"'{data}' cannot be encoded as ISO_8859_1"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,9 +102,9 @@ pub fn encode_with_charset(
|
|||||||
if let Ok(bytes) = charset.encode(data, encoding::EncoderTrap::Strict) {
|
if let Ok(bytes) = charset.encode(data, encoding::EncoderTrap::Strict) {
|
||||||
encode_bytes_with_charset(&bytes, minECCPercent, userSpecifiedLayers, charset)
|
encode_bytes_with_charset(&bytes, minECCPercent, userSpecifiedLayers, charset)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::IllegalArgumentException(Some(format!(
|
Err(Exceptions::illegalArgument(format!(
|
||||||
"'{data}' cannot be encoded as ISO_8859_1"
|
"'{data}' cannot be encoded as ISO_8859_1"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,24 +178,24 @@ pub fn encode_bytes_with_charset(
|
|||||||
MAX_NB_BITS
|
MAX_NB_BITS
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Illegal value {user_specified_layers} for layers"
|
"Illegal value {user_specified_layers} for layers"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
total_bits_in_layer_var = total_bits_in_layer(layers, compact);
|
total_bits_in_layer_var = total_bits_in_layer(layers, compact);
|
||||||
word_size = WORD_SIZE[layers as usize];
|
word_size = WORD_SIZE[layers as usize];
|
||||||
let usable_bits_in_layers = total_bits_in_layer_var - (total_bits_in_layer_var % word_size);
|
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)?;
|
stuffed_bits = stuffBits(&bits, word_size as usize)?;
|
||||||
if stuffed_bits.getSize() as u32 + ecc_bits > usable_bits_in_layers {
|
if stuffed_bits.getSize() as u32 + ecc_bits > usable_bits_in_layers {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Data to large for user specified layer".to_owned(),
|
"Data to large for user specified layer".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
if compact && stuffed_bits.getSize() as u32 > word_size * 64 {
|
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
|
// Compact format only allows 64 data words, though C4 can hold more words than that
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Data to large for user specified layer".to_owned(),
|
"Data to large for user specified layer".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
word_size = 0;
|
word_size = 0;
|
||||||
@@ -207,9 +207,9 @@ pub fn encode_bytes_with_charset(
|
|||||||
loop {
|
loop {
|
||||||
// for (int i = 0; ; i++) {
|
// for (int i = 0; ; i++) {
|
||||||
if i > MAX_NB_BITS {
|
if i > MAX_NB_BITS {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Data too large for an Aztec code".to_owned(),
|
"Data too large for an Aztec code".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
compact = i <= 3;
|
compact = i <= 3;
|
||||||
layers = if compact { i + 1 } else { i };
|
layers = if compact { i + 1 } else { i };
|
||||||
@@ -482,9 +482,9 @@ fn getGF(wordSize: usize) -> Result<GenericGFRef, Exceptions> {
|
|||||||
8 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData8)),
|
8 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData8)),
|
||||||
10 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData10)),
|
10 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData10)),
|
||||||
12 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData12)),
|
12 => Ok(get_predefined_genericgf(PredefinedGenericGF::AztecData12)),
|
||||||
_ => Err(Exceptions::IllegalArgumentException(Some(format!(
|
_ => Err(Exceptions::illegalArgument(format!(
|
||||||
"Unsupported word size {wordSize}"
|
"Unsupported word size {wordSize}"
|
||||||
)))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -248,9 +248,9 @@ impl HighLevelEncoder {
|
|||||||
initial_state = initial_state.appendFLGn(CharacterSetECI::getValue(&eci))?;
|
initial_state = initial_state.appendFLGn(CharacterSetECI::getValue(&eci))?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"No ECI code for character set".to_owned(),
|
"No ECI code for character set".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
// if self.charset != null {
|
// if self.charset != null {
|
||||||
// CharacterSetECI eci = CharacterSetECI.getCharacterSetECI(charset);
|
// CharacterSetECI eci = CharacterSetECI.getCharacterSetECI(charset);
|
||||||
|
|||||||
@@ -80,15 +80,15 @@ impl State {
|
|||||||
token.add(0, 3); // 0: FNC1
|
token.add(0, 3); // 0: FNC1
|
||||||
} else */
|
} else */
|
||||||
if eci > 999999 {
|
if eci > 999999 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"ECI code must be between 0 and 999999".to_owned(),
|
"ECI code must be between 0 and 999999".to_owned(),
|
||||||
)));
|
));
|
||||||
// throw new IllegalArgumentException("ECI code must be between 0 and 999999");
|
// throw new IllegalArgumentException("ECI code must be between 0 and 999999");
|
||||||
} else {
|
} else {
|
||||||
let Ok(eci_digits) = encoding::all::ISO_8859_1
|
let Ok(eci_digits) = encoding::all::ISO_8859_1
|
||||||
.encode(&format!("{eci}"), encoding::EncoderTrap::Strict)
|
.encode(&format!("{eci}"), encoding::EncoderTrap::Strict)
|
||||||
else {
|
else {
|
||||||
return Err(Exceptions::IllegalArgumentException(None))
|
return Err(Exceptions::illegalArgumentEmpty())
|
||||||
};
|
};
|
||||||
// let eciDigits = Integer.toString(eci).getBytes(StandardCharsets.ISO_8859_1);
|
// let eciDigits = Integer.toString(eci).getBytes(StandardCharsets.ISO_8859_1);
|
||||||
token.add(eci_digits.len() as i32, 3); // 1-6: number of ECI digits
|
token.add(eci_digits.len() as i32, 3); // 1-6: number of ECI digits
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ impl TokenType {
|
|||||||
match self {
|
match self {
|
||||||
TokenType::Simple(a) => a.appendTo(bit_array, text),
|
TokenType::Simple(a) => a.appendTo(bit_array, text),
|
||||||
TokenType::BinaryShift(a) => a.appendTo(bit_array, text),
|
TokenType::BinaryShift(a) => a.appendTo(bit_array, text),
|
||||||
TokenType::Empty => Err(Exceptions::IllegalStateException(Some(String::from(
|
TokenType::Empty => Err(Exceptions::illegalState(String::from(
|
||||||
"cannot appendTo on Empty final item",
|
"cannot appendTo on Empty final item",
|
||||||
)))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,19 +120,19 @@ impl AddressBookParsedRXingResult {
|
|||||||
geo: Vec<String>,
|
geo: Vec<String>,
|
||||||
) -> Result<Self, Exceptions> {
|
) -> Result<Self, Exceptions> {
|
||||||
if phone_numbers.len() != phone_types.len() && !phone_types.is_empty() {
|
if phone_numbers.len() != phone_types.len() && !phone_types.is_empty() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Phone numbers and types lengths differ".to_owned(),
|
"Phone numbers and types lengths differ".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
if emails.len() != email_types.len() && !email_types.is_empty() {
|
if emails.len() != email_types.len() && !email_types.is_empty() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Emails and types lengths differ".to_owned(),
|
"Emails and types lengths differ".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
if addresses.len() != address_types.len() && !address_types.is_empty() {
|
if addresses.len() != address_types.len() && !address_types.is_empty() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Addresses and types lengths differ".to_owned(),
|
"Addresses and types lengths differ".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
names,
|
names,
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ impl CalendarParsedRXingResult {
|
|||||||
*/
|
*/
|
||||||
fn parseDate(when: String) -> Result<i64, Exceptions> {
|
fn parseDate(when: String) -> Result<i64, Exceptions> {
|
||||||
if !DATE_TIME.is_match(&when) {
|
if !DATE_TIME.is_match(&when) {
|
||||||
return Err(Exceptions::ParseException(Some(when)));
|
return Err(Exceptions::parse(when));
|
||||||
}
|
}
|
||||||
if when.len() == 8 {
|
if when.len() == 8 {
|
||||||
// Show only year/month/day
|
// Show only year/month/day
|
||||||
@@ -177,7 +177,7 @@ impl CalendarParsedRXingResult {
|
|||||||
// http://code.google.com/p/android/issues/detail?id=8330
|
// http://code.google.com/p/android/issues/detail?id=8330
|
||||||
return match Utc.datetime_from_str(&format!("{}T000000Z", &when,), date_format_string) {
|
return match Utc.datetime_from_str(&format!("{}T000000Z", &when,), date_format_string) {
|
||||||
Ok(dtm) => Ok(dtm.timestamp()),
|
Ok(dtm) => Ok(dtm.timestamp()),
|
||||||
Err(e) => Err(Exceptions::ParseException(Some(e.to_string()))),
|
Err(e) => Err(Exceptions::parse(e.to_string())),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// The when string can be local time, or UTC if it ends with a Z
|
// The when string can be local time, or UTC if it ends with a Z
|
||||||
@@ -185,14 +185,12 @@ impl CalendarParsedRXingResult {
|
|||||||
&& when
|
&& when
|
||||||
.chars()
|
.chars()
|
||||||
.nth(15)
|
.nth(15)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
== 'Z'
|
== 'Z'
|
||||||
{
|
{
|
||||||
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%SZ") {
|
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%SZ") {
|
||||||
Ok(dtm) => Ok(dtm.with_timezone(&Utc).timestamp()),
|
Ok(dtm) => Ok(dtm.with_timezone(&Utc).timestamp()),
|
||||||
Err(e) => Err(Exceptions::ParseException(Some(format!(
|
Err(e) => Err(Exceptions::parse(format!("couldn't parse string: {e}"))),
|
||||||
"couldn't parse string: {e}"
|
|
||||||
)))),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Try once more, with weird tz formatting
|
// Try once more, with weird tz formatting
|
||||||
@@ -202,16 +200,14 @@ impl CalendarParsedRXingResult {
|
|||||||
let tz_parsed: Tz = match tz_part.parse() {
|
let tz_parsed: Tz = match tz_part.parse() {
|
||||||
Ok(time_zone) => time_zone,
|
Ok(time_zone) => time_zone,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(Exceptions::ParseException(Some(format!(
|
return Err(Exceptions::parse(format!(
|
||||||
"couldn't parse timezone '{tz_part}': {e}"
|
"couldn't parse timezone '{tz_part}': {e}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return match Utc.datetime_from_str(time_part, "%Y%m%dT%H%M%S") {
|
return match Utc.datetime_from_str(time_part, "%Y%m%dT%H%M%S") {
|
||||||
Ok(dtm) => Ok(dtm.with_timezone(&tz_parsed).timestamp()),
|
Ok(dtm) => Ok(dtm.with_timezone(&tz_parsed).timestamp()),
|
||||||
Err(e) => Err(Exceptions::ParseException(Some(format!(
|
Err(e) => Err(Exceptions::parse(format!("couldn't parse string: {e}"))),
|
||||||
"couldn't parse string: {e}"
|
|
||||||
)))),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,9 +215,7 @@ impl CalendarParsedRXingResult {
|
|||||||
if when.len() == 15 {
|
if when.len() == 15 {
|
||||||
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%S") {
|
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%S") {
|
||||||
Ok(dtm) => Ok(dtm.timestamp()),
|
Ok(dtm) => Ok(dtm.timestamp()),
|
||||||
Err(e) => Err(Exceptions::ParseException(Some(format!(
|
Err(e) => Err(Exceptions::parse(format!("couldn't parse local time: {e}"))),
|
||||||
"couldn't parse local time: {e}"
|
|
||||||
)))),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Self::parseDateTimeString(&when)
|
Self::parseDateTimeString(&when)
|
||||||
@@ -258,7 +252,7 @@ impl CalendarParsedRXingResult {
|
|||||||
let z = parseable
|
let z = parseable
|
||||||
.as_str()
|
.as_str()
|
||||||
.parse::<i64>()
|
.parse::<i64>()
|
||||||
.map_err(|e| Exceptions::ParseException(Some(e.to_string())))?;
|
.map_err(|e| Exceptions::parse(e.to_string()))?;
|
||||||
durationMS += unit * z;
|
durationMS += unit * z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,9 +277,9 @@ impl CalendarParsedRXingResult {
|
|||||||
if let Ok(dtm) = DateTime::parse_from_str(dateTimeString, "%Y%m%dT%H%M%S") {
|
if let Ok(dtm) = DateTime::parse_from_str(dateTimeString, "%Y%m%dT%H%M%S") {
|
||||||
Ok(dtm.timestamp())
|
Ok(dtm.timestamp())
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::ParseException(Some(format!(
|
Err(Exceptions::parse(format!(
|
||||||
"Couldn't parse {dateTimeString}"
|
"Couldn't parse {dateTimeString}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
// DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
|
// DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
|
||||||
// return format.parse(dateTimeString).getTime();
|
// return format.parse(dateTimeString).getTime();
|
||||||
|
|||||||
@@ -300,9 +300,9 @@ pub fn urlDecode(encoded: &str) -> Result<String, Exceptions> {
|
|||||||
if let Ok(decoded) = decode(encoded) {
|
if let Ok(decoded) = decode(encoded) {
|
||||||
Ok(decoded.to_string())
|
Ok(decoded.to_string())
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::IllegalStateException(Some(String::from(
|
Err(Exceptions::illegalState(String::from(
|
||||||
"UnsupportedEncodingException",
|
"UnsupportedEncodingException",
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,13 +74,13 @@ fn check_checksum(vin: &str) -> Result<bool, Exceptions> {
|
|||||||
* vin_char_value(
|
* vin_char_value(
|
||||||
vin.chars()
|
vin.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IllegalArgumentException(None))?,
|
.ok_or(Exceptions::illegalArgumentEmpty())?,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
let check_to_char = vin
|
let check_to_char = vin
|
||||||
.chars()
|
.chars()
|
||||||
.nth(8)
|
.nth(8)
|
||||||
.ok_or(Exceptions::IllegalArgumentException(None))?;
|
.ok_or(Exceptions::illegalArgumentEmpty())?;
|
||||||
let expected_check_char = check_char((sum % 11) as u8)?;
|
let expected_check_char = check_char((sum % 11) as u8)?;
|
||||||
Ok(check_to_char == expected_check_char)
|
Ok(check_to_char == expected_check_char)
|
||||||
}
|
}
|
||||||
@@ -91,9 +91,9 @@ fn vin_char_value(c: char) -> Result<u32, Exceptions> {
|
|||||||
'J'..='R' => Ok((c as u8 as u32 - b'J' as u32) + 1),
|
'J'..='R' => Ok((c as u8 as u32 - b'J' as u32) + 1),
|
||||||
'S'..='Z' => Ok((c as u8 as u32 - b'S' as u32) + 2),
|
'S'..='Z' => Ok((c as u8 as u32 - b'S' as u32) + 2),
|
||||||
'0'..='9' => Ok(c as u8 as u32 - b'0' as u32),
|
'0'..='9' => Ok(c as u8 as u32 - b'0' as u32),
|
||||||
_ => Err(Exceptions::IllegalArgumentException(Some(
|
_ => Err(Exceptions::illegalArgument(
|
||||||
"vin char out of range".to_owned(),
|
"vin char out of range".to_owned(),
|
||||||
))),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,9 +103,9 @@ fn vin_position_weight(position: usize) -> Result<usize, Exceptions> {
|
|||||||
8 => Ok(10),
|
8 => Ok(10),
|
||||||
9 => Ok(0),
|
9 => Ok(0),
|
||||||
10..=17 => Ok(19 - position),
|
10..=17 => Ok(19 - position),
|
||||||
_ => Err(Exceptions::IllegalArgumentException(Some(
|
_ => Err(Exceptions::illegalArgument(
|
||||||
"vin position weight out of bounds".to_owned(),
|
"vin position weight out of bounds".to_owned(),
|
||||||
))),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,9 +113,7 @@ fn check_char(remainder: u8) -> Result<char, Exceptions> {
|
|||||||
match remainder {
|
match remainder {
|
||||||
0..=9 => Ok((b'0' + remainder) as char),
|
0..=9 => Ok((b'0' + remainder) as char),
|
||||||
10 => Ok('X'),
|
10 => Ok('X'),
|
||||||
_ => Err(Exceptions::IllegalArgumentException(Some(
|
_ => Err(Exceptions::illegalArgument("remainder too high".to_owned())),
|
||||||
"remainder too high".to_owned(),
|
|
||||||
))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,9 +126,9 @@ fn model_year(c: char) -> Result<u32, Exceptions> {
|
|||||||
'V'..='Y' => Ok((c as u8 as u32 - b'V' as u32) + 1997),
|
'V'..='Y' => Ok((c as u8 as u32 - b'V' as u32) + 1997),
|
||||||
'1'..='9' => Ok((c as u8 as u32 - b'1' as u32) + 2001),
|
'1'..='9' => Ok((c as u8 as u32 - b'1' as u32) + 2001),
|
||||||
'A'..='D' => Ok((c as u8 as u32 - b'A' as u32) + 2010),
|
'A'..='D' => Ok((c as u8 as u32 - b'A' as u32) + 2010),
|
||||||
_ => Err(Exceptions::IllegalArgumentException(Some(String::from(
|
_ => Err(Exceptions::illegalArgument(String::from(
|
||||||
"model year argument out of range",
|
"model year argument out of range",
|
||||||
)))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ impl BitArray {
|
|||||||
pub fn setRange(&mut self, start: usize, end: usize) -> Result<(), Exceptions> {
|
pub fn setRange(&mut self, start: usize, end: usize) -> Result<(), Exceptions> {
|
||||||
let mut end = end;
|
let mut end = end;
|
||||||
if end < start || end > self.size {
|
if end < start || end > self.size {
|
||||||
return Err(Exceptions::IllegalArgumentException(None));
|
return Err(Exceptions::illegalArgumentEmpty());
|
||||||
}
|
}
|
||||||
if end == start {
|
if end == start {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -211,7 +211,7 @@ impl BitArray {
|
|||||||
pub fn isRange(&self, start: usize, end: usize, value: bool) -> Result<bool, Exceptions> {
|
pub fn isRange(&self, start: usize, end: usize, value: bool) -> Result<bool, Exceptions> {
|
||||||
let mut end = end;
|
let mut end = end;
|
||||||
if end < start || end > self.size {
|
if end < start || end > self.size {
|
||||||
return Err(Exceptions::IllegalArgumentException(None));
|
return Err(Exceptions::illegalArgumentEmpty());
|
||||||
}
|
}
|
||||||
if end == start {
|
if end == start {
|
||||||
return Ok(true); // empty range matches
|
return Ok(true); // empty range matches
|
||||||
@@ -253,9 +253,9 @@ impl BitArray {
|
|||||||
*/
|
*/
|
||||||
pub fn appendBits(&mut self, value: u32, num_bits: usize) -> Result<(), Exceptions> {
|
pub fn appendBits(&mut self, value: u32, num_bits: usize) -> Result<(), Exceptions> {
|
||||||
if num_bits > 32 {
|
if num_bits > 32 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"num bits must be between 0 and 32".to_owned(),
|
"num bits must be between 0 and 32".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if num_bits == 0 {
|
if num_bits == 0 {
|
||||||
@@ -286,9 +286,7 @@ impl BitArray {
|
|||||||
|
|
||||||
pub fn xor(&mut self, other: &BitArray) -> Result<(), Exceptions> {
|
pub fn xor(&mut self, other: &BitArray) -> Result<(), Exceptions> {
|
||||||
if self.size != other.size {
|
if self.size != other.size {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument("Sizes don't match".to_owned()));
|
||||||
"Sizes don't match".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
for i in 0..self.bits.len() {
|
for i in 0..self.bits.len() {
|
||||||
//for (int i = 0; i < bits.length; i++) {
|
//for (int i = 0; i < bits.length; i++) {
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ impl BitMatrix {
|
|||||||
*/
|
*/
|
||||||
pub fn new(width: u32, height: u32) -> Result<Self, Exceptions> {
|
pub fn new(width: u32, height: u32) -> Result<Self, Exceptions> {
|
||||||
if width < 1 || height < 1 {
|
if width < 1 || height < 1 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Both dimensions must be greater than 0".to_owned(),
|
"Both dimensions must be greater than 0".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
width,
|
width,
|
||||||
@@ -137,12 +137,12 @@ impl BitMatrix {
|
|||||||
if string_representation
|
if string_representation
|
||||||
.chars()
|
.chars()
|
||||||
.nth(pos)
|
.nth(pos)
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
== '\n'
|
== '\n'
|
||||||
|| string_representation
|
|| string_representation
|
||||||
.chars()
|
.chars()
|
||||||
.nth(pos)
|
.nth(pos)
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
== '\r'
|
== '\r'
|
||||||
{
|
{
|
||||||
if bitsPos > rowStartPos {
|
if bitsPos > rowStartPos {
|
||||||
@@ -151,9 +151,9 @@ impl BitMatrix {
|
|||||||
first_run = false;
|
first_run = false;
|
||||||
rowLength = bitsPos - rowStartPos;
|
rowLength = bitsPos - rowStartPos;
|
||||||
} else if bitsPos - rowStartPos != rowLength {
|
} else if bitsPos - rowStartPos != rowLength {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"row lengths do not match".to_owned(),
|
"row lengths do not match".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
rowStartPos = bitsPos;
|
rowStartPos = bitsPos;
|
||||||
nRows += 1;
|
nRows += 1;
|
||||||
@@ -168,10 +168,10 @@ impl BitMatrix {
|
|||||||
bits[bitsPos] = false;
|
bits[bitsPos] = false;
|
||||||
bitsPos += 1;
|
bitsPos += 1;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"illegal character encountered: {}",
|
"illegal character encountered: {}",
|
||||||
string_representation[pos..].to_owned()
|
string_representation[pos..].to_owned()
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,9 +182,9 @@ impl BitMatrix {
|
|||||||
// first_run = false;
|
// first_run = false;
|
||||||
rowLength = bitsPos - rowStartPos;
|
rowLength = bitsPos - rowStartPos;
|
||||||
} else if bitsPos - rowStartPos != rowLength {
|
} else if bitsPos - rowStartPos != rowLength {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"row lengths do not match".to_owned(),
|
"row lengths do not match".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
nRows += 1;
|
nRows += 1;
|
||||||
}
|
}
|
||||||
@@ -311,9 +311,9 @@ impl BitMatrix {
|
|||||||
pub fn xor(&mut self, mask: &BitMatrix) -> Result<(), Exceptions> {
|
pub fn xor(&mut self, mask: &BitMatrix) -> Result<(), Exceptions> {
|
||||||
if self.width != mask.width || self.height != mask.height || self.row_size != mask.row_size
|
if self.width != mask.width || self.height != mask.height || self.row_size != mask.row_size
|
||||||
{
|
{
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"input matrix dimensions do not match".to_owned(),
|
"input matrix dimensions do not match".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
// let mut rowArray = BitArray::with_size(self.width as usize);
|
// let mut rowArray = BitArray::with_size(self.width as usize);
|
||||||
for y in 0..self.height {
|
for y in 0..self.height {
|
||||||
@@ -363,16 +363,16 @@ impl BitMatrix {
|
|||||||
// ));
|
// ));
|
||||||
// }
|
// }
|
||||||
if height < 1 || width < 1 {
|
if height < 1 || width < 1 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"height and width must be at least 1".to_owned(),
|
"height and width must be at least 1".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
let right = left + width;
|
let right = left + width;
|
||||||
let bottom = top + height;
|
let bottom = top + height;
|
||||||
if bottom > self.height || right > self.width {
|
if bottom > self.height || right > self.width {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"the region must fit inside the matrix".to_owned(),
|
"the region must fit inside the matrix".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
for y in top..bottom {
|
for y in top..bottom {
|
||||||
//for (int y = top; y < bottom; y++) {
|
//for (int y = top; y < bottom; y++) {
|
||||||
@@ -444,9 +444,9 @@ impl BitMatrix {
|
|||||||
self.rotate180();
|
self.rotate180();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(Exceptions::IllegalArgumentException(Some(
|
_ => Err(Exceptions::illegalArgument(
|
||||||
"degrees must be a multiple of 0, 90, 180, or 270".to_owned(),
|
"degrees must be a multiple of 0, 90, 180, or 270".to_owned(),
|
||||||
))),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,9 +70,7 @@ impl BitSource {
|
|||||||
*/
|
*/
|
||||||
pub fn readBits(&mut self, numBits: usize) -> Result<u32, Exceptions> {
|
pub fn readBits(&mut self, numBits: usize) -> Result<u32, Exceptions> {
|
||||||
if !(1..=32).contains(&numBits) || numBits > self.available() {
|
if !(1..=32).contains(&numBits) || numBits > self.available() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(numBits.to_string()));
|
||||||
numBits.to_string(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result: u32 = 0;
|
let mut result: u32 = 0;
|
||||||
|
|||||||
@@ -244,9 +244,7 @@ impl CharacterSetECI {
|
|||||||
28 => Ok(CharacterSetECI::Big5),
|
28 => Ok(CharacterSetECI::Big5),
|
||||||
29 => Ok(CharacterSetECI::GB18030),
|
29 => Ok(CharacterSetECI::GB18030),
|
||||||
30 => Ok(CharacterSetECI::EUC_KR),
|
30 => Ok(CharacterSetECI::EUC_KR),
|
||||||
_ => Err(Exceptions::NotFoundException(Some(
|
_ => Err(Exceptions::notFound("Bad ECI Value".to_owned())),
|
||||||
"Bad ECI Value".to_owned(),
|
|
||||||
))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ impl GridSampler for DefaultGridSampler {
|
|||||||
transform: &PerspectiveTransform,
|
transform: &PerspectiveTransform,
|
||||||
) -> Result<BitMatrix, Exceptions> {
|
) -> Result<BitMatrix, Exceptions> {
|
||||||
if dimensionX == 0 || dimensionY == 0 {
|
if dimensionX == 0 || dimensionY == 0 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
let mut bits = BitMatrix::new(dimensionX, dimensionY)?;
|
let mut bits = BitMatrix::new(dimensionX, dimensionY)?;
|
||||||
let mut points = vec![0.0; 2 * dimensionX as usize];
|
let mut points = vec![0.0; 2 * dimensionX as usize];
|
||||||
@@ -92,15 +92,15 @@ impl GridSampler for DefaultGridSampler {
|
|||||||
// for (int x = 0; x < max; x += 2) {
|
// for (int x = 0; x < max; x += 2) {
|
||||||
// if points[x] as u32 >= image.getWidth() || points[x + 1] as u32 >= image.getHeight()
|
// if points[x] as u32 >= image.getWidth() || points[x + 1] as u32 >= image.getHeight()
|
||||||
// {
|
// {
|
||||||
// return Err(Exceptions::NotFoundException(Some(
|
// return Err(Exceptions::notFound(
|
||||||
// "index out of bounds, see documentation in file for explanation".to_owned(),
|
// "index out of bounds, see documentation in file for explanation".to_owned(),
|
||||||
// )));
|
// ));
|
||||||
// }
|
// }
|
||||||
if image
|
if image
|
||||||
.try_get(points[x] as u32, points[x + 1] as u32)
|
.try_get(points[x] as u32, points[x + 1] as u32)
|
||||||
.ok_or(Exceptions::NotFoundException(Some(
|
.ok_or(Exceptions::notFound(
|
||||||
"index out of bounds, see documentation in file for explanation".to_owned(),
|
"index out of bounds, see documentation in file for explanation".to_owned(),
|
||||||
)))?
|
))?
|
||||||
{
|
{
|
||||||
// Black(-ish) pixel
|
// Black(-ish) pixel
|
||||||
bits.set(x as u32 / 2, y);
|
bits.set(x as u32 / 2, y);
|
||||||
|
|||||||
@@ -200,13 +200,13 @@ impl<'a> MonochromeRectangleDetector<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
lastRange_z = range;
|
lastRange_z = range;
|
||||||
y += deltaY;
|
y += deltaY;
|
||||||
x += deltaX
|
x += deltaX
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ impl<'a> WhiteRectangleDetector<'_> {
|
|||||||
|| downInit >= image.getHeight() as i32
|
|| downInit >= image.getHeight() as i32
|
||||||
|| rightInit >= image.getWidth() as i32
|
|| rightInit >= image.getWidth() as i32
|
||||||
{
|
{
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(WhiteRectangleDetector {
|
Ok(WhiteRectangleDetector {
|
||||||
@@ -223,7 +223,7 @@ impl<'a> WhiteRectangleDetector<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if z.is_none() {
|
if z.is_none() {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut t: Option<RXingResultPoint> = None;
|
let mut t: Option<RXingResultPoint> = None;
|
||||||
@@ -241,7 +241,7 @@ impl<'a> WhiteRectangleDetector<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if t.is_none() {
|
if t.is_none() {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut x: Option<RXingResultPoint> = None;
|
let mut x: Option<RXingResultPoint> = None;
|
||||||
@@ -259,7 +259,7 @@ impl<'a> WhiteRectangleDetector<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if x.is_none() {
|
if x.is_none() {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut y: Option<RXingResultPoint> = None;
|
let mut y: Option<RXingResultPoint> = None;
|
||||||
@@ -277,12 +277,12 @@ impl<'a> WhiteRectangleDetector<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if y.is_none() {
|
if y.is_none() {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self.center_edges(&y.unwrap(), &z.unwrap(), &x.unwrap(), &t.unwrap()))
|
Ok(self.center_edges(&y.unwrap(), &z.unwrap(), &x.unwrap(), &t.unwrap()))
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -233,9 +233,9 @@ impl GlobalHistogramBinarizer {
|
|||||||
// If there is too little contrast in the image to pick a meaningful black point, throw rather
|
// If there is too little contrast in the image to pick a meaningful black point, throw rather
|
||||||
// than waste time trying to decode the image, and risk false positives.
|
// than waste time trying to decode the image, and risk false positives.
|
||||||
if secondPeak - firstPeak <= numBuckets / 16 {
|
if secondPeak - firstPeak <= numBuckets / 16 {
|
||||||
return Err(Exceptions::NotFoundException(Some(
|
return Err(Exceptions::notFound(
|
||||||
"secondPeak - firstPeak <= numBuckets / 16 ".to_owned(),
|
"secondPeak - firstPeak <= numBuckets / 16 ".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a valley between them that is low and closer to the white peak.
|
// Find a valley between them that is low and closer to the white peak.
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ pub trait GridSampler {
|
|||||||
let x = points[offset] as i32;
|
let x = points[offset] as i32;
|
||||||
let y = points[offset + 1] as i32;
|
let y = points[offset + 1] as i32;
|
||||||
if x < -1 || x > width as i32 || y < -1 || y > height as i32 {
|
if x < -1 || x > width as i32 || y < -1 || y > height as i32 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
nudged = false;
|
nudged = false;
|
||||||
if x == -1 {
|
if x == -1 {
|
||||||
@@ -172,7 +172,7 @@ pub trait GridSampler {
|
|||||||
let x = points[offset as usize] as i32;
|
let x = points[offset as usize] as i32;
|
||||||
let y = points[offset as usize + 1] as i32;
|
let y = points[offset as usize + 1] as i32;
|
||||||
if x < -1 || x > width as i32 || y < -1 || y > height as i32 {
|
if x < -1 || x > width as i32 || y < -1 || y > height as i32 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
nudged = false;
|
nudged = false;
|
||||||
if x == -1 {
|
if x == -1 {
|
||||||
|
|||||||
@@ -67,14 +67,12 @@ impl ECIInput for MinimalECIInput {
|
|||||||
*/
|
*/
|
||||||
fn charAt(&self, index: usize) -> Result<char, Exceptions> {
|
fn charAt(&self, index: usize) -> Result<char, Exceptions> {
|
||||||
if index >= self.length() {
|
if index >= self.length() {
|
||||||
return Err(Exceptions::IndexOutOfBoundsException(Some(
|
return Err(Exceptions::indexOutOfBounds(index.to_string()));
|
||||||
index.to_string(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
if self.isECI(index as u32)? {
|
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"
|
"value at {index} is not a character but an ECI"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
if self.isFNC1(index)? {
|
if self.isFNC1(index)? {
|
||||||
Ok(self.fnc1 as u8 as char)
|
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> {
|
fn subSequence(&self, start: usize, end: usize) -> Result<Vec<char>, Exceptions> {
|
||||||
if start > end || end > self.length() {
|
if start > end || end > self.length() {
|
||||||
return Err(Exceptions::IndexOutOfBoundsException(None));
|
return Err(Exceptions::indexOutOfBoundsEmpty());
|
||||||
}
|
}
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
for i in start..end {
|
for i in start..end {
|
||||||
// for (int i = start; i < end; i++) {
|
// for (int i = start; i < end; i++) {
|
||||||
if self.isECI(i as u32)? {
|
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"
|
"value at {i} is not a character but an ECI"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
result.push_str(&self.charAt(i)?.to_string());
|
result.push_str(&self.charAt(i)?.to_string());
|
||||||
}
|
}
|
||||||
@@ -133,7 +131,7 @@ impl ECIInput for MinimalECIInput {
|
|||||||
*/
|
*/
|
||||||
fn isECI(&self, index: u32) -> Result<bool, Exceptions> {
|
fn isECI(&self, index: u32) -> Result<bool, Exceptions> {
|
||||||
if index >= self.length() as u32 {
|
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)
|
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> {
|
fn getECIValue(&self, index: usize) -> Result<i32, Exceptions> {
|
||||||
if index >= self.length() {
|
if index >= self.length() {
|
||||||
return Err(Exceptions::IndexOutOfBoundsException(None));
|
return Err(Exceptions::indexOutOfBoundsEmpty());
|
||||||
}
|
}
|
||||||
if !self.isECI(index as u32)? {
|
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"
|
"value at {index} is not an ECI but a character"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
Ok((self.bytes[index] as u32 - 256) as i32)
|
Ok((self.bytes[index] as u32 - 256) as i32)
|
||||||
}
|
}
|
||||||
@@ -250,7 +248,7 @@ impl MinimalECIInput {
|
|||||||
*/
|
*/
|
||||||
pub fn isFNC1(&self, index: usize) -> Result<bool, Exceptions> {
|
pub fn isFNC1(&self, index: usize) -> Result<bool, Exceptions> {
|
||||||
if index >= self.length() {
|
if index >= self.length() {
|
||||||
return Err(Exceptions::IndexOutOfBoundsException(None));
|
return Err(Exceptions::indexOutOfBoundsEmpty());
|
||||||
}
|
}
|
||||||
Ok(self.bytes[index] == 1000)
|
Ok(self.bytes[index] == 1000)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ impl OtsuLevelBinarizer {
|
|||||||
fn generate_threshold_matrix(source: &dyn LuminanceSource) -> Result<BitMatrix, Exceptions> {
|
fn generate_threshold_matrix(source: &dyn LuminanceSource) -> Result<BitMatrix, Exceptions> {
|
||||||
let image_buffer = {
|
let image_buffer = {
|
||||||
let Some(buff) : Option<ImageBuffer<Luma<u8>,Vec<u8>>> = ImageBuffer::from_vec(source.getWidth() as u32, source.getHeight() as u32, source.getMatrix()) else {
|
let Some(buff) : Option<ImageBuffer<Luma<u8>,Vec<u8>>> = ImageBuffer::from_vec(source.getWidth() as u32, source.getHeight() as u32, source.getMatrix()) else {
|
||||||
return Err(Exceptions::IllegalArgumentException(None))
|
return Err(Exceptions::illegalArgumentEmpty())
|
||||||
};
|
};
|
||||||
buff
|
buff
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ impl GenericGF {
|
|||||||
*/
|
*/
|
||||||
pub fn log(&self, a: i32) -> Result<i32, Exceptions> {
|
pub fn log(&self, a: i32) -> Result<i32, Exceptions> {
|
||||||
if a == 0 {
|
if a == 0 {
|
||||||
return Err(Exceptions::IllegalArgumentException(None));
|
return Err(Exceptions::illegalArgumentEmpty());
|
||||||
}
|
}
|
||||||
// let pos: usize = a.try_into().unwrap();
|
// let pos: usize = a.try_into().unwrap();
|
||||||
Ok(self.logTable[a as usize])
|
Ok(self.logTable[a as usize])
|
||||||
@@ -144,7 +144,7 @@ impl GenericGF {
|
|||||||
*/
|
*/
|
||||||
pub fn inverse(&self, a: i32) -> Result<i32, Exceptions> {
|
pub fn inverse(&self, a: i32) -> Result<i32, Exceptions> {
|
||||||
if a == 0 {
|
if a == 0 {
|
||||||
return Err(Exceptions::ArithmeticException(None));
|
return Err(Exceptions::arithmeticEmpty());
|
||||||
}
|
}
|
||||||
let log_t_loc: usize = a as usize;
|
let log_t_loc: usize = a as usize;
|
||||||
let loc: usize = ((self.size as i32) - self.logTable[log_t_loc] - 1) as usize;
|
let loc: usize = ((self.size as i32) - self.logTable[log_t_loc] - 1) as usize;
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ impl GenericGFPoly {
|
|||||||
*/
|
*/
|
||||||
pub fn new(field: GenericGFRef, coefficients: &[i32]) -> Result<Self, Exceptions> {
|
pub fn new(field: GenericGFRef, coefficients: &[i32]) -> Result<Self, Exceptions> {
|
||||||
if coefficients.is_empty() {
|
if coefficients.is_empty() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(String::from(
|
return Err(Exceptions::illegalArgument(String::from(
|
||||||
"coefficients cannot be empty",
|
"coefficients cannot be empty",
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
field,
|
field,
|
||||||
@@ -140,9 +140,9 @@ impl GenericGFPoly {
|
|||||||
|
|
||||||
pub fn addOrSubtract(&self, other: &GenericGFPoly) -> Result<GenericGFPoly, Exceptions> {
|
pub fn addOrSubtract(&self, other: &GenericGFPoly) -> Result<GenericGFPoly, Exceptions> {
|
||||||
if self.field != other.field {
|
if self.field != other.field {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"GenericGFPolys do not have same GenericGF field".to_owned(),
|
"GenericGFPolys do not have same GenericGF field".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
if self.isZero() {
|
if self.isZero() {
|
||||||
return Ok(other.clone());
|
return Ok(other.clone());
|
||||||
@@ -177,9 +177,9 @@ impl GenericGFPoly {
|
|||||||
pub fn multiply(&self, other: &GenericGFPoly) -> Result<GenericGFPoly, Exceptions> {
|
pub fn multiply(&self, other: &GenericGFPoly) -> Result<GenericGFPoly, Exceptions> {
|
||||||
if self.field != other.field {
|
if self.field != other.field {
|
||||||
//if (!field.equals(other.field)) {
|
//if (!field.equals(other.field)) {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"GenericGFPolys do not have same GenericGF field".to_owned(),
|
"GenericGFPolys do not have same GenericGF field".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
if self.isZero() || other.isZero() {
|
if self.isZero() || other.isZero() {
|
||||||
return Ok(self.getZero());
|
return Ok(self.getZero());
|
||||||
@@ -252,14 +252,12 @@ impl GenericGFPoly {
|
|||||||
other: &GenericGFPoly,
|
other: &GenericGFPoly,
|
||||||
) -> Result<(GenericGFPoly, GenericGFPoly), Exceptions> {
|
) -> Result<(GenericGFPoly, GenericGFPoly), Exceptions> {
|
||||||
if self.field != other.field {
|
if self.field != other.field {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"GenericGFPolys do not have same GenericGF field".to_owned(),
|
"GenericGFPolys do not have same GenericGF field".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
if other.isZero() {
|
if other.isZero() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument("Divide by 0".to_owned()));
|
||||||
"Divide by 0".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut quotient = self.getZero();
|
let mut quotient = self.getZero();
|
||||||
@@ -268,11 +266,7 @@ impl GenericGFPoly {
|
|||||||
let denominator_leading_term = other.getCoefficient(other.getDegree());
|
let denominator_leading_term = other.getCoefficient(other.getDegree());
|
||||||
let inverse_denominator_leading_term = match self.field.inverse(denominator_leading_term) {
|
let inverse_denominator_leading_term = match self.field.inverse(denominator_leading_term) {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(_issue) => {
|
Err(_issue) => return Err(Exceptions::illegalArgument("arithmetic issue".to_owned())),
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
|
||||||
"arithmetic issue".to_owned(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
while remainder.getDegree() >= other.getDegree() && !remainder.isZero() {
|
while remainder.getDegree() >= other.getDegree() && !remainder.isZero() {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ impl ReedSolomonDecoder {
|
|||||||
return Ok(0);
|
return Ok(0);
|
||||||
}
|
}
|
||||||
let Ok(syndrome) = GenericGFPoly::new(self.field, &syndromeCoefficients) else {
|
let Ok(syndrome) = GenericGFPoly::new(self.field, &syndromeCoefficients) else {
|
||||||
return Err(Exceptions::ReedSolomonException(None));
|
return Err(Exceptions::reedSolomonEmpty());
|
||||||
};
|
};
|
||||||
let sigmaOmega = self.runEuclideanAlgorithm(
|
let sigmaOmega = self.runEuclideanAlgorithm(
|
||||||
&GenericGF::buildMonomial(self.field, twoS as usize, 1),
|
&GenericGF::buildMonomial(self.field, twoS as usize, 1),
|
||||||
@@ -92,15 +92,11 @@ impl ReedSolomonDecoder {
|
|||||||
//for (int i = 0; i < errorLocations.length; i++) {
|
//for (int i = 0; i < errorLocations.length; i++) {
|
||||||
let log_value = self.field.log(errorLocations[i] as i32)?;
|
let log_value = self.field.log(errorLocations[i] as i32)?;
|
||||||
if log_value > received.len() as i32 - 1 {
|
if log_value > received.len() as i32 - 1 {
|
||||||
return Err(Exceptions::ReedSolomonException(Some(
|
return Err(Exceptions::reedSolomon("Bad error location".to_owned()));
|
||||||
"Bad error location".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
let position: isize = received.len() as isize - 1 - log_value as isize;
|
let position: isize = received.len() as isize - 1 - log_value as isize;
|
||||||
if position < 0 {
|
if position < 0 {
|
||||||
return Err(Exceptions::ReedSolomonException(Some(
|
return Err(Exceptions::reedSolomon("Bad error location".to_owned()));
|
||||||
"Bad error location".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
received[position as usize] =
|
received[position as usize] =
|
||||||
GenericGF::addOrSubtract(received[position as usize], errorMagnitudes[i]);
|
GenericGF::addOrSubtract(received[position as usize], errorMagnitudes[i]);
|
||||||
@@ -138,9 +134,7 @@ impl ReedSolomonDecoder {
|
|||||||
// Divide rLastLast by rLast, with quotient in q and remainder in r
|
// Divide rLastLast by rLast, with quotient in q and remainder in r
|
||||||
if rLast.isZero() {
|
if rLast.isZero() {
|
||||||
// Oops, Euclidean algorithm already terminated?
|
// Oops, Euclidean algorithm already terminated?
|
||||||
return Err(Exceptions::ReedSolomonException(Some(
|
return Err(Exceptions::reedSolomon("r_{i-1} was zero".to_owned()));
|
||||||
"r_{i-1} was zero".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
r = rLastLast;
|
r = rLastLast;
|
||||||
let mut q = r.getZero();
|
let mut q = r.getZero();
|
||||||
@@ -158,26 +152,20 @@ impl ReedSolomonDecoder {
|
|||||||
t = (q.multiply(&tLast)?).addOrSubtract(&tLastLast)?;
|
t = (q.multiply(&tLast)?).addOrSubtract(&tLastLast)?;
|
||||||
|
|
||||||
if r.getDegree() >= rLast.getDegree() {
|
if r.getDegree() >= rLast.getDegree() {
|
||||||
return Err(Exceptions::ReedSolomonException(Some(format!(
|
return Err(Exceptions::reedSolomon(format!(
|
||||||
"Division algorithm failed to reduce polynomial? r: {r}, rLast: {rLast}"
|
"Division algorithm failed to reduce polynomial? r: {r}, rLast: {rLast}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sigmaTildeAtZero = t.getCoefficient(0);
|
let sigmaTildeAtZero = t.getCoefficient(0);
|
||||||
if sigmaTildeAtZero == 0 {
|
if sigmaTildeAtZero == 0 {
|
||||||
return Err(Exceptions::ReedSolomonException(Some(
|
return Err(Exceptions::reedSolomon("sigmaTilde(0) was zero".to_owned()));
|
||||||
"sigmaTilde(0) was zero".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let inverse = match self.field.inverse(sigmaTildeAtZero) {
|
let inverse = match self.field.inverse(sigmaTildeAtZero) {
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
Err(_err) => {
|
Err(_err) => return Err(Exceptions::reedSolomon("ArithmetricException".to_owned())),
|
||||||
return Err(Exceptions::ReedSolomonException(Some(
|
|
||||||
"ArithmetricException".to_owned(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let sigma = t.multiply_with_scalar(inverse);
|
let sigma = t.multiply_with_scalar(inverse);
|
||||||
let omega = r.multiply_with_scalar(inverse);
|
let omega = r.multiply_with_scalar(inverse);
|
||||||
@@ -205,9 +193,9 @@ impl ReedSolomonDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if e != numErrors {
|
if e != numErrors {
|
||||||
return Err(Exceptions::ReedSolomonException(Some(
|
return Err(Exceptions::reedSolomon(
|
||||||
"Error locator degree does not match number of roots".to_owned(),
|
"Error locator degree does not match number of roots".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,15 +73,15 @@ impl ReedSolomonEncoder {
|
|||||||
|
|
||||||
pub fn encode(&mut self, to_encode: &mut Vec<i32>, ec_bytes: usize) -> Result<(), Exceptions> {
|
pub fn encode(&mut self, to_encode: &mut Vec<i32>, ec_bytes: usize) -> Result<(), Exceptions> {
|
||||||
if ec_bytes == 0 {
|
if ec_bytes == 0 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"No error correction bytes".to_owned(),
|
"No error correction bytes".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
let data_bytes = to_encode.len() - ec_bytes;
|
let data_bytes = to_encode.len() - ec_bytes;
|
||||||
if data_bytes == 0 {
|
if data_bytes == 0 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"No data bytes provided".to_owned(),
|
"No data bytes provided".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
let fld = self.field;
|
let fld = self.field;
|
||||||
let generator = self.buildGenerator(ec_bytes);
|
let generator = self.buildGenerator(ec_bytes);
|
||||||
@@ -91,7 +91,7 @@ impl ReedSolomonEncoder {
|
|||||||
let mut info = GenericGFPoly::new(fld, &info_coefficients)?;
|
let mut info = GenericGFPoly::new(fld, &info_coefficients)?;
|
||||||
info = info.multiply_by_monomial(ec_bytes, 1)?;
|
info = info.multiply_by_monomial(ec_bytes, 1)?;
|
||||||
let remainder = &info
|
let remainder = &info
|
||||||
.divide(generator.ok_or(Exceptions::ReedSolomonException(None))?)?
|
.divide(generator.ok_or(Exceptions::reedSolomonEmpty())?)?
|
||||||
.1;
|
.1;
|
||||||
let coefficients = remainder.getCoefficients();
|
let coefficients = remainder.getCoefficients();
|
||||||
let num_zero_coefficients = ec_bytes - coefficients.len();
|
let num_zero_coefficients = ec_bytes - coefficients.len();
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ impl Reader for DataMatrixReader {
|
|||||||
DECODER.decode(&bits)?
|
DECODER.decode(&bits)?
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
};
|
};
|
||||||
|
|
||||||
// decoderRXingResult = DECODER.decode(detectorRXingResult.getBits())?;
|
// decoderRXingResult = DECODER.decode(detectorRXingResult.getBits())?;
|
||||||
@@ -181,10 +181,10 @@ impl DataMatrixReader {
|
|||||||
*/
|
*/
|
||||||
fn extractPureBits(&self, image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
fn extractPureBits(&self, image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
||||||
let Some(leftTopBlack) = image.getTopLeftOnBit() else {
|
let Some(leftTopBlack) = image.getTopLeftOnBit() else {
|
||||||
return Err(Exceptions::NotFoundException(None))
|
return Err(Exceptions::notFoundEmpty())
|
||||||
};
|
};
|
||||||
let Some(rightBottomBlack) = image.getBottomRightOnBit()else {
|
let Some(rightBottomBlack) = image.getBottomRightOnBit()else {
|
||||||
return Err(Exceptions::NotFoundException(None))
|
return Err(Exceptions::notFoundEmpty())
|
||||||
};
|
};
|
||||||
|
|
||||||
let moduleSize = Self::moduleSize(&leftTopBlack, image)?;
|
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 matrixWidth = (right as i32 - left as i32 + 1) / moduleSize as i32;
|
||||||
let matrixHeight = (bottom as i32 - top as i32 + 1) / moduleSize as i32;
|
let matrixHeight = (bottom as i32 - top as i32 + 1) / moduleSize as i32;
|
||||||
if matrixWidth <= 0 || matrixHeight <= 0 {
|
if matrixWidth <= 0 || matrixHeight <= 0 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
// throw NotFoundException.getNotFoundInstance();
|
// throw NotFoundException.getNotFoundInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,12 +234,12 @@ impl DataMatrixReader {
|
|||||||
x += 1;
|
x += 1;
|
||||||
}
|
}
|
||||||
if x == width {
|
if x == width {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let moduleSize = x - leftTopBlack[0];
|
let moduleSize = x - leftTopBlack[0];
|
||||||
if moduleSize == 0 {
|
if moduleSize == 0 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(moduleSize)
|
Ok(moduleSize)
|
||||||
|
|||||||
@@ -60,21 +60,21 @@ impl Writer for DataMatrixWriter {
|
|||||||
hints: &crate::EncodingHintDictionary,
|
hints: &crate::EncodingHintDictionary,
|
||||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||||
if contents.is_empty() {
|
if contents.is_empty() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Found empty contents".to_owned(),
|
"Found empty contents".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if format != &BarcodeFormat::DATA_MATRIX {
|
if format != &BarcodeFormat::DATA_MATRIX {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Can only encode DATA_MATRIX, but got {format:?}"
|
"Can only encode DATA_MATRIX, but got {format:?}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if width < 0 || height < 0 {
|
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}"
|
"Requested dimensions can't be negative: {width}x{height}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get force shape & min / max size
|
// Try to get force shape & min / max size
|
||||||
@@ -123,7 +123,7 @@ impl Writer for DataMatrixWriter {
|
|||||||
if hasEncodingHint {
|
if hasEncodingHint {
|
||||||
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
|
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
|
||||||
hints.get(&EncodeHintType::CHARACTER_SET) else {
|
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 = encoding::label::encoding_from_whatwg_label(char_set_name);
|
||||||
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
|
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
|
||||||
@@ -157,7 +157,7 @@ impl Writer for DataMatrixWriter {
|
|||||||
|
|
||||||
let symbol_lookup = SymbolInfoLookup::new();
|
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 {
|
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
|
//2. step: ECC generation
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ impl BitMatrixParser {
|
|||||||
pub fn new(bitMatrix: &BitMatrix) -> Result<Self, Exceptions> {
|
pub fn new(bitMatrix: &BitMatrix) -> Result<Self, Exceptions> {
|
||||||
let dimension = bitMatrix.getHeight();
|
let dimension = bitMatrix.getHeight();
|
||||||
if !(8..=144).contains(&dimension) || (dimension & 0x01) != 0 {
|
if !(8..=144).contains(&dimension) || (dimension & 0x01) != 0 {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let version = Self::readVersion(bitMatrix)?;
|
let version = Self::readVersion(bitMatrix)?;
|
||||||
@@ -178,7 +178,7 @@ impl BitMatrixParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resultOffset != self.version.getTotalCodewords() as usize {
|
if resultOffset != self.version.getTotalCodewords() as usize {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
@@ -456,9 +456,9 @@ impl BitMatrixParser {
|
|||||||
let symbolSizeColumns = version.getSymbolSizeColumns();
|
let symbolSizeColumns = version.getSymbolSizeColumns();
|
||||||
|
|
||||||
if bitMatrix.getHeight() != symbolSizeRows {
|
if bitMatrix.getHeight() != symbolSizeRows {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Dimension of bitMatrix must match the version size".to_owned(),
|
"Dimension of bitMatrix must match the version size".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let dataRegionSizeRows = version.getDataRegionSizeRows();
|
let dataRegionSizeRows = version.getDataRegionSizeRows();
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ impl DataBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rawCodewordsOffset != rawCodewords.len() {
|
if rawCodewordsOffset != rawCodewords.len() {
|
||||||
return Err(Exceptions::IllegalArgumentException(None));
|
return Err(Exceptions::illegalArgumentEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(result)
|
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
|
isECIencoded = true; // ECI detection only, atm continue decoding as ASCII
|
||||||
mode = Mode::ASCII_ENCODE;
|
mode = Mode::ASCII_ENCODE;
|
||||||
}
|
}
|
||||||
_ => return Err(Exceptions::FormatException(None)),
|
_ => return Err(Exceptions::formatEmpty()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(mode != Mode::PAD_ENCODE && bits.available() > 0) {
|
if !(mode != Mode::PAD_ENCODE && bits.available() > 0) {
|
||||||
@@ -225,16 +225,14 @@ fn decodeAsciiSegment(
|
|||||||
loop {
|
loop {
|
||||||
let mut oneByte = bits.readBits(8)?;
|
let mut oneByte = bits.readBits(8)?;
|
||||||
match oneByte {
|
match oneByte {
|
||||||
0 => return Err(Exceptions::FormatException(None)),
|
0 => return Err(Exceptions::formatEmpty()),
|
||||||
1..=128 => {
|
1..=128 => {
|
||||||
// ASCII data (ASCII value + 1)
|
// ASCII data (ASCII value + 1)
|
||||||
if upperShift {
|
if upperShift {
|
||||||
oneByte += 128;
|
oneByte += 128;
|
||||||
//upperShift = false;
|
//upperShift = false;
|
||||||
}
|
}
|
||||||
result.append_char(
|
result.append_char(char::from_u32(oneByte - 1).ok_or(Exceptions::parseEmpty())?);
|
||||||
char::from_u32(oneByte - 1).ok_or(Exceptions::ParseException(None))?,
|
|
||||||
);
|
|
||||||
return Ok(Mode::ASCII_ENCODE);
|
return Ok(Mode::ASCII_ENCODE);
|
||||||
}
|
}
|
||||||
129 => return Ok(Mode::PAD_ENCODE), // Pad
|
129 => return Ok(Mode::PAD_ENCODE), // Pad
|
||||||
@@ -280,9 +278,9 @@ fn decodeAsciiSegment(
|
|||||||
if !firstCodeword
|
if !firstCodeword
|
||||||
// Must be first ISO 16022:2006 5.6.1
|
// 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(),
|
"structured append tag must be first code word".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
parse_structured_append(bits, &mut sai)?;
|
parse_structured_append(bits, &mut sai)?;
|
||||||
firstFNC1Position = 5;
|
firstFNC1Position = 5;
|
||||||
@@ -333,7 +331,7 @@ fn decodeAsciiSegment(
|
|||||||
// Not to be used in ASCII encodation
|
// Not to be used in ASCII encodation
|
||||||
// but work around encoders that end with 254, latch back to ASCII
|
// but work around encoders that end with 254, latch back to ASCII
|
||||||
if oneByte != 254 || bits.available() != 0 {
|
if oneByte != 254 || bits.available() != 0 {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,26 +386,24 @@ fn decodeC40Segment(
|
|||||||
if upperShift {
|
if upperShift {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(c40char as u32 + 128)
|
char::from_u32(c40char as u32 + 128)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
} else {
|
} else {
|
||||||
result.append_char(c40char);
|
result.append_char(c40char);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
if upperShift {
|
if upperShift {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(cValue + 128).ok_or(Exceptions::ParseException(None))?,
|
char::from_u32(cValue + 128).ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
} else {
|
} else {
|
||||||
result.append_char(
|
result.append_char(char::from_u32(cValue).ok_or(Exceptions::parseEmpty())?);
|
||||||
char::from_u32(cValue).ok_or(Exceptions::ParseException(None))?,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
shift = 0;
|
shift = 0;
|
||||||
}
|
}
|
||||||
@@ -417,7 +413,7 @@ fn decodeC40Segment(
|
|||||||
if upperShift {
|
if upperShift {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(c40char as u32 + 128)
|
char::from_u32(c40char as u32 + 128)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -436,7 +432,7 @@ fn decodeC40Segment(
|
|||||||
upperShift = true
|
upperShift = true
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => return Err(Exceptions::FormatException(None)),
|
_ => return Err(Exceptions::formatEmpty()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shift = 0;
|
shift = 0;
|
||||||
@@ -444,18 +440,18 @@ fn decodeC40Segment(
|
|||||||
3 => {
|
3 => {
|
||||||
if upperShift {
|
if upperShift {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(cValue + 224).ok_or(Exceptions::ParseException(None))?,
|
char::from_u32(cValue + 224).ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
} else {
|
} else {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(cValue + 96).ok_or(Exceptions::ParseException(None))?,
|
char::from_u32(cValue + 96).ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
shift = 0;
|
shift = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => return Err(Exceptions::FormatException(None)),
|
_ => return Err(Exceptions::formatEmpty()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bits.available() == 0 {
|
if bits.available() == 0 {
|
||||||
@@ -505,26 +501,24 @@ fn decodeTextSegment(
|
|||||||
if upperShift {
|
if upperShift {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(textChar as u32 + 128)
|
char::from_u32(textChar as u32 + 128)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
} else {
|
} else {
|
||||||
result.append_char(textChar);
|
result.append_char(textChar);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
if upperShift {
|
if upperShift {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(cValue + 128).ok_or(Exceptions::ParseException(None))?,
|
char::from_u32(cValue + 128).ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
} else {
|
} else {
|
||||||
result.append_char(
|
result.append_char(char::from_u32(cValue).ok_or(Exceptions::parseEmpty())?);
|
||||||
char::from_u32(cValue).ok_or(Exceptions::ParseException(None))?,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
shift = 0;
|
shift = 0;
|
||||||
}
|
}
|
||||||
@@ -536,7 +530,7 @@ fn decodeTextSegment(
|
|||||||
if upperShift {
|
if upperShift {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(textChar as u32 + 128)
|
char::from_u32(textChar as u32 + 128)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -555,7 +549,7 @@ fn decodeTextSegment(
|
|||||||
upperShift = true
|
upperShift = true
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => return Err(Exceptions::FormatException(None)),
|
_ => return Err(Exceptions::formatEmpty()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shift = 0;
|
shift = 0;
|
||||||
@@ -566,7 +560,7 @@ fn decodeTextSegment(
|
|||||||
if upperShift {
|
if upperShift {
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(textChar as u32 + 128)
|
char::from_u32(textChar as u32 + 128)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
upperShift = false;
|
upperShift = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -574,11 +568,11 @@ fn decodeTextSegment(
|
|||||||
}
|
}
|
||||||
shift = 0;
|
shift = 0;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => return Err(Exceptions::FormatException(None)),
|
_ => return Err(Exceptions::formatEmpty()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bits.available() == 0 {
|
if bits.available() == 0 {
|
||||||
@@ -645,15 +639,15 @@ fn decodeAnsiX12Segment(
|
|||||||
if cValue < 14 {
|
if cValue < 14 {
|
||||||
// 0 - 9
|
// 0 - 9
|
||||||
result.append_char(
|
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 {
|
} else if cValue < 40 {
|
||||||
// A - Z
|
// A - Z
|
||||||
result.append_char(
|
result.append_char(
|
||||||
char::from_u32(cValue + 51).ok_or(Exceptions::ParseException(None))?,
|
char::from_u32(cValue + 51).ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -708,8 +702,7 @@ fn decodeEdifactSegment(
|
|||||||
// no 1 in the leading (6th) bit
|
// no 1 in the leading (6th) bit
|
||||||
edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value
|
edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value
|
||||||
}
|
}
|
||||||
result
|
result.append_char(char::from_u32(edifactValue).ok_or(Exceptions::parseEmpty())?);
|
||||||
.append_char(char::from_u32(edifactValue).ok_or(Exceptions::ParseException(None))?);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if bits.available() == 0 {
|
if bits.available() == 0 {
|
||||||
@@ -746,7 +739,7 @@ fn decodeBase256Segment(
|
|||||||
// We're seeing NegativeArraySizeException errors from users.
|
// We're seeing NegativeArraySizeException errors from users.
|
||||||
// but we shouldn't in rust because it's unsigned
|
// but we shouldn't in rust because it's unsigned
|
||||||
// if count < 0 {
|
// if count < 0 {
|
||||||
// return Err(Exceptions::FormatException(None));
|
// return Err(Exceptions::formatEmpty());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let mut bytes = vec![0u8; count as usize];
|
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
|
// 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
|
// 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 {
|
if bits.available() < 8 {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
*byte = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8;
|
*byte = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8;
|
||||||
codewordPosition += 1;
|
codewordPosition += 1;
|
||||||
@@ -762,7 +755,7 @@ fn decodeBase256Segment(
|
|||||||
result.append_string(
|
result.append_string(
|
||||||
&encoding::all::ISO_8859_1
|
&encoding::all::ISO_8859_1
|
||||||
.decode(&bytes, encoding::DecoderTrap::Strict)
|
.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);
|
byteSegments.push(bytes);
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ impl Version {
|
|||||||
numColumns: u32,
|
numColumns: u32,
|
||||||
) -> Result<&'static Version, Exceptions> {
|
) -> Result<&'static Version, Exceptions> {
|
||||||
if (numRows & 0x01) != 0 || (numColumns & 0x01) != 0 {
|
if (numRows & 0x01) != 0 || (numColumns & 0x01) != 0 {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
for version in VERSIONS.iter() {
|
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) {
|
if let Some(point) = self.correctTopRight(&points) {
|
||||||
points[3] = point;
|
points[3] = point;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(Some(
|
return Err(Exceptions::notFound("point 4 unfound".to_owned()));
|
||||||
"point 4 unfound".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
// points[3] = self.correctTopRight(&points);
|
// points[3] = self.correctTopRight(&points);
|
||||||
// if points[3] == null {
|
// if points[3] == null {
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ fn Scan(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detect(
|
pub fn detect(
|
||||||
@@ -359,6 +359,6 @@ pub fn detect(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// #ifndef __cpp_impl_coroutine
|
// #ifndef __cpp_impl_coroutine
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ impl RegressionLine for DMRegressionLine {
|
|||||||
|
|
||||||
fn add(&mut self, p: &RXingResultPoint) -> Result<(), Exceptions> {
|
fn add(&mut self, p: &RXingResultPoint) -> Result<(), Exceptions> {
|
||||||
if self.direction_inward == RXingResultPoint::default() {
|
if self.direction_inward == RXingResultPoint::default() {
|
||||||
return Err(Exceptions::IllegalStateException(None));
|
return Err(Exceptions::illegalStateEmpty());
|
||||||
}
|
}
|
||||||
self.points.push(*p);
|
self.points.push(*p);
|
||||||
if self.points.len() == 1 {
|
if self.points.len() == 1 {
|
||||||
@@ -241,7 +241,7 @@ impl DMRegressionLine {
|
|||||||
end: &RXingResultPoint,
|
end: &RXingResultPoint,
|
||||||
) -> Result<f64, Exceptions> {
|
) -> Result<f64, Exceptions> {
|
||||||
if self.points.len() <= 3 {
|
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.
|
// re-evaluate and filter out all points too far away. required for the gapSizes calculation.
|
||||||
@@ -267,11 +267,11 @@ impl DMRegressionLine {
|
|||||||
&(*self
|
&(*self
|
||||||
.points
|
.points
|
||||||
.last()
|
.last()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
- *self
|
- *self
|
||||||
.points
|
.points
|
||||||
.first()
|
.first()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
|
||||||
)) as f64;
|
)) as f64;
|
||||||
|
|
||||||
// calculate the width of 2 modules (first black pixel to first black pixel)
|
// calculate the width of 2 modules (first black pixel to first black pixel)
|
||||||
@@ -297,7 +297,7 @@ impl DMRegressionLine {
|
|||||||
&self.project(
|
&self.project(
|
||||||
self.points
|
self.points
|
||||||
.last()
|
.last()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
),
|
),
|
||||||
) as f64,
|
) as f64,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ impl<'a> EdgeTracer<'_> {
|
|||||||
if self.whiteAt(&pEdge) {
|
if self.whiteAt(&pEdge) {
|
||||||
// if we are not making any progress, we still have another endless loop bug
|
// if we are not making any progress, we still have another endless loop bug
|
||||||
if self.p == RXingResultPoint::centered(&pEdge) {
|
if self.p == RXingResultPoint::centered(&pEdge) {
|
||||||
return Err(Exceptions::IllegalStateException(None));
|
return Err(Exceptions::illegalStateEmpty());
|
||||||
}
|
}
|
||||||
self.p = RXingResultPoint::centered(&pEdge);
|
self.p = RXingResultPoint::centered(&pEdge);
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ impl<'a> EdgeTracer<'_> {
|
|||||||
.points()
|
.points()
|
||||||
.first()
|
.first()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
|
||||||
) {
|
) {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
@@ -307,9 +307,9 @@ impl<'a> EdgeTracer<'_> {
|
|||||||
.points()
|
.points()
|
||||||
.last()
|
.last()
|
||||||
.as_ref()
|
.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()
|
if !line.points().is_empty()
|
||||||
&& &&self.p
|
&& &&self.p
|
||||||
@@ -317,7 +317,7 @@ impl<'a> EdgeTracer<'_> {
|
|||||||
.points()
|
.points()
|
||||||
.last()
|
.last()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
{
|
{
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
@@ -363,7 +363,7 @@ impl<'a> EdgeTracer<'_> {
|
|||||||
line.points()
|
line.points()
|
||||||
.last()
|
.last()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
),
|
),
|
||||||
) < 1.0
|
) < 1.0
|
||||||
{
|
{
|
||||||
@@ -380,7 +380,7 @@ impl<'a> EdgeTracer<'_> {
|
|||||||
- line
|
- line
|
||||||
.points()
|
.points()
|
||||||
.last()
|
.last()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
line.add(&self.p)?;
|
line.add(&self.p)?;
|
||||||
@@ -396,7 +396,7 @@ impl<'a> EdgeTracer<'_> {
|
|||||||
+ *line
|
+ *line
|
||||||
.points()
|
.points()
|
||||||
.first()
|
.first()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
|
||||||
) {
|
) {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub fn intersect(
|
|||||||
l2: &DMRegressionLine,
|
l2: &DMRegressionLine,
|
||||||
) -> Result<RXingResultPoint, Exceptions> {
|
) -> Result<RXingResultPoint, Exceptions> {
|
||||||
if !(l1.isValid() && l2.isValid()) {
|
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 d = l1.a * l2.b - l1.b * l2.a;
|
||||||
let x = (l1.c * l2.b - l1.b * l2.c) / d;
|
let x = (l1.c * l2.b - l1.b * l2.c) / d;
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ impl Encoder for ASCIIEncoder {
|
|||||||
.getMessage()
|
.getMessage()
|
||||||
.chars()
|
.chars()
|
||||||
.nth(context.pos as usize)
|
.nth(context.pos as usize)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
context
|
context
|
||||||
.getMessage()
|
.getMessage()
|
||||||
.chars()
|
.chars()
|
||||||
.nth(context.pos as usize + 1)
|
.nth(context.pos as usize + 1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
)? as u8);
|
)? as u8);
|
||||||
context.pos += 2;
|
context.pos += 2;
|
||||||
} else {
|
} else {
|
||||||
@@ -73,9 +73,7 @@ impl Encoder for ASCIIEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Exceptions::IllegalStateException(Some(format!(
|
return Err(Exceptions::illegalState(format!("Illegal mode: {newMode}")));
|
||||||
"Illegal mode: {newMode}"
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if high_level_encoder::isExtendedASCII(c) {
|
} else if high_level_encoder::isExtendedASCII(c) {
|
||||||
@@ -104,9 +102,9 @@ impl ASCIIEncoder {
|
|||||||
let num = (digit1 as u8 - 48) * 10 + (digit2 as u8 - 48);
|
let num = (digit1 as u8 - 48) * 10 + (digit2 as u8 - 48);
|
||||||
Ok((num + 130) as char)
|
Ok((num + 130) as char)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::IllegalArgumentException(Some(format!(
|
Err(Exceptions::illegalArgument(format!(
|
||||||
"not digits: {digit1}{digit2}"
|
"not digits: {digit1}{digit2}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ impl Encoder for Base256Encoder {
|
|||||||
context.updateSymbolInfoWithLength(currentSize);
|
context.updateSymbolInfoWithLength(currentSize);
|
||||||
let mustPad = (context
|
let mustPad = (context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity()
|
.getDataCapacity()
|
||||||
- currentSize as u32)
|
- currentSize as u32)
|
||||||
> 0;
|
> 0;
|
||||||
@@ -62,29 +62,29 @@ impl Encoder for Base256Encoder {
|
|||||||
buffer.replace_range(
|
buffer.replace_range(
|
||||||
0..1,
|
0..1,
|
||||||
&char::from_u32(dataCount as u32)
|
&char::from_u32(dataCount as u32)
|
||||||
.ok_or(Exceptions::ParseException(None))?
|
.ok_or(Exceptions::parseEmpty())?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
} else if dataCount <= 1555 {
|
} else if dataCount <= 1555 {
|
||||||
buffer.replace_range(
|
buffer.replace_range(
|
||||||
0..1,
|
0..1,
|
||||||
&char::from_u32((dataCount as u32 / 250) + 249)
|
&char::from_u32((dataCount as u32 / 250) + 249)
|
||||||
.ok_or(Exceptions::ParseException(None))?
|
.ok_or(Exceptions::parseEmpty())?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
let (ci_pos, _) = buffer
|
let (ci_pos, _) = buffer
|
||||||
.char_indices()
|
.char_indices()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
buffer.insert(
|
buffer.insert(
|
||||||
ci_pos,
|
ci_pos,
|
||||||
char::from_u32(dataCount as u32 % 250)
|
char::from_u32(dataCount as u32 % 250)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalStateException(Some(format!(
|
return Err(Exceptions::illegalState(format!(
|
||||||
"Message length not in valid ranges: {dataCount}"
|
"Message length not in valid ranges: {dataCount}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let c = buffer.chars().count();
|
let c = buffer.chars().count();
|
||||||
@@ -95,10 +95,10 @@ impl Encoder for Base256Encoder {
|
|||||||
buffer
|
buffer
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
context.getCodewordCount() as u32 + 1,
|
context.getCodewordCount() as u32 + 1,
|
||||||
)
|
)
|
||||||
.ok_or(Exceptions::ParseException(None))? as u8,
|
.ok_or(Exceptions::parseEmpty())? as u8,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ impl C40Encoder {
|
|||||||
context.updateSymbolInfoWithLength(curCodewordCount);
|
context.updateSymbolInfoWithLength(curCodewordCount);
|
||||||
let available = context
|
let available = context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity() as usize
|
.getDataCapacity() as usize
|
||||||
- curCodewordCount;
|
- curCodewordCount;
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ impl C40Encoder {
|
|||||||
context.updateSymbolInfoWithLength(curCodewordCount);
|
context.updateSymbolInfoWithLength(curCodewordCount);
|
||||||
let available = context
|
let available = context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity() as usize
|
.getDataCapacity() as usize
|
||||||
- curCodewordCount;
|
- curCodewordCount;
|
||||||
let rest = buffer.chars().count() % 3;
|
let rest = buffer.chars().count() % 3;
|
||||||
@@ -182,9 +182,7 @@ impl C40Encoder {
|
|||||||
context: &mut EncoderContext,
|
context: &mut EncoderContext,
|
||||||
buffer: &mut String,
|
buffer: &mut String,
|
||||||
) -> Result<(), Exceptions> {
|
) -> Result<(), Exceptions> {
|
||||||
context.writeCodewords(
|
context.writeCodewords(&Self::encodeToCodewords(buffer).ok_or(Exceptions::formatEmpty())?);
|
||||||
&Self::encodeToCodewords(buffer).ok_or(Exceptions::FormatException(None))?,
|
|
||||||
);
|
|
||||||
buffer.replace_range(0..3, "");
|
buffer.replace_range(0..3, "");
|
||||||
// buffer.delete(0, 3);
|
// buffer.delete(0, 3);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -207,7 +205,7 @@ impl C40Encoder {
|
|||||||
context.updateSymbolInfoWithLength(curCodewordCount);
|
context.updateSymbolInfoWithLength(curCodewordCount);
|
||||||
let available = context
|
let available = context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity() as usize
|
.getDataCapacity() as usize
|
||||||
- curCodewordCount;
|
- curCodewordCount;
|
||||||
|
|
||||||
@@ -236,9 +234,9 @@ impl C40Encoder {
|
|||||||
context.writeCodeword(C40_UNLATCH);
|
context.writeCodeword(C40_UNLATCH);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalStateException(Some(
|
return Err(Exceptions::illegalState(
|
||||||
"Unexpected case. Please report!".to_owned(),
|
"Unexpected case. Please report!".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
context.signalEncoderChange(ASCII_ENCODATION);
|
context.signalEncoderChange(ASCII_ENCODATION);
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ impl DefaultPlacement {
|
|||||||
.codewords
|
.codewords
|
||||||
.chars()
|
.chars()
|
||||||
.nth(pos)
|
.nth(pos)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as u32;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as u32;
|
||||||
v &= 1 << (8 - bit);
|
v &= 1 << (8 - bit);
|
||||||
self.setBit(col as usize, row as usize, v != 0);
|
self.setBit(col as usize, row as usize, v != 0);
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ impl EdifactEncoder {
|
|||||||
context.updateSymbolInfo();
|
context.updateSymbolInfo();
|
||||||
let mut available = context
|
let mut available = context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity()
|
.getDataCapacity()
|
||||||
- context.getCodewordCount() as u32;
|
- context.getCodewordCount() as u32;
|
||||||
let remaining = context.getRemainingCharacters();
|
let remaining = context.getRemainingCharacters();
|
||||||
@@ -85,7 +85,7 @@ impl EdifactEncoder {
|
|||||||
context.updateSymbolInfoWithLength(context.getCodewordCount() + 1);
|
context.updateSymbolInfoWithLength(context.getCodewordCount() + 1);
|
||||||
available = context
|
available = context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity()
|
.getDataCapacity()
|
||||||
- context.getCodewordCount() as u32;
|
- context.getCodewordCount() as u32;
|
||||||
}
|
}
|
||||||
@@ -95,9 +95,9 @@ impl EdifactEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if count > 4 {
|
if count > 4 {
|
||||||
return Err(Exceptions::IllegalStateException(Some(
|
return Err(Exceptions::illegalState(
|
||||||
"Count must not exceed 4".to_owned(),
|
"Count must not exceed 4".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
let restChars = count - 1;
|
let restChars = count - 1;
|
||||||
let encoded = Self::encodeToCodewords(buffer)?;
|
let encoded = Self::encodeToCodewords(buffer)?;
|
||||||
@@ -108,7 +108,7 @@ impl EdifactEncoder {
|
|||||||
context.updateSymbolInfoWithLength(context.getCodewordCount() + restChars);
|
context.updateSymbolInfoWithLength(context.getCodewordCount() + restChars);
|
||||||
let available = context
|
let available = context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity()
|
.getDataCapacity()
|
||||||
- context.getCodewordCount() as u32;
|
- context.getCodewordCount() as u32;
|
||||||
if available >= 3 {
|
if available >= 3 {
|
||||||
@@ -149,32 +149,32 @@ impl EdifactEncoder {
|
|||||||
fn encodeToCodewords(sb: &str) -> Result<String, Exceptions> {
|
fn encodeToCodewords(sb: &str) -> Result<String, Exceptions> {
|
||||||
let len = sb.chars().count();
|
let len = sb.chars().count();
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
return Err(Exceptions::IllegalStateException(Some(
|
return Err(Exceptions::illegalState(
|
||||||
"StringBuilder must not be empty".to_owned(),
|
"StringBuilder must not be empty".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
let c1 = sb
|
let c1 = sb
|
||||||
.chars()
|
.chars()
|
||||||
.next()
|
.next()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
let c2 = if len >= 2 {
|
let c2 = if len >= 2 {
|
||||||
sb.chars()
|
sb.chars()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
} else {
|
} else {
|
||||||
0 as char
|
0 as char
|
||||||
};
|
};
|
||||||
let c3 = if len >= 3 {
|
let c3 = if len >= 3 {
|
||||||
sb.chars()
|
sb.chars()
|
||||||
.nth(2)
|
.nth(2)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
} else {
|
} else {
|
||||||
0 as char
|
0 as char
|
||||||
};
|
};
|
||||||
let c4 = if len >= 4 {
|
let c4 = if len >= 4 {
|
||||||
sb.chars()
|
sb.chars()
|
||||||
.nth(3)
|
.nth(3)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
} else {
|
} else {
|
||||||
0 as char
|
0 as char
|
||||||
};
|
};
|
||||||
@@ -184,12 +184,12 @@ impl EdifactEncoder {
|
|||||||
let cw2 = (v >> 8) & 255;
|
let cw2 = (v >> 8) & 255;
|
||||||
let cw3 = v & 255;
|
let cw3 = v & 255;
|
||||||
let mut res = String::with_capacity(3);
|
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 {
|
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 {
|
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)
|
Ok(res)
|
||||||
|
|||||||
@@ -63,14 +63,12 @@ impl<'a> EncoderContext<'_> {
|
|||||||
ISO_8859_1_ENCODER
|
ISO_8859_1_ENCODER
|
||||||
.decode(&encoded_bytes, encoding::DecoderTrap::Strict)
|
.decode(&encoded_bytes, encoding::DecoderTrap::Strict)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
Exceptions::ParseException(Some(format!(
|
Exceptions::parse(format!("round trip decode should always work: {e}"))
|
||||||
"round trip decode should always work: {e}"
|
|
||||||
)))
|
|
||||||
})?
|
})?
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Message contains characters outside ISO-8859-1 encoding.".to_owned(),
|
"Message contains characters outside ISO-8859-1 encoding.".to_owned(),
|
||||||
)));
|
));
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
symbol_lookup: Rc::new(SymbolInfoLookup::new()),
|
symbol_lookup: Rc::new(SymbolInfoLookup::new()),
|
||||||
|
|||||||
@@ -154,9 +154,9 @@ const ALOG: [u32; 255] = {
|
|||||||
*/
|
*/
|
||||||
pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String, Exceptions> {
|
pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String, Exceptions> {
|
||||||
if codewords.chars().count() != symbolInfo.getDataCapacity() as usize {
|
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(),
|
"The number of codewords does not match the selected symbol".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
let mut sb = String::with_capacity(
|
let mut sb = String::with_capacity(
|
||||||
(symbolInfo.getDataCapacity() + symbolInfo.getErrorCodewords()) as usize,
|
(symbolInfo.getDataCapacity() + symbolInfo.getErrorCodewords()) as usize,
|
||||||
@@ -185,7 +185,7 @@ pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String,
|
|||||||
codewords
|
codewords
|
||||||
.chars()
|
.chars()
|
||||||
.nth(d)
|
.nth(d)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
);
|
);
|
||||||
|
|
||||||
d += blockCount;
|
d += blockCount;
|
||||||
@@ -198,12 +198,12 @@ pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String,
|
|||||||
let (char_index, replace_char) = sb
|
let (char_index, replace_char) = sb
|
||||||
.char_indices()
|
.char_indices()
|
||||||
.nth(symbolInfo.getDataCapacity() as usize + e)
|
.nth(symbolInfo.getDataCapacity() as usize + e)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
sb.replace_range(
|
sb.replace_range(
|
||||||
char_index..(replace_char.len_utf8()),
|
char_index..(replace_char.len_utf8()),
|
||||||
&ecc.chars()
|
&ecc.chars()
|
||||||
.nth(pos)
|
.nth(pos)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
// sb.setCharAt(symbolInfo.getDataCapacity() + e, ecc.charAt(pos));
|
// sb.setCharAt(symbolInfo.getDataCapacity() + e, ecc.charAt(pos));
|
||||||
@@ -228,9 +228,9 @@ fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if table < 0 {
|
if table < 0 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Illegal number of error correction codewords specified: {numECWords}"
|
"Illegal number of error correction codewords specified: {numECWords}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
let poly = &FACTORS[table as usize];
|
let poly = &FACTORS[table as usize];
|
||||||
let mut ecc = vec![0 as char; numECWords];
|
let mut ecc = vec![0 as char; numECWords];
|
||||||
@@ -244,21 +244,21 @@ fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptio
|
|||||||
^ codewords
|
^ codewords
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as usize;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as usize;
|
||||||
for k in (1..numECWords).rev() {
|
for k in (1..numECWords).rev() {
|
||||||
// for (int k = numECWords - 1; k > 0; k--) {
|
// for (int k = numECWords - 1; k > 0; k--) {
|
||||||
if m != 0 && poly[k] != 0 {
|
if m != 0 && poly[k] != 0 {
|
||||||
ecc[k] = char::from_u32(
|
ecc[k] = char::from_u32(
|
||||||
ecc[k - 1] as u32 ^ ALOG[(LOG[m] + LOG[poly[k] as usize]) as usize % 255],
|
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 {
|
} else {
|
||||||
ecc[k] = ecc[k - 1];
|
ecc[k] = ecc[k - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if m != 0 && poly[0] != 0 {
|
if m != 0 && poly[0] != 0 {
|
||||||
ecc[0] = char::from_u32(ALOG[(LOG[m] + LOG[poly[0] as usize]) as usize % 255])
|
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 {
|
} else {
|
||||||
ecc[0] = 0 as char;
|
ecc[0] = 0 as char;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
|
|||||||
c40Encoder.encodeMaximalC40(&mut context)?;
|
c40Encoder.encodeMaximalC40(&mut context)?;
|
||||||
encodingMode = context
|
encodingMode = context
|
||||||
.getNewEncoding()
|
.getNewEncoding()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?;
|
.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
context.resetEncoderSignal();
|
context.resetEncoderSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
|
|||||||
if context.getNewEncoding().is_some() {
|
if context.getNewEncoding().is_some() {
|
||||||
encodingMode = context
|
encodingMode = context
|
||||||
.getNewEncoding()
|
.getNewEncoding()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?;
|
.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
context.resetEncoderSignal();
|
context.resetEncoderSignal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
|
|||||||
context.updateSymbolInfo();
|
context.updateSymbolInfo();
|
||||||
let capacity = context
|
let capacity = context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity();
|
.getDataCapacity();
|
||||||
if len < capacity as usize
|
if len < capacity as usize
|
||||||
&& encodingMode != ASCII_ENCODATION
|
&& encodingMode != ASCII_ENCODATION
|
||||||
@@ -611,7 +611,7 @@ pub fn determineConsecutiveDigitCount(msg: &str, startpos: u32) -> u32 {
|
|||||||
pub fn illegalCharacter(c: char) -> Result<(), Exceptions> {
|
pub fn illegalCharacter(c: char) -> Result<(), Exceptions> {
|
||||||
// let hex = Integer.toHexString(c);
|
// let hex = Integer.toHexString(c);
|
||||||
// hex = "0000".substring(0, 4 - hex.length()) + hex;
|
// hex = "0000".substring(0, 4 - hex.length()) + hex;
|
||||||
Err(Exceptions::IllegalArgumentException(Some(format!(
|
Err(Exceptions::illegalArgument(format!(
|
||||||
"Illegal character: {c} (0x{c})"
|
"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()
|
if edges[vertexIndex][edge.getEndMode()?.ordinal()].is_none()
|
||||||
|| edges[vertexIndex][edge.getEndMode()?.ordinal()]
|
|| edges[vertexIndex][edge.getEndMode()?.ordinal()]
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.cachedTotalSize
|
.cachedTotalSize
|
||||||
> edge.cachedTotalSize
|
> edge.cachedTotalSize
|
||||||
{
|
{
|
||||||
@@ -635,9 +635,9 @@ fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult, Exceptions> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if minimalJ < 0 {
|
if minimalJ < 0 {
|
||||||
return Err(Exceptions::IllegalStateException(Some(format!(
|
return Err(Exceptions::illegalState(format!(
|
||||||
"Internal error: failed to encode \"{input}\""
|
"Internal error: failed to encode \"{input}\""
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
RXingResult::new(edges[inputLength][minimalJ as usize].clone())
|
RXingResult::new(edges[inputLength][minimalJ as usize].clone())
|
||||||
}
|
}
|
||||||
@@ -669,7 +669,7 @@ impl Edge {
|
|||||||
previous: Option<Rc<Edge>>,
|
previous: Option<Rc<Edge>>,
|
||||||
) -> Result<Self, Exceptions> {
|
) -> Result<Self, Exceptions> {
|
||||||
if fromPosition + characterLength > input.length() as u32 {
|
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() {
|
let mut size = if let Some(previous) = previous.clone() {
|
||||||
@@ -1276,7 +1276,7 @@ impl RXingResult {
|
|||||||
let solution = if let Some(edge) = solution {
|
let solution = if let Some(edge) = solution {
|
||||||
edge
|
edge
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalArgumentException(None));
|
return Err(Exceptions::illegalArgumentEmpty());
|
||||||
};
|
};
|
||||||
let input = solution.input.clone();
|
let input = solution.input.clone();
|
||||||
let mut size = 0;
|
let mut size = 0;
|
||||||
|
|||||||
@@ -128,9 +128,9 @@ impl SymbolInfo {
|
|||||||
2 | 4 => Ok(2),
|
2 | 4 => Ok(2),
|
||||||
16 => Ok(4),
|
16 => Ok(4),
|
||||||
36 => Ok(6),
|
36 => Ok(6),
|
||||||
_ => Err(Exceptions::IllegalStateException(Some(
|
_ => Err(Exceptions::illegalState(
|
||||||
"Cannot handle this number of data regions".to_owned(),
|
"Cannot handle this number of data regions".to_owned(),
|
||||||
))),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,9 +140,9 @@ impl SymbolInfo {
|
|||||||
4 => Ok(2),
|
4 => Ok(2),
|
||||||
16 => Ok(4),
|
16 => Ok(4),
|
||||||
36 => Ok(6),
|
36 => Ok(6),
|
||||||
_ => Err(Exceptions::IllegalStateException(Some(
|
_ => Err(Exceptions::illegalState(
|
||||||
"Cannot handle this number of data regions".to_owned(),
|
"Cannot handle this number of data regions".to_owned(),
|
||||||
))),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,9 +310,9 @@ impl<'a> SymbolInfoLookup<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fail {
|
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}"
|
"Can't find a symbol arrangement that matches the message. Data codewords: {dataCodewords}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ impl X12Encoder {
|
|||||||
context.updateSymbolInfo();
|
context.updateSymbolInfo();
|
||||||
let available = context
|
let available = context
|
||||||
.getSymbolInfo()
|
.getSymbolInfo()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getDataCapacity()
|
.getDataCapacity()
|
||||||
- context.getCodewordCount() as u32;
|
- context.getCodewordCount() as u32;
|
||||||
let count = buffer.chars().count();
|
let count = buffer.chars().count();
|
||||||
|
|||||||
@@ -35,20 +35,20 @@ pub fn detect_in_svg_with_hints(
|
|||||||
|
|
||||||
let path = PathBuf::from(file_name);
|
let path = PathBuf::from(file_name);
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"file does not exist".to_owned(),
|
"file does not exist".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let Ok(mut file) = File::open(path) else {
|
let Ok(mut file) = File::open(path) else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some("file cannot be opened".to_owned())));
|
return Err(Exceptions::illegalArgument("file cannot be opened".to_owned()));
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut svg_data = Vec::new();
|
let mut svg_data = Vec::new();
|
||||||
if file.read_to_end(&mut svg_data).is_err() {
|
if file.read_to_end(&mut svg_data).is_err() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"file cannot be read".to_owned(),
|
"file cannot be read".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut multi_format_reader = MultiFormatReader::default();
|
let mut multi_format_reader = MultiFormatReader::default();
|
||||||
@@ -88,20 +88,20 @@ pub fn detect_multiple_in_svg_with_hints(
|
|||||||
|
|
||||||
let path = PathBuf::from(file_name);
|
let path = PathBuf::from(file_name);
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"file does not exist".to_owned(),
|
"file does not exist".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let Ok(mut file) = File::open(path) else {
|
let Ok(mut file) = File::open(path) else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some("file cannot be opened".to_owned())));
|
return Err(Exceptions::illegalArgument("file cannot be opened".to_owned()));
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut svg_data = Vec::new();
|
let mut svg_data = Vec::new();
|
||||||
if file.read_to_end(&mut svg_data).is_err() {
|
if file.read_to_end(&mut svg_data).is_err() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"file cannot be read".to_owned(),
|
"file cannot be read".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let multi_format_reader = MultiFormatReader::default();
|
let multi_format_reader = MultiFormatReader::default();
|
||||||
@@ -134,7 +134,7 @@ pub fn detect_in_file_with_hints(
|
|||||||
hints: &mut DecodingHintDictionary,
|
hints: &mut DecodingHintDictionary,
|
||||||
) -> Result<RXingResult, Exceptions> {
|
) -> Result<RXingResult, Exceptions> {
|
||||||
let Ok(img) = image::open(file_name) else {
|
let Ok(img) = image::open(file_name) else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!("file '{file_name}' not found or cannot be opened"))));
|
return Err(Exceptions::illegalArgument(format!("file '{file_name}' not found or cannot be opened")));
|
||||||
};
|
};
|
||||||
let mut multi_format_reader = MultiFormatReader::default();
|
let mut multi_format_reader = MultiFormatReader::default();
|
||||||
|
|
||||||
@@ -167,9 +167,8 @@ pub fn detect_multiple_in_file_with_hints(
|
|||||||
file_name: &str,
|
file_name: &str,
|
||||||
hints: &mut DecodingHintDictionary,
|
hints: &mut DecodingHintDictionary,
|
||||||
) -> Result<Vec<RXingResult>, Exceptions> {
|
) -> Result<Vec<RXingResult>, Exceptions> {
|
||||||
let img = image::open(file_name).map_err(|e| {
|
let img = image::open(file_name)
|
||||||
Exceptions::RuntimeException(Some(format!("couldn't read {file_name}: {e}")))
|
.map_err(|e| Exceptions::runtime(format!("couldn't read {file_name}: {e}")))?;
|
||||||
})?;
|
|
||||||
let multi_format_reader = MultiFormatReader::default();
|
let multi_format_reader = MultiFormatReader::default();
|
||||||
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
|
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
|
||||||
|
|
||||||
@@ -256,9 +255,9 @@ pub fn save_image(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Excepti
|
|||||||
let image: image::DynamicImage = bit_matrix.into();
|
let image: image::DynamicImage = bit_matrix.into();
|
||||||
match image.save(file_name) {
|
match image.save(file_name) {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(Exceptions::IllegalArgumentException(Some(format!(
|
Err(err) => Err(Exceptions::illegalArgument(format!(
|
||||||
"could not save file '{file_name}': {err}"
|
"could not save file '{file_name}': {err}"
|
||||||
)))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,10 +267,10 @@ pub fn save_svg(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exception
|
|||||||
|
|
||||||
match svg::save(file_name, &svg) {
|
match svg::save(file_name, &svg) {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(Exceptions::IllegalArgumentException(Some(format!(
|
Err(err) => Err(Exceptions::illegalArgument(format!(
|
||||||
"could not save file '{}': {}",
|
"could not save file '{}': {}",
|
||||||
file_name, err
|
file_name, err
|
||||||
)))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,8 +302,8 @@ pub fn save_file(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exceptio
|
|||||||
Ok(())
|
Ok(())
|
||||||
}() {
|
}() {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err(Exceptions::IllegalArgumentException(Some(format!(
|
Err(_) => Err(Exceptions::illegalArgument(format!(
|
||||||
"could not write to '{file_name}'"
|
"could not write to '{file_name}'"
|
||||||
)))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ impl LuminanceSource for Luma8LuminanceSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn rotateCounterClockwise45(&self) -> Result<Box<dyn LuminanceSource>, crate::Exceptions> {
|
fn rotateCounterClockwise45(&self) -> Result<Box<dyn LuminanceSource>, crate::Exceptions> {
|
||||||
Err(crate::Exceptions::UnsupportedOperationException(Some(
|
Err(crate::Exceptions::unsupportedOperation(
|
||||||
"This luminance source does not support rotation by 45 degrees.".to_owned(),
|
"This luminance source does not support rotation by 45 degrees.".to_owned(),
|
||||||
)))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,9 +91,9 @@ pub trait LuminanceSource {
|
|||||||
_width: usize,
|
_width: usize,
|
||||||
_height: usize,
|
_height: usize,
|
||||||
) -> Result<Box<dyn LuminanceSource>, Exceptions> {
|
) -> Result<Box<dyn LuminanceSource>, Exceptions> {
|
||||||
Err(Exceptions::UnsupportedOperationException(Some(
|
Err(Exceptions::unsupportedOperation(
|
||||||
"This luminance source does not support cropping.".to_owned(),
|
"This luminance source does not support cropping.".to_owned(),
|
||||||
)))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,9 +118,9 @@ pub trait LuminanceSource {
|
|||||||
* @return A rotated version of this object.
|
* @return A rotated version of this object.
|
||||||
*/
|
*/
|
||||||
fn rotateCounterClockwise(&self) -> Result<Box<dyn LuminanceSource>, Exceptions> {
|
fn rotateCounterClockwise(&self) -> Result<Box<dyn LuminanceSource>, Exceptions> {
|
||||||
Err(Exceptions::UnsupportedOperationException(Some(
|
Err(Exceptions::unsupportedOperation(
|
||||||
"This luminance source does not support rotation by 90 degrees.".to_owned(),
|
"This luminance source does not support rotation by 90 degrees.".to_owned(),
|
||||||
)))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,9 +130,9 @@ pub trait LuminanceSource {
|
|||||||
* @return A rotated version of this object.
|
* @return A rotated version of this object.
|
||||||
*/
|
*/
|
||||||
fn rotateCounterClockwise45(&self) -> Result<Box<dyn LuminanceSource>, Exceptions> {
|
fn rotateCounterClockwise45(&self) -> Result<Box<dyn LuminanceSource>, Exceptions> {
|
||||||
Err(Exceptions::UnsupportedOperationException(Some(
|
Err(Exceptions::unsupportedOperation(
|
||||||
"This luminance source does not support rotation by 45 degrees.".to_owned(),
|
"This luminance source does not support rotation by 45 degrees.".to_owned(),
|
||||||
)))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions>
|
|||||||
let pc = getPostCode2(bytes);
|
let pc = getPostCode2(bytes);
|
||||||
let ps2Length = getPostCode2Length(bytes) as usize;
|
let ps2Length = getPostCode2Length(bytes) as usize;
|
||||||
if ps2Length > 10 {
|
if ps2Length > 10 {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
// NumberFormat df = new DecimalFormat("0000000000".substring(0, ps2Length));
|
// NumberFormat df = new DecimalFormat("0000000000".substring(0, ps2Length));
|
||||||
// postcode = df.format(pc);
|
// postcode = df.format(pc);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ pub fn decode_with_hints(
|
|||||||
correctErrors(&mut codewords, 20, 68, 56, ODD)?;
|
correctErrors(&mut codewords, 20, 68, 56, ODD)?;
|
||||||
datawords = vec![0u8; 78];
|
datawords = vec![0u8; 78];
|
||||||
}
|
}
|
||||||
_ => return Err(Exceptions::NotFoundException(None)),
|
_ => return Err(Exceptions::notFoundEmpty()),
|
||||||
}
|
}
|
||||||
|
|
||||||
datawords[0..10].clone_from_slice(&codewords[0..10]);
|
datawords[0..10].clone_from_slice(&codewords[0..10]);
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ impl Circle<'_> {
|
|||||||
pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionResult, Exceptions> {
|
pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionResult, Exceptions> {
|
||||||
// find concentric circles
|
// find concentric circles
|
||||||
let Some( mut circles) = find_concentric_circles(image) else {
|
let Some( mut circles) = find_concentric_circles(image) else {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
};
|
};
|
||||||
|
|
||||||
// we should have an idea where the center is at this point,
|
// we should have an idea where the center is at this point,
|
||||||
@@ -341,7 +341,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
|||||||
if try_harder {
|
if try_harder {
|
||||||
continue;
|
continue;
|
||||||
}else {
|
}else {
|
||||||
return Err(Exceptions::NotFoundException(None))
|
return Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let grid_sampler = DefaultGridSampler::default();
|
let grid_sampler = DefaultGridSampler::default();
|
||||||
@@ -378,7 +378,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
|||||||
if try_harder {
|
if try_harder {
|
||||||
continue;
|
continue;
|
||||||
}else {
|
}else {
|
||||||
return Err(Exceptions::NotFoundException(None))
|
return Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Ok(MaxicodeDetectionResult {
|
return Ok(MaxicodeDetectionResult {
|
||||||
@@ -392,7 +392,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locate concentric circles.
|
/// Locate concentric circles.
|
||||||
@@ -734,7 +734,7 @@ fn box_symbol(
|
|||||||
#[cfg(feature = "experimental_features")]
|
#[cfg(feature = "experimental_features")]
|
||||||
if is_ellipse {
|
if is_ellipse {
|
||||||
// we don't deal with ellipses yet
|
// we don't deal with ellipses yet
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut final_rotation = 0.0;
|
let mut final_rotation = 0.0;
|
||||||
@@ -1054,7 +1054,7 @@ fn compare_circle(a: &Circle, b: &Circle) -> std::cmp::Ordering {
|
|||||||
pub fn read_bits(image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
pub fn read_bits(image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
||||||
let enclosingRectangle = image
|
let enclosingRectangle = image
|
||||||
.getEnclosingRectangle()
|
.getEnclosingRectangle()
|
||||||
.ok_or(Exceptions::NotFoundException(None))?;
|
.ok_or(Exceptions::notFoundEmpty())?;
|
||||||
|
|
||||||
let left = enclosingRectangle[0];
|
let left = enclosingRectangle[0];
|
||||||
let top = enclosingRectangle[1];
|
let top = enclosingRectangle[1];
|
||||||
|
|||||||
@@ -126,11 +126,10 @@ impl MaxiCodeReader {
|
|||||||
fn extractPureBits(image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
fn extractPureBits(image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
|
||||||
let enclosingRectangleOption = image.getEnclosingRectangle();
|
let enclosingRectangleOption = image.getEnclosingRectangle();
|
||||||
if enclosingRectangleOption.is_none() {
|
if enclosingRectangleOption.is_none() {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let enclosingRectangle =
|
let enclosingRectangle = enclosingRectangleOption.ok_or(Exceptions::notFoundEmpty())?;
|
||||||
enclosingRectangleOption.ok_or(Exceptions::NotFoundException(None))?;
|
|
||||||
|
|
||||||
let left = enclosingRectangle[0];
|
let left = enclosingRectangle[0];
|
||||||
let top = enclosingRectangle[1];
|
let top = enclosingRectangle[1];
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ impl<T: Reader> MultipleBarcodeReader for GenericMultipleBarcodeReader<T> {
|
|||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
self.doDecodeMultiple(image, hints, &mut results, 0, 0, 0);
|
self.doDecodeMultiple(image, hints, &mut results, 0, 0, 0);
|
||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
Ok(results)
|
Ok(results)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ impl<'a> MultiDetector<'_> {
|
|||||||
let infos = finder.findMulti(hints)?;
|
let infos = finder.findMulti(hints)?;
|
||||||
|
|
||||||
if infos.is_empty() {
|
if infos.is_empty() {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
|||||||
@@ -93,9 +93,9 @@ impl<'a> MultiFinderPatternFinder<'_> {
|
|||||||
|
|
||||||
if size < 3 {
|
if size < 3 {
|
||||||
// Couldn't find enough finder patterns
|
// Couldn't find enough finder patterns
|
||||||
return Err(Exceptions::NotFoundException(Some(
|
return Err(Exceptions::notFound(
|
||||||
"Couldn't find enough finder patterns".to_owned(),
|
"Couldn't find enough finder patterns".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -212,7 +212,7 @@ impl<'a> MultiFinderPatternFinder<'_> {
|
|||||||
if !results.is_empty() {
|
if !results.is_empty() {
|
||||||
Ok(results)
|
Ok(results)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ impl MultipleBarcodeReader for QRCodeMultiReader {
|
|||||||
// ignore and continue
|
// ignore and continue
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
return Err(output.err().unwrap_or(Exceptions::NotFoundException(None)));
|
return Err(output.err().unwrap_or(Exceptions::notFoundEmpty()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -192,6 +192,6 @@ impl MultiFormatReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ impl Writer for MultiFormatWriter {
|
|||||||
BarcodeFormat::DATA_MATRIX => Box::<DataMatrixWriter>::default(),
|
BarcodeFormat::DATA_MATRIX => Box::<DataMatrixWriter>::default(),
|
||||||
BarcodeFormat::AZTEC => Box::<AztecWriter>::default(),
|
BarcodeFormat::AZTEC => Box::<AztecWriter>::default(),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"No encoder available for format {format:?}"
|
"No encoder available for format {format:?}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -65,13 +65,13 @@ impl OneDReader for CodaBarReader {
|
|||||||
loop {
|
loop {
|
||||||
let charOffset = self.toNarrowWidePattern(nextStart);
|
let charOffset = self.toNarrowWidePattern(nextStart);
|
||||||
if charOffset == -1 {
|
if charOffset == -1 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
// Hack: We store the position in the alphabet table into a
|
// Hack: We store the position in the alphabet table into a
|
||||||
// StringBuilder, so that we can access the decoded patterns in
|
// StringBuilder, so that we can access the decoded patterns in
|
||||||
// validatePattern. We'll translate to the actual characters later.
|
// validatePattern. We'll translate to the actual characters later.
|
||||||
self.decodeRowRXingResult
|
self.decodeRowRXingResult
|
||||||
.push(char::from_u32(charOffset as u32).ok_or(Exceptions::ParseException(None))?);
|
.push(char::from_u32(charOffset as u32).ok_or(Exceptions::parseEmpty())?);
|
||||||
nextStart += 8;
|
nextStart += 8;
|
||||||
// Stop as soon as we see the end character.
|
// Stop as soon as we see the end character.
|
||||||
if self.decodeRowRXingResult.chars().count() > 1
|
if self.decodeRowRXingResult.chars().count() > 1
|
||||||
@@ -99,7 +99,7 @@ impl OneDReader for CodaBarReader {
|
|||||||
// otherwise this is probably a false positive. The exception is if we are
|
// otherwise this is probably a false positive. The exception is if we are
|
||||||
// at the end of the row. (I.e. the barcode barely fits.)
|
// at the end of the row. (I.e. the barcode barely fits.)
|
||||||
if nextStart < self.counterLength && trailingWhitespace < lastPatternSize / 2 {
|
if nextStart < self.counterLength && trailingWhitespace < lastPatternSize / 2 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.validatePattern(startOffset)?;
|
self.validatePattern(startOffset)?;
|
||||||
@@ -113,7 +113,7 @@ impl OneDReader for CodaBarReader {
|
|||||||
.decodeRowRXingResult
|
.decodeRowRXingResult
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
as usize]
|
as usize]
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
@@ -123,23 +123,23 @@ impl OneDReader for CodaBarReader {
|
|||||||
.decodeRowRXingResult
|
.decodeRowRXingResult
|
||||||
.chars()
|
.chars()
|
||||||
.next()
|
.next()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
if !Self::arrayContains(&Self::STARTEND_ENCODING, startchar) {
|
if !Self::arrayContains(&Self::STARTEND_ENCODING, startchar) {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
let endchar = self
|
let endchar = self
|
||||||
.decodeRowRXingResult
|
.decodeRowRXingResult
|
||||||
.chars()
|
.chars()
|
||||||
.nth(self.decodeRowRXingResult.chars().count() - 1)
|
.nth(self.decodeRowRXingResult.chars().count() - 1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
if !Self::arrayContains(&Self::STARTEND_ENCODING, endchar) {
|
if !Self::arrayContains(&Self::STARTEND_ENCODING, endchar) {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove stop/start characters character and check if a long enough string is contained
|
// remove stop/start characters character and check if a long enough string is contained
|
||||||
if (self.decodeRowRXingResult.chars().count()) <= Self::MIN_CHARACTER_LENGTH as usize {
|
if (self.decodeRowRXingResult.chars().count()) <= Self::MIN_CHARACTER_LENGTH as usize {
|
||||||
// Almost surely a false positive ( start + stop + at least 1 character)
|
// Almost surely a false positive ( start + stop + at least 1 character)
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !matches!(
|
if !matches!(
|
||||||
@@ -243,7 +243,7 @@ impl CodaBarReader {
|
|||||||
.decodeRowRXingResult
|
.decodeRowRXingResult
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
as usize];
|
as usize];
|
||||||
for j in (0_usize..=6).rev() {
|
for j in (0_usize..=6).rev() {
|
||||||
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
|
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
|
||||||
@@ -282,7 +282,7 @@ impl CodaBarReader {
|
|||||||
.decodeRowRXingResult
|
.decodeRowRXingResult
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
as usize];
|
as usize];
|
||||||
for j in (0usize..=6).rev() {
|
for j in (0usize..=6).rev() {
|
||||||
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
|
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
|
||||||
@@ -290,7 +290,7 @@ impl CodaBarReader {
|
|||||||
let category = (j & 1) + ((pattern as usize) & 1) * 2;
|
let category = (j & 1) + ((pattern as usize) & 1) * 2;
|
||||||
let size = self.counters[(pos + j)];
|
let size = self.counters[(pos + j)];
|
||||||
if (size as f32) < mins[category] || (size as f32) > maxes[category] {
|
if (size as f32) < mins[category] || (size as f32) > maxes[category] {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
pattern >>= 1;
|
pattern >>= 1;
|
||||||
}
|
}
|
||||||
@@ -311,7 +311,7 @@ impl CodaBarReader {
|
|||||||
let mut i = row.getNextUnset(0);
|
let mut i = row.getNextUnset(0);
|
||||||
let end = row.getSize();
|
let end = row.getSize();
|
||||||
if i >= end {
|
if i >= end {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
let mut isWhite = true;
|
let mut isWhite = true;
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
@@ -363,7 +363,7 @@ impl CodaBarReader {
|
|||||||
|
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn arrayContains(array: &[char], key: char) -> bool {
|
pub fn arrayContains(array: &[char], key: char) -> bool {
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
|||||||
let firstChar = contents
|
let firstChar = contents
|
||||||
.chars()
|
.chars()
|
||||||
.next()
|
.next()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_ascii_uppercase();
|
.to_ascii_uppercase();
|
||||||
let lastChar = contents
|
let lastChar = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(contents.chars().count() - 1)
|
.nth(contents.chars().count() - 1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_ascii_uppercase();
|
.to_ascii_uppercase();
|
||||||
let startsNormal = CodaBarReader::arrayContains(&START_END_CHARS, firstChar);
|
let startsNormal = CodaBarReader::arrayContains(&START_END_CHARS, firstChar);
|
||||||
let endsNormal = CodaBarReader::arrayContains(&START_END_CHARS, lastChar);
|
let endsNormal = CodaBarReader::arrayContains(&START_END_CHARS, lastChar);
|
||||||
@@ -56,26 +56,26 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
|||||||
let endsAlt = CodaBarReader::arrayContains(&ALT_START_END_CHARS, lastChar);
|
let endsAlt = CodaBarReader::arrayContains(&ALT_START_END_CHARS, lastChar);
|
||||||
if startsNormal {
|
if startsNormal {
|
||||||
if !endsNormal {
|
if !endsNormal {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Invalid start/end guards: {contents}"
|
"Invalid start/end guards: {contents}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
// else already has valid start/end
|
// else already has valid start/end
|
||||||
contents.to_owned()
|
contents.to_owned()
|
||||||
} else if startsAlt {
|
} else if startsAlt {
|
||||||
if !endsAlt {
|
if !endsAlt {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Invalid start/end guards: {contents}"
|
"Invalid start/end guards: {contents}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
// else already has valid start/end
|
// else already has valid start/end
|
||||||
contents.to_owned()
|
contents.to_owned()
|
||||||
} else {
|
} else {
|
||||||
// Doesn't start with a guard
|
// Doesn't start with a guard
|
||||||
if endsNormal || endsAlt {
|
if endsNormal || endsAlt {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Invalid start/end guards: {contents}"
|
"Invalid start/end guards: {contents}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
// else doesn't end with guard either, so add a default
|
// else doesn't end with guard either, so add a default
|
||||||
format!("{DEFAULT_GUARD}{contents}{DEFAULT_GUARD}")
|
format!("{DEFAULT_GUARD}{contents}{DEFAULT_GUARD}")
|
||||||
@@ -93,9 +93,9 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
|||||||
) {
|
) {
|
||||||
resultLength += 10;
|
resultLength += 10;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Cannot encode : '{ch}'"
|
"Cannot encode : '{ch}'"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// A blank is placed between each character.
|
// A blank is placed between each character.
|
||||||
@@ -108,7 +108,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
|
|||||||
let mut c = contents
|
let mut c = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(index)
|
.nth(index)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_ascii_uppercase();
|
.to_ascii_uppercase();
|
||||||
if index == 0 || index == contents.chars().count() - 1 {
|
if index == 0 || index == contents.chars().count() - 1 {
|
||||||
// The start/end chars are not in the CodaBarReader.ALPHABET.
|
// The start/end chars are not in the CodaBarReader.ALPHABET.
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ impl OneDReader for Code128Reader {
|
|||||||
CODE_START_A => CODE_CODE_A,
|
CODE_START_A => CODE_CODE_A,
|
||||||
CODE_START_B => CODE_CODE_B,
|
CODE_START_B => CODE_CODE_B,
|
||||||
CODE_START_C => CODE_CODE_C,
|
CODE_START_C => CODE_CODE_C,
|
||||||
_ => return Err(Exceptions::FormatException(None)),
|
_ => return Err(Exceptions::formatEmpty()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut done = false;
|
let mut done = false;
|
||||||
@@ -100,9 +100,7 @@ impl OneDReader for Code128Reader {
|
|||||||
|
|
||||||
// Take care of illegal start codes
|
// Take care of illegal start codes
|
||||||
match code {
|
match code {
|
||||||
CODE_START_A | CODE_START_B | CODE_START_C => {
|
CODE_START_A | CODE_START_B | CODE_START_C => return Err(Exceptions::formatEmpty()),
|
||||||
return Err(Exceptions::FormatException(None))
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,21 +294,21 @@ impl OneDReader for Code128Reader {
|
|||||||
row.getSize().min(nextStart + (nextStart - lastStart) / 2),
|
row.getSize().min(nextStart + (nextStart - lastStart) / 2),
|
||||||
false,
|
false,
|
||||||
)? {
|
)? {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pull out from sum the value of the penultimate check code
|
// Pull out from sum the value of the penultimate check code
|
||||||
checksumTotal -= multiplier as usize * lastCode as usize;
|
checksumTotal -= multiplier as usize * lastCode as usize;
|
||||||
// lastCode is the checksum then:
|
// lastCode is the checksum then:
|
||||||
if (checksumTotal % 103) as u8 != lastCode {
|
if (checksumTotal % 103) as u8 != lastCode {
|
||||||
return Err(Exceptions::ChecksumException(None));
|
return Err(Exceptions::checksumEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to pull out the check digits from string
|
// Need to pull out the check digits from string
|
||||||
let resultLength = result.chars().count();
|
let resultLength = result.chars().count();
|
||||||
if resultLength == 0 {
|
if resultLength == 0 {
|
||||||
// false positive
|
// false positive
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only bother if the result had at least one character, and if the checksum digit happened to
|
// Only bother if the result had at least one character, and if the checksum digit happened to
|
||||||
@@ -331,9 +329,7 @@ impl OneDReader for Code128Reader {
|
|||||||
let rawCodesSize = rawCodes.len();
|
let rawCodesSize = rawCodes.len();
|
||||||
let mut rawBytes = vec![0u8; rawCodesSize];
|
let mut rawBytes = vec![0u8; rawCodesSize];
|
||||||
for (i, rawByte) in rawBytes.iter_mut().enumerate().take(rawCodesSize) {
|
for (i, rawByte) in rawBytes.iter_mut().enumerate().take(rawCodesSize) {
|
||||||
*rawByte = *rawCodes
|
*rawByte = *rawCodes.get(i).ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
.get(i)
|
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
|
||||||
}
|
}
|
||||||
let mut resultObject = RXingResult::new(
|
let mut resultObject = RXingResult::new(
|
||||||
&result,
|
&result,
|
||||||
@@ -407,7 +403,7 @@ impl Code128Reader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decodeCode(
|
fn decodeCode(
|
||||||
@@ -432,7 +428,7 @@ impl Code128Reader {
|
|||||||
if bestMatch >= 0 {
|
if bestMatch >= 0 {
|
||||||
Ok(bestMatch as u8)
|
Ok(bestMatch as u8)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,23 +99,23 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
|
|||||||
let length = contents.chars().count();
|
let length = contents.chars().count();
|
||||||
// Check length
|
// Check length
|
||||||
if !(1..=80).contains(&length) {
|
if !(1..=80).contains(&length) {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Contents length should be between 1 and 80 characters, but got {length}"
|
"Contents length should be between 1 and 80 characters, but got {length}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for forced code set hint.
|
// Check for forced code set hint.
|
||||||
let mut forcedCodeSet = -1_i32;
|
let mut forcedCodeSet = -1_i32;
|
||||||
if hints.contains_key(&EncodeHintType::FORCE_CODE_SET) {
|
if hints.contains_key(&EncodeHintType::FORCE_CODE_SET) {
|
||||||
let Some(EncodeHintValue::ForceCodeSet(codeSetHint)) = hints.get(&EncodeHintType::FORCE_CODE_SET) else { return Err(Exceptions::IllegalStateException(None)) };
|
let Some(EncodeHintValue::ForceCodeSet(codeSetHint)) = hints.get(&EncodeHintType::FORCE_CODE_SET) else { return Err(Exceptions::illegalStateEmpty()) };
|
||||||
match codeSetHint.as_str() {
|
match codeSetHint.as_str() {
|
||||||
"A" => forcedCodeSet = CODE_CODE_A as i32,
|
"A" => forcedCodeSet = CODE_CODE_A as i32,
|
||||||
"B" => forcedCodeSet = CODE_CODE_B as i32,
|
"B" => forcedCodeSet = CODE_CODE_B as i32,
|
||||||
"C" => forcedCodeSet = CODE_CODE_C as i32,
|
"C" => forcedCodeSet = CODE_CODE_C as i32,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Unsupported code set hint: {codeSetHint}"
|
"Unsupported code set hint: {codeSetHint}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,9 +134,9 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
|
|||||||
if c > 127 {
|
if c > 127 {
|
||||||
// no full Latin-1 character set available at the moment
|
// no full Latin-1 character set available at the moment
|
||||||
// shift and manual code change are not supported
|
// shift and manual code change are not supported
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Bad character in input: ASCII value={c}"
|
"Bad character in input: ASCII value={c}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,18 +149,18 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
|
|||||||
// allows no ascii above 95 (no lower caps, no special symbols)
|
// allows no ascii above 95 (no lower caps, no special symbols)
|
||||||
{
|
{
|
||||||
if c > 95 && c <= 127 {
|
if c > 95 && c <= 127 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Bad character in input for forced code set A: ASCII value={c}"
|
"Bad character in input for forced code set A: ASCII value={c}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CODE_CODE_B_I32 =>
|
CODE_CODE_B_I32 =>
|
||||||
// allows no ascii below 32 (terminal symbols)
|
// allows no ascii below 32 (terminal symbols)
|
||||||
{
|
{
|
||||||
if c <= 32 {
|
if c <= 32 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Bad character in input for forced code set B: ASCII value={c}"
|
"Bad character in input for forced code set B: ASCII value={c}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CODE_CODE_C_I32 =>
|
CODE_CODE_C_I32 =>
|
||||||
@@ -172,9 +172,9 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
|
|||||||
|| ch == ESCAPE_FNC_3
|
|| ch == ESCAPE_FNC_3
|
||||||
|| ch == ESCAPE_FNC_4
|
|| ch == ESCAPE_FNC_4
|
||||||
{
|
{
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Bad character in input for forced code set C: ASCII value={c}"
|
"Bad character in input for forced code set C: ASCII value={c}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -195,8 +195,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>, Exception
|
|||||||
while position < length {
|
while position < length {
|
||||||
//Select code to use
|
//Select code to use
|
||||||
let newCodeSet = if forcedCodeSet == -1 {
|
let newCodeSet = if forcedCodeSet == -1 {
|
||||||
chooseCode(contents, position, codeSet)
|
chooseCode(contents, position, codeSet).ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
|
||||||
} else {
|
} else {
|
||||||
forcedCodeSet as usize // THIS IS RISKY
|
forcedCodeSet as usize // THIS IS RISKY
|
||||||
};
|
};
|
||||||
@@ -209,7 +208,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>, Exception
|
|||||||
match contents
|
match contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(position)
|
.nth(position)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
{
|
{
|
||||||
ESCAPE_FNC_1 => patternIndex = CODE_FNC_1 as isize,
|
ESCAPE_FNC_1 => patternIndex = CODE_FNC_1 as isize,
|
||||||
ESCAPE_FNC_2 => patternIndex = CODE_FNC_2 as isize,
|
ESCAPE_FNC_2 => patternIndex = CODE_FNC_2 as isize,
|
||||||
@@ -229,7 +228,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>, Exception
|
|||||||
patternIndex = contents
|
patternIndex = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(position)
|
.nth(position)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
as isize
|
as isize
|
||||||
- ' ' as isize;
|
- ' ' as isize;
|
||||||
if patternIndex < 0 {
|
if patternIndex < 0 {
|
||||||
@@ -241,7 +240,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>, Exception
|
|||||||
patternIndex = contents
|
patternIndex = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(position)
|
.nth(position)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
as isize
|
as isize
|
||||||
- ' ' as isize
|
- ' ' as isize
|
||||||
}
|
}
|
||||||
@@ -249,9 +248,9 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>, Exception
|
|||||||
// CODE_CODE_C
|
// CODE_CODE_C
|
||||||
if position + 1 == length {
|
if position + 1 == length {
|
||||||
// this is the last character, but the encoding is C, which always encodes two characers
|
// this is the last character, but the encoding is C, which always encodes two characers
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Bad number of characters for digit only encoding.".to_owned(),
|
"Bad number of characters for digit only encoding.".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
let s: String = contents
|
let s: String = contents
|
||||||
.char_indices()
|
.char_indices()
|
||||||
@@ -260,7 +259,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>, Exception
|
|||||||
.map(|(_u, c)| c)
|
.map(|(_u, c)| c)
|
||||||
.collect();
|
.collect();
|
||||||
patternIndex = s.parse::<isize>().map_err(|e| {
|
patternIndex = s.parse::<isize>().map_err(|e| {
|
||||||
Exceptions::ParseException(Some(format!("issue parsing {s}: {e}")))
|
Exceptions::parse(format!("issue parsing {s}: {e}"))
|
||||||
})?;
|
})?;
|
||||||
position += 1;
|
position += 1;
|
||||||
} // Also incremented below
|
} // Also incremented below
|
||||||
@@ -536,7 +535,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
|||||||
if contents
|
if contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
== ESCAPE_FNC_1
|
== ESCAPE_FNC_1
|
||||||
{
|
{
|
||||||
addPattern(
|
addPattern(
|
||||||
@@ -555,9 +554,8 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
|||||||
.collect();
|
.collect();
|
||||||
addPattern(
|
addPattern(
|
||||||
&mut patterns,
|
&mut patterns,
|
||||||
s.parse::<usize>().map_err(|e| {
|
s.parse::<usize>()
|
||||||
Exceptions::ParseException(Some(format!("unable to parse {s} {e}")))
|
.map_err(|e| Exceptions::parse(format!("unable to parse {s} {e}")))?,
|
||||||
})?,
|
|
||||||
&mut checkSum,
|
&mut checkSum,
|
||||||
&mut checkWeight,
|
&mut checkWeight,
|
||||||
i,
|
i,
|
||||||
@@ -572,7 +570,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
|||||||
let mut patternIndex = match contents
|
let mut patternIndex = match contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
{
|
{
|
||||||
ESCAPE_FNC_1 => CODE_FNC_1 as isize,
|
ESCAPE_FNC_1 => CODE_FNC_1 as isize,
|
||||||
ESCAPE_FNC_2 => CODE_FNC_2 as isize,
|
ESCAPE_FNC_2 => CODE_FNC_2 as isize,
|
||||||
@@ -590,7 +588,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
|||||||
contents
|
contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
as isize
|
as isize
|
||||||
- ' ' as isize
|
- ' ' as isize
|
||||||
}
|
}
|
||||||
@@ -682,7 +680,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
|||||||
minPath: &mut Vec<Vec<Latch>>,
|
minPath: &mut Vec<Vec<Latch>>,
|
||||||
) -> Result<u32, Exceptions> {
|
) -> Result<u32, Exceptions> {
|
||||||
if position >= contents.chars().count() {
|
if position >= contents.chars().count() {
|
||||||
return Err(Exceptions::IllegalStateException(None));
|
return Err(Exceptions::illegalStateEmpty());
|
||||||
}
|
}
|
||||||
let mCost = memoizedCost[charset.ordinal()][position];
|
let mCost = memoizedCost[charset.ordinal()][position];
|
||||||
if mCost > 0 {
|
if mCost > 0 {
|
||||||
@@ -763,10 +761,10 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if minCost == u32::MAX {
|
if minCost == u32::MAX {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Bad character in input: ASCII value={}",
|
"Bad character in input: ASCII value={}",
|
||||||
contents.chars().nth(position).unwrap_or('x')
|
contents.chars().nth(position).unwrap_or('x')
|
||||||
))));
|
)));
|
||||||
// throw new IllegalArgumentException("Bad character in input: ASCII value=" + (int) contents.charAt(position));
|
// throw new IllegalArgumentException("Bad character in input: ASCII value=" + (int) contents.charAt(position));
|
||||||
}
|
}
|
||||||
memoizedCost[charset.ordinal()][position] = minCost;
|
memoizedCost[charset.ordinal()][position] = minCost;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ impl OneDReader for Code39Reader {
|
|||||||
one_d_reader::recordPattern(row, nextStart, &mut counters)?;
|
one_d_reader::recordPattern(row, nextStart, &mut counters)?;
|
||||||
let pattern = Self::toNarrowWidePattern(&counters);
|
let pattern = Self::toNarrowWidePattern(&counters);
|
||||||
if pattern < 0 {
|
if pattern < 0 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
decodedChar = Self::patternToChar(pattern as u32)?;
|
decodedChar = Self::patternToChar(pattern as u32)?;
|
||||||
self.decodeRowRXingResult.push(decodedChar);
|
self.decodeRowRXingResult.push(decodedChar);
|
||||||
@@ -85,7 +85,7 @@ impl OneDReader for Code39Reader {
|
|||||||
// If 50% of last pattern size, following last pattern, is not whitespace, fail
|
// If 50% of last pattern size, following last pattern, is not whitespace, fail
|
||||||
// (but if it's whitespace to the very end of the image, that's OK)
|
// (but if it's whitespace to the very end of the image, that's OK)
|
||||||
if nextStart != end && (whiteSpaceAfterEnd * 2) < lastPatternSize as usize {
|
if nextStart != end && (whiteSpaceAfterEnd * 2) < lastPatternSize as usize {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.usingCheckDigit {
|
if self.usingCheckDigit {
|
||||||
@@ -96,7 +96,7 @@ impl OneDReader for Code39Reader {
|
|||||||
self.decodeRowRXingResult
|
self.decodeRowRXingResult
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
) {
|
) {
|
||||||
total += pos;
|
total += pos;
|
||||||
}
|
}
|
||||||
@@ -105,20 +105,20 @@ impl OneDReader for Code39Reader {
|
|||||||
.decodeRowRXingResult
|
.decodeRowRXingResult
|
||||||
.chars()
|
.chars()
|
||||||
.nth(max)
|
.nth(max)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
!= Self::ALPHABET_STRING
|
!= Self::ALPHABET_STRING
|
||||||
.chars()
|
.chars()
|
||||||
.nth(total % 43)
|
.nth(total % 43)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
{
|
{
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
self.decodeRowRXingResult.truncate(max);
|
self.decodeRowRXingResult.truncate(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.decodeRowRXingResult.chars().count() == 0 {
|
if self.decodeRowRXingResult.chars().count() == 0 {
|
||||||
// false positive
|
// false positive
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let resultString = if self.extendedMode {
|
let resultString = if self.extendedMode {
|
||||||
@@ -246,7 +246,7 @@ impl Code39Reader {
|
|||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
// For efficiency, returns -1 on failure. Not throwing here saved as many as 700 exceptions
|
// For efficiency, returns -1 on failure. Not throwing here saved as many as 700 exceptions
|
||||||
@@ -306,13 +306,13 @@ impl Code39Reader {
|
|||||||
return Self::ALPHABET_STRING
|
return Self::ALPHABET_STRING
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None));
|
.ok_or(Exceptions::indexOutOfBoundsEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pattern == Self::ASTERISK_ENCODING {
|
if pattern == Self::ASTERISK_ENCODING {
|
||||||
return Ok('*');
|
return Ok('*');
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decodeExtended(encoded: &str) -> Result<String, Exceptions> {
|
fn decodeExtended(encoded: &str) -> Result<String, Exceptions> {
|
||||||
@@ -325,46 +325,46 @@ impl Code39Reader {
|
|||||||
let c = encoded
|
let c = encoded
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
if c == '+' || c == '$' || c == '%' || c == '/' {
|
if c == '+' || c == '$' || c == '%' || c == '/' {
|
||||||
let next = encoded
|
let next = encoded
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i + 1)
|
.nth(i + 1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
let mut decodedChar = '\0';
|
let mut decodedChar = '\0';
|
||||||
match c {
|
match c {
|
||||||
'+' => {
|
'+' => {
|
||||||
// +A to +Z map to a to z
|
// +A to +Z map to a to z
|
||||||
if ('A'..='Z').contains(&next) {
|
if ('A'..='Z').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 + 32)
|
decodedChar = char::from_u32(next as u32 + 32)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'$' => {
|
'$' => {
|
||||||
// $A to $Z map to control codes SH to SB
|
// $A to $Z map to control codes SH to SB
|
||||||
if ('A'..='Z').contains(&next) {
|
if ('A'..='Z').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 - 64)
|
decodedChar = char::from_u32(next as u32 - 64)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'%' => {
|
'%' => {
|
||||||
// %A to %E map to control codes ESC to US
|
// %A to %E map to control codes ESC to US
|
||||||
if ('A'..='E').contains(&next) {
|
if ('A'..='E').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 - 38)
|
decodedChar = char::from_u32(next as u32 - 38)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
} else if ('F'..='J').contains(&next) {
|
} else if ('F'..='J').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 - 11)
|
decodedChar = char::from_u32(next as u32 - 11)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
} else if ('K'..='O').contains(&next) {
|
} else if ('K'..='O').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 + 16)
|
decodedChar = char::from_u32(next as u32 + 16)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
} else if ('P'..='T').contains(&next) {
|
} else if ('P'..='T').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 + 43)
|
decodedChar = char::from_u32(next as u32 + 43)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
} else if next == 'U' {
|
} else if next == 'U' {
|
||||||
decodedChar = 0 as char;
|
decodedChar = 0 as char;
|
||||||
} else if next == 'V' {
|
} else if next == 'V' {
|
||||||
@@ -374,18 +374,18 @@ impl Code39Reader {
|
|||||||
} else if next == 'X' || next == 'Y' || next == 'Z' {
|
} else if next == 'X' || next == 'Y' || next == 'Z' {
|
||||||
decodedChar = 127 as char;
|
decodedChar = 127 as char;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'/' => {
|
'/' => {
|
||||||
// /A to /O map to ! to , and /Z maps to :
|
// /A to /O map to ! to , and /Z maps to :
|
||||||
if ('A'..='O').contains(&next) {
|
if ('A'..='O').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 - 32)
|
decodedChar = char::from_u32(next as u32 - 32)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
} else if next == 'Z' {
|
} else if next == 'Z' {
|
||||||
decodedChar = ':';
|
decodedChar = ':';
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ impl OneDimensionalCodeWriter for Code39Writer {
|
|||||||
let mut contents = contents.to_owned();
|
let mut contents = contents.to_owned();
|
||||||
let mut length = contents.chars().count();
|
let mut length = contents.chars().count();
|
||||||
if length > 80 {
|
if length > 80 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Requested contents should be less than 80 digits long, but got {length}"
|
"Requested contents should be less than 80 digits long, but got {length}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
@@ -47,14 +47,14 @@ impl OneDimensionalCodeWriter for Code39Writer {
|
|||||||
contents
|
contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
)
|
)
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
contents = Self::tryToConvertToExtendedMode(&contents)?;
|
contents = Self::tryToConvertToExtendedMode(&contents)?;
|
||||||
length = contents.chars().count();
|
length = contents.chars().count();
|
||||||
if length > 80 {
|
if length > 80 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!("Requested contents should be less than 80 digits long, but got {length} (extended full ASCII mode)"))));
|
return Err(Exceptions::illegalArgument(format!("Requested contents should be less than 80 digits long, but got {length} (extended full ASCII mode)")));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ impl OneDimensionalCodeWriter for Code39Writer {
|
|||||||
pos += Self::appendPattern(&mut result, pos as usize, &narrowWhite, false);
|
pos += Self::appendPattern(&mut result, pos as usize, &narrowWhite, false);
|
||||||
//append next character to byte matrix
|
//append next character to byte matrix
|
||||||
for i in 0..length {
|
for i in 0..length {
|
||||||
let Some(indexInString) = Code39Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::IndexOutOfBoundsException(None))?) else {
|
let Some(indexInString) = Code39Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::indexOutOfBoundsEmpty())?) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
Self::toIntArray(
|
Self::toIntArray(
|
||||||
@@ -117,58 +117,58 @@ impl Code39Writer {
|
|||||||
extendedContent.push('$');
|
extendedContent.push('$');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + (character as u32 - 1))
|
char::from_u32('A' as u32 + (character as u32 - 1))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character < ' ' {
|
} else if character < ' ' {
|
||||||
extendedContent.push('%');
|
extendedContent.push('%');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + (character as u32 - 27))
|
char::from_u32('A' as u32 + (character as u32 - 27))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character <= ',' || character == '/' || character == ':' {
|
} else if character <= ',' || character == '/' || character == ':' {
|
||||||
extendedContent.push('/');
|
extendedContent.push('/');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + (character as u32 - 33))
|
char::from_u32('A' as u32 + (character as u32 - 33))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character <= '9' {
|
} else if character <= '9' {
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('0' as u32 + (character as u32 - 48))
|
char::from_u32('0' as u32 + (character as u32 - 48))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character <= '?' {
|
} else if character <= '?' {
|
||||||
extendedContent.push('%');
|
extendedContent.push('%');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('F' as u32 + (character as u32 - 59))
|
char::from_u32('F' as u32 + (character as u32 - 59))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character <= 'Z' {
|
} else if character <= 'Z' {
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + (character as u32 - 65))
|
char::from_u32('A' as u32 + (character as u32 - 65))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character <= '_' {
|
} else if character <= '_' {
|
||||||
extendedContent.push('%');
|
extendedContent.push('%');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('K' as u32 + (character as u32 - 91))
|
char::from_u32('K' as u32 + (character as u32 - 91))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character <= 'z' {
|
} else if character <= 'z' {
|
||||||
extendedContent.push('+');
|
extendedContent.push('+');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + (character as u32 - 97))
|
char::from_u32('A' as u32 + (character as u32 - 97))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character as u32 <= 127 {
|
} else if character as u32 <= 127 {
|
||||||
extendedContent.push('%');
|
extendedContent.push('%');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('P' as u32 + (character as u32 - 123))
|
char::from_u32('P' as u32 + (character as u32 - 123))
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Requested content contains a non-encodable character: '{character}'"
|
"Requested content contains a non-encodable character: '{character}'"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ impl OneDReader for Code93Reader {
|
|||||||
one_d_reader::recordPattern(row, nextStart, &mut theCounters)?;
|
one_d_reader::recordPattern(row, nextStart, &mut theCounters)?;
|
||||||
let pattern = Self::toPattern(&theCounters);
|
let pattern = Self::toPattern(&theCounters);
|
||||||
if pattern < 0 {
|
if pattern < 0 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
decodedChar = Self::patternToChar(pattern as u32)?;
|
decodedChar = Self::patternToChar(pattern as u32)?;
|
||||||
self.decodeRowRXingResult.push(decodedChar);
|
self.decodeRowRXingResult.push(decodedChar);
|
||||||
@@ -92,12 +92,12 @@ impl OneDReader for Code93Reader {
|
|||||||
|
|
||||||
// Should be at least one more black module
|
// Should be at least one more black module
|
||||||
if nextStart == end || !row.get(nextStart) {
|
if nextStart == end || !row.get(nextStart) {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.decodeRowRXingResult.chars().count() < 2 {
|
if self.decodeRowRXingResult.chars().count() < 2 {
|
||||||
// false positive -- need at least 2 checksum digits
|
// false positive -- need at least 2 checksum digits
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::checkChecksums(&self.decodeRowRXingResult)?;
|
Self::checkChecksums(&self.decodeRowRXingResult)?;
|
||||||
@@ -191,7 +191,7 @@ impl Code93Reader {
|
|||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toPattern(counters: &[u32; 6]) -> i32 {
|
fn toPattern(counters: &[u32; 6]) -> i32 {
|
||||||
@@ -221,7 +221,7 @@ impl Code93Reader {
|
|||||||
return Ok(Self::ALPHABET[i]);
|
return Ok(Self::ALPHABET[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decodeExtended(encoded: &str) -> Result<String, Exceptions> {
|
fn decodeExtended(encoded: &str) -> Result<String, Exceptions> {
|
||||||
@@ -234,52 +234,52 @@ impl Code93Reader {
|
|||||||
let c = encoded
|
let c = encoded
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
if ('a'..='d').contains(&c) {
|
if ('a'..='d').contains(&c) {
|
||||||
if i >= length - 1 {
|
if i >= length - 1 {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
let next = encoded
|
let next = encoded
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i + 1)
|
.nth(i + 1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
let mut decodedChar = '\0';
|
let mut decodedChar = '\0';
|
||||||
match c {
|
match c {
|
||||||
'd' => {
|
'd' => {
|
||||||
// +A to +Z map to a to z
|
// +A to +Z map to a to z
|
||||||
if ('A'..='Z').contains(&next) {
|
if ('A'..='Z').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 + 32)
|
decodedChar =
|
||||||
.ok_or(Exceptions::ParseException(None))?;
|
char::from_u32(next as u32 + 32).ok_or(Exceptions::parseEmpty())?;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'a' => {
|
'a' => {
|
||||||
// $A to $Z map to control codes SH to SB
|
// $A to $Z map to control codes SH to SB
|
||||||
if ('A'..='Z').contains(&next) {
|
if ('A'..='Z').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 - 64)
|
decodedChar =
|
||||||
.ok_or(Exceptions::ParseException(None))?;
|
char::from_u32(next as u32 - 64).ok_or(Exceptions::parseEmpty())?;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'b' => {
|
'b' => {
|
||||||
if ('A'..='E').contains(&next) {
|
if ('A'..='E').contains(&next) {
|
||||||
// %A to %E map to control codes ESC to USep
|
// %A to %E map to control codes ESC to USep
|
||||||
decodedChar = char::from_u32(next as u32 - 38)
|
decodedChar =
|
||||||
.ok_or(Exceptions::ParseException(None))?;
|
char::from_u32(next as u32 - 38).ok_or(Exceptions::parseEmpty())?;
|
||||||
} else if ('F'..='J').contains(&next) {
|
} else if ('F'..='J').contains(&next) {
|
||||||
// %F to %J map to ; < = > ?
|
// %F to %J map to ; < = > ?
|
||||||
decodedChar = char::from_u32(next as u32 - 11)
|
decodedChar =
|
||||||
.ok_or(Exceptions::ParseException(None))?;
|
char::from_u32(next as u32 - 11).ok_or(Exceptions::parseEmpty())?;
|
||||||
} else if ('K'..='O').contains(&next) {
|
} else if ('K'..='O').contains(&next) {
|
||||||
// %K to %O map to [ \ ] ^ _
|
// %K to %O map to [ \ ] ^ _
|
||||||
decodedChar = char::from_u32(next as u32 + 16)
|
decodedChar =
|
||||||
.ok_or(Exceptions::ParseException(None))?;
|
char::from_u32(next as u32 + 16).ok_or(Exceptions::parseEmpty())?;
|
||||||
} else if ('P'..='T').contains(&next) {
|
} else if ('P'..='T').contains(&next) {
|
||||||
// %P to %T map to { | } ~ DEL
|
// %P to %T map to { | } ~ DEL
|
||||||
decodedChar = char::from_u32(next as u32 + 43)
|
decodedChar =
|
||||||
.ok_or(Exceptions::ParseException(None))?;
|
char::from_u32(next as u32 + 43).ok_or(Exceptions::parseEmpty())?;
|
||||||
} else if next == 'U' {
|
} else if next == 'U' {
|
||||||
// %U map to NUL
|
// %U map to NUL
|
||||||
decodedChar = '\0';
|
decodedChar = '\0';
|
||||||
@@ -293,18 +293,18 @@ impl Code93Reader {
|
|||||||
// %X to %Z all map to DEL (127)
|
// %X to %Z all map to DEL (127)
|
||||||
decodedChar = 127 as char;
|
decodedChar = 127 as char;
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'c' => {
|
'c' => {
|
||||||
// /A to /O map to ! to , and /Z maps to :
|
// /A to /O map to ! to , and /Z maps to :
|
||||||
if ('A'..='O').contains(&next) {
|
if ('A'..='O').contains(&next) {
|
||||||
decodedChar = char::from_u32(next as u32 - 32)
|
decodedChar =
|
||||||
.ok_or(Exceptions::ParseException(None))?;
|
char::from_u32(next as u32 - 32).ok_or(Exceptions::parseEmpty())?;
|
||||||
} else if next == 'Z' {
|
} else if next == 'Z' {
|
||||||
decodedChar = ':';
|
decodedChar = ':';
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -342,7 +342,7 @@ impl Code93Reader {
|
|||||||
result
|
result
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
)
|
)
|
||||||
.map_or_else(|| -1_i32, |v| v as i32);
|
.map_or_else(|| -1_i32, |v| v as i32);
|
||||||
weight += 1;
|
weight += 1;
|
||||||
@@ -353,10 +353,10 @@ impl Code93Reader {
|
|||||||
if result
|
if result
|
||||||
.chars()
|
.chars()
|
||||||
.nth(checkPosition)
|
.nth(checkPosition)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
!= Self::ALPHABET[(total as usize) % 47]
|
!= Self::ALPHABET[(total as usize) % 47]
|
||||||
{
|
{
|
||||||
Err(Exceptions::ChecksumException(None))
|
Err(Exceptions::checksumEmpty())
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
|||||||
let mut contents = Self::convertToExtended(contents)?;
|
let mut contents = Self::convertToExtended(contents)?;
|
||||||
let length = contents.chars().count();
|
let length = contents.chars().count();
|
||||||
if length > 80 {
|
if length > 80 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!("Requested contents should be less than 80 digits long after converting to extended encoding, but got {length}" ))));
|
return Err(Exceptions::illegalArgument(format!("Requested contents should be less than 80 digits long after converting to extended encoding, but got {length}" )));
|
||||||
}
|
}
|
||||||
|
|
||||||
//length of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar
|
//length of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar
|
||||||
@@ -48,7 +48,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
|||||||
|
|
||||||
for i in 0..length {
|
for i in 0..length {
|
||||||
// for (int i = 0; i < length; i++) {
|
// for (int i = 0; i < length; i++) {
|
||||||
let Some(indexInString) = Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::IndexOutOfBoundsException(None))?) else {panic!("alphabet")};
|
let Some(indexInString) = Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::indexOutOfBoundsEmpty())?) else {panic!("alphabet")};
|
||||||
pos += Self::appendPattern(
|
pos += Self::appendPattern(
|
||||||
&mut result,
|
&mut result,
|
||||||
pos,
|
pos,
|
||||||
@@ -65,7 +65,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
|||||||
Code93Reader::ALPHABET_STRING
|
Code93Reader::ALPHABET_STRING
|
||||||
.chars()
|
.chars()
|
||||||
.nth(check1)
|
.nth(check1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
|
||||||
);
|
);
|
||||||
|
|
||||||
let check2 = Self::computeChecksumIndex(&contents, 15);
|
let check2 = Self::computeChecksumIndex(&contents, 15);
|
||||||
@@ -157,14 +157,14 @@ impl Code93Writer {
|
|||||||
extendedContent.push('a');
|
extendedContent.push('a');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + character as u32 - 1)
|
char::from_u32('A' as u32 + character as u32 - 1)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character as u32 <= 31 {
|
} else if character as u32 <= 31 {
|
||||||
// ESC - US: (%)A - (%)E
|
// ESC - US: (%)A - (%)E
|
||||||
extendedContent.push('b');
|
extendedContent.push('b');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + character as u32 - 27)
|
char::from_u32('A' as u32 + character as u32 - 27)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character == ' ' || character == '$' || character == '%' || character == '+' {
|
} else if character == ' ' || character == '$' || character == '%' || character == '+' {
|
||||||
// space $ % +
|
// space $ % +
|
||||||
@@ -174,7 +174,7 @@ impl Code93Writer {
|
|||||||
extendedContent.push('c');
|
extendedContent.push('c');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + character as u32 - '!' as u32)
|
char::from_u32('A' as u32 + character as u32 - '!' as u32)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character <= '9' {
|
} else if character <= '9' {
|
||||||
extendedContent.push(character);
|
extendedContent.push(character);
|
||||||
@@ -186,7 +186,7 @@ impl Code93Writer {
|
|||||||
extendedContent.push('b');
|
extendedContent.push('b');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('F' as u32 + character as u32 - ';' as u32)
|
char::from_u32('F' as u32 + character as u32 - ';' as u32)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character == '@' {
|
} else if character == '@' {
|
||||||
// @: (%)V
|
// @: (%)V
|
||||||
@@ -199,7 +199,7 @@ impl Code93Writer {
|
|||||||
extendedContent.push('b');
|
extendedContent.push('b');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('K' as u32 + character as u32 - '[' as u32)
|
char::from_u32('K' as u32 + character as u32 - '[' as u32)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character == '`' {
|
} else if character == '`' {
|
||||||
// `: (%)W
|
// `: (%)W
|
||||||
@@ -209,19 +209,19 @@ impl Code93Writer {
|
|||||||
extendedContent.push('d');
|
extendedContent.push('d');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('A' as u32 + character as u32 - 'a' as u32)
|
char::from_u32('A' as u32 + character as u32 - 'a' as u32)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else if character as u32 <= 127 {
|
} else if character as u32 <= 127 {
|
||||||
// { - DEL: (%)P - (%)T
|
// { - DEL: (%)P - (%)T
|
||||||
extendedContent.push('b');
|
extendedContent.push('b');
|
||||||
extendedContent.push(
|
extendedContent.push(
|
||||||
char::from_u32('P' as u32 + character as u32 - '{' as u32)
|
char::from_u32('P' as u32 + character as u32 - '{' as u32)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Requested content contains a non-encodable character: '{character}'"
|
"Requested content contains a non-encodable character: '{character}'"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ impl UPCEANReader for EAN13Reader {
|
|||||||
)?;
|
)?;
|
||||||
resultString.push(
|
resultString.push(
|
||||||
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
|
|
||||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||||
@@ -90,8 +90,7 @@ impl UPCEANReader for EAN13Reader {
|
|||||||
let bestMatch =
|
let bestMatch =
|
||||||
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
||||||
resultString.push(
|
resultString.push(
|
||||||
char::from_u32('0' as u32 + bestMatch as u32)
|
char::from_u32('0' as u32 + bestMatch as u32).ok_or(Exceptions::parseEmpty())?,
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||||
@@ -154,12 +153,11 @@ impl EAN13Reader {
|
|||||||
if lgPatternFound == Self::FIRST_DIGIT_ENCODINGS[d] {
|
if lgPatternFound == Self::FIRST_DIGIT_ENCODINGS[d] {
|
||||||
resultString.insert(
|
resultString.insert(
|
||||||
0,
|
0,
|
||||||
char::from_u32('0' as u32 + d as u32)
|
char::from_u32('0' as u32 + d as u32).ok_or(Exceptions::parseEmpty())?,
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,15 +45,15 @@ impl OneDimensionalCodeWriter for EAN13Writer {
|
|||||||
}
|
}
|
||||||
13 => {
|
13 => {
|
||||||
if !reader.checkStandardUPCEANChecksum(&contents)? {
|
if !reader.checkStandardUPCEANChecksum(&contents)? {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Contents do not pass checksum".to_owned(),
|
"Contents do not pass checksum".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Requested contents should be 12 or 13 digits long, but got {length}"
|
"Requested contents should be 12 or 13 digits long, but got {length}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,9 +62,9 @@ impl OneDimensionalCodeWriter for EAN13Writer {
|
|||||||
let firstDigit = contents
|
let firstDigit = contents
|
||||||
.chars()
|
.chars()
|
||||||
.next()
|
.next()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
.ok_or(Exceptions::parseEmpty())? as usize;
|
||||||
let parities = EAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit];
|
let parities = EAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit];
|
||||||
let mut result = [false; CODE_WIDTH];
|
let mut result = [false; CODE_WIDTH];
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
@@ -79,9 +79,9 @@ impl OneDimensionalCodeWriter for EAN13Writer {
|
|||||||
let mut digit = contents
|
let mut digit = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
.ok_or(Exceptions::parseEmpty())? as usize;
|
||||||
if (parities >> (6 - i) & 1) == 1 {
|
if (parities >> (6 - i) & 1) == 1 {
|
||||||
digit += 10;
|
digit += 10;
|
||||||
}
|
}
|
||||||
@@ -100,9 +100,9 @@ impl OneDimensionalCodeWriter for EAN13Writer {
|
|||||||
let digit = contents
|
let digit = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
.ok_or(Exceptions::parseEmpty())? as usize;
|
||||||
|
|
||||||
pos += EAN13Writer::appendPattern(
|
pos += EAN13Writer::appendPattern(
|
||||||
&mut result,
|
&mut result,
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ impl UPCEANReader for EAN8Reader {
|
|||||||
let bestMatch =
|
let bestMatch =
|
||||||
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
||||||
resultString.push(
|
resultString.push(
|
||||||
char::from_u32('0' as u32 + bestMatch as u32)
|
char::from_u32('0' as u32 + bestMatch as u32).ok_or(Exceptions::parseEmpty())?,
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||||
@@ -71,8 +70,7 @@ impl UPCEANReader for EAN8Reader {
|
|||||||
let bestMatch =
|
let bestMatch =
|
||||||
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
self.decodeDigit(row, &mut counters, rowOffset, &upc_ean_reader::L_PATTERNS)?;
|
||||||
resultString.push(
|
resultString.push(
|
||||||
char::from_u32('0' as u32 + bestMatch as u32)
|
char::from_u32('0' as u32 + bestMatch as u32).ok_or(Exceptions::parseEmpty())?,
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||||
|
|||||||
@@ -55,15 +55,15 @@ impl OneDimensionalCodeWriter for EAN8Writer {
|
|||||||
}
|
}
|
||||||
8 => {
|
8 => {
|
||||||
if !EAN8Reader.checkStandardUPCEANChecksum(&contents)? {
|
if !EAN8Reader.checkStandardUPCEANChecksum(&contents)? {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Contents do not pass checksum".to_owned(),
|
"Contents do not pass checksum".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Requested contents should be 7 or 8 digits long, but got {length}"
|
"Requested contents should be 7 or 8 digits long, but got {length}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,10 +80,9 @@ impl OneDimensionalCodeWriter for EAN8Writer {
|
|||||||
let digit = contents
|
let digit = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as usize;
|
||||||
as usize;
|
|
||||||
pos += Self::appendPattern(&mut result, pos, &upc_ean_reader::L_PATTERNS[digit], false)
|
pos += Self::appendPattern(&mut result, pos, &upc_ean_reader::L_PATTERNS[digit], false)
|
||||||
as usize;
|
as usize;
|
||||||
}
|
}
|
||||||
@@ -96,10 +95,9 @@ impl OneDimensionalCodeWriter for EAN8Writer {
|
|||||||
let digit = contents
|
let digit = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as usize;
|
||||||
as usize;
|
|
||||||
pos += Self::appendPattern(&mut result, pos, &upc_ean_reader::L_PATTERNS[digit], true)
|
pos += Self::appendPattern(&mut result, pos, &upc_ean_reader::L_PATTERNS[digit], true)
|
||||||
as usize;
|
as usize;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ impl OneDReader for ITFReader {
|
|||||||
lengthOK = true;
|
lengthOK = true;
|
||||||
}
|
}
|
||||||
if !lengthOK {
|
if !lengthOK {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut resultObject = RXingResult::new(
|
let mut resultObject = RXingResult::new(
|
||||||
@@ -195,13 +195,11 @@ impl ITFReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut bestMatch = self.decodeDigit(&counterBlack)?;
|
let mut bestMatch = self.decodeDigit(&counterBlack)?;
|
||||||
resultString.push(
|
resultString
|
||||||
char::from_u32('0' as u32 + bestMatch).ok_or(Exceptions::ParseException(None))?,
|
.push(char::from_u32('0' as u32 + bestMatch).ok_or(Exceptions::parseEmpty())?);
|
||||||
);
|
|
||||||
bestMatch = self.decodeDigit(&counterWhite)?;
|
bestMatch = self.decodeDigit(&counterWhite)?;
|
||||||
resultString.push(
|
resultString
|
||||||
char::from_u32('0' as u32 + bestMatch).ok_or(Exceptions::ParseException(None))?,
|
.push(char::from_u32('0' as u32 + bestMatch).ok_or(Exceptions::parseEmpty())?);
|
||||||
);
|
|
||||||
|
|
||||||
payloadStart += counterDigitPair.iter().sum::<u32>() as usize;
|
payloadStart += counterDigitPair.iter().sum::<u32>() as usize;
|
||||||
}
|
}
|
||||||
@@ -262,7 +260,7 @@ impl ITFReader {
|
|||||||
|
|
||||||
if quietCount != 0 {
|
if quietCount != 0 {
|
||||||
// Unable to find the necessary number of quiet zone pixels.
|
// Unable to find the necessary number of quiet zone pixels.
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -279,7 +277,7 @@ impl ITFReader {
|
|||||||
let width = row.getSize();
|
let width = row.getSize();
|
||||||
let endStart = row.getNextSet(0);
|
let endStart = row.getNextSet(0);
|
||||||
if endStart == width {
|
if endStart == width {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(endStart)
|
Ok(endStart)
|
||||||
@@ -374,7 +372,7 @@ impl ITFReader {
|
|||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -403,7 +401,7 @@ impl ITFReader {
|
|||||||
if bestMatch >= 0 {
|
if bestMatch >= 0 {
|
||||||
Ok(bestMatch as u32 % 10)
|
Ok(bestMatch as u32 % 10)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ impl OneDimensionalCodeWriter for ITFWriter {
|
|||||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||||
let length = contents.chars().count();
|
let length = contents.chars().count();
|
||||||
if length % 2 != 0 {
|
if length % 2 != 0 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"The length of the input should be even".to_owned(),
|
"The length of the input should be even".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
if length > 80 {
|
if length > 80 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Requested contents should be less than 80 digits long, but got {length}"
|
"Requested contents should be less than 80 digits long, but got {length}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::checkNumeric(contents)?;
|
Self::checkNumeric(contents)?;
|
||||||
@@ -51,15 +51,15 @@ impl OneDimensionalCodeWriter for ITFWriter {
|
|||||||
let one = contents
|
let one = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
.ok_or(Exceptions::parseEmpty())? as usize;
|
||||||
let two = contents
|
let two = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i + 1)
|
.nth(i + 1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))? as usize;
|
.ok_or(Exceptions::parseEmpty())? as usize;
|
||||||
let mut encoding = [0; 10];
|
let mut encoding = [0; 10];
|
||||||
for j in 0..5 {
|
for j in 0..5 {
|
||||||
encoding[2 * j] = PATTERNS[one][j];
|
encoding[2 * j] = PATTERNS[one][j];
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl OneDReader for MultiFormatOneDReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl MultiFormatOneDReader {
|
impl MultiFormatOneDReader {
|
||||||
@@ -168,7 +168,7 @@ impl Reader for MultiFormatOneDReader {
|
|||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ impl OneDReader for MultiFormatUPCEANReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ impl Reader for MultiFormatUPCEANReader {
|
|||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,9 +100,9 @@ pub trait OneDimensionalCodeWriter: Writer {
|
|||||||
*/
|
*/
|
||||||
fn checkNumeric(contents: &str) -> Result<(), Exceptions> {
|
fn checkNumeric(contents: &str) -> Result<(), Exceptions> {
|
||||||
if !NUMERIC.is_match(contents) {
|
if !NUMERIC.is_match(contents) {
|
||||||
Err(Exceptions::IllegalArgumentException(Some(
|
Err(Exceptions::illegalArgument(
|
||||||
"Input should only contain digits 0-9".to_owned(),
|
"Input should only contain digits 0-9".to_owned(),
|
||||||
)))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -163,29 +163,29 @@ impl Writer for L {
|
|||||||
hints: &crate::EncodingHintDictionary,
|
hints: &crate::EncodingHintDictionary,
|
||||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||||
if contents.is_empty() {
|
if contents.is_empty() {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Found empty contents".to_owned(),
|
"Found empty contents".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if width < 0 || height < 0 {
|
if width < 0 || height < 0 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Negative size is not allowed. Input: {width}x{height}"
|
"Negative size is not allowed. Input: {width}x{height}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
if let Some(supportedFormats) = self.getSupportedWriteFormats() {
|
if let Some(supportedFormats) = self.getSupportedWriteFormats() {
|
||||||
if !supportedFormats.contains(format) {
|
if !supportedFormats.contains(format) {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Can only encode {supportedFormats:?}, but got {format:?}"
|
"Can only encode {supportedFormats:?}, but got {format:?}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sidesMargin = self.getDefaultMargin();
|
let mut sidesMargin = self.getDefaultMargin();
|
||||||
if let Some(EncodeHintValue::Margin(margin)) = hints.get(&EncodeHintType::MARGIN) {
|
if let Some(EncodeHintValue::Margin(margin)) = hints.get(&EncodeHintType::MARGIN) {
|
||||||
sidesMargin = margin.parse::<u32>().map_err(|e| {
|
sidesMargin = margin
|
||||||
Exceptions::IllegalArgumentException(Some(format!("couldnt parse {margin}: {e}")))
|
.parse::<u32>()
|
||||||
})?;
|
.map_err(|e| Exceptions::illegalArgument(format!("couldnt parse {margin}: {e}")))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = self.encode_oned_with_hints(contents, hints)?;
|
let code = self.encode_oned_with_hints(contents, hints)?;
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ pub trait OneDReader: Reader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,7 +218,7 @@ pub fn recordPattern(row: &BitArray, start: usize, counters: &mut [u32]) -> Resu
|
|||||||
|
|
||||||
let end = row.getSize();
|
let end = row.getSize();
|
||||||
if start >= end {
|
if start >= end {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut isWhite = !row.get(start);
|
let mut isWhite = !row.get(start);
|
||||||
@@ -241,7 +241,7 @@ pub fn recordPattern(row: &BitArray, start: usize, counters: &mut [u32]) -> Resu
|
|||||||
// If we read fully the last section of pixels and filled up our counters -- or filled
|
// If we read fully the last section of pixels and filled up our counters -- or filled
|
||||||
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
|
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
|
||||||
if !(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end)) {
|
if !(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end)) {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ pub fn recordPatternInReverse(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if numTransitionsLeft >= 0 {
|
if numTransitionsLeft >= 0 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
recordPattern(row, start + 1, counters)?;
|
recordPattern(row, start + 1, counters)?;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub trait AbstractRSSReaderTrait: OneDReader {
|
|||||||
return Ok(value as u32);
|
return Ok(value as u32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,23 +50,13 @@ pub fn buildBitArrayFromString(data: &str) -> Result<BitArray, Exceptions> {
|
|||||||
// for (int i = 0; i < dotsAndXs.length(); ++i) {
|
// for (int i = 0; i < dotsAndXs.length(); ++i) {
|
||||||
if i % 9 == 0 {
|
if i % 9 == 0 {
|
||||||
// spaces
|
// spaces
|
||||||
if dotsAndXs
|
if dotsAndXs.chars().nth(i).ok_or(Exceptions::parseEmpty())? != ' ' {
|
||||||
.chars()
|
return Err(Exceptions::illegalState("space expected".to_owned()));
|
||||||
.nth(i)
|
|
||||||
.ok_or(Exceptions::ParseException(None))?
|
|
||||||
!= ' '
|
|
||||||
{
|
|
||||||
return Err(Exceptions::IllegalStateException(Some(
|
|
||||||
"space expected".to_owned(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentChar = dotsAndXs
|
let currentChar = dotsAndXs.chars().nth(i).ok_or(Exceptions::parseEmpty())?;
|
||||||
.chars()
|
|
||||||
.nth(i)
|
|
||||||
.ok_or(Exceptions::ParseException(None))?;
|
|
||||||
if currentChar == 'X' || currentChar == 'x' {
|
if currentChar == 'X' || currentChar == 'x' {
|
||||||
binary.set(counter);
|
binary.set(counter);
|
||||||
}
|
}
|
||||||
@@ -92,7 +82,7 @@ pub fn buildBitArrayFromStringWithoutSpaces(data: &str) -> Result<BitArray, Exce
|
|||||||
dotsAndXs
|
dotsAndXs
|
||||||
.chars()
|
.chars()
|
||||||
.nth(current)
|
.nth(current)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
current += 1;
|
current += 1;
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ pub fn createDecoder<'a>(
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::IllegalStateException(Some(format!(
|
Err(Exceptions::illegalState(format!(
|
||||||
"unknown decoder: {information}"
|
"unknown decoder: {information}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl AI01decoder for AI01392xDecoder<'_> {}
|
|||||||
impl AbstractExpandedDecoder for AI01392xDecoder<'_> {
|
impl AbstractExpandedDecoder for AI01392xDecoder<'_> {
|
||||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||||
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
||||||
return Err(crate::Exceptions::NotFoundException(None));
|
return Err(crate::Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl AI01decoder for AI01393xDecoder<'_> {}
|
|||||||
impl AbstractExpandedDecoder for AI01393xDecoder<'_> {
|
impl AbstractExpandedDecoder for AI01393xDecoder<'_> {
|
||||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||||
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
||||||
return Err(crate::Exceptions::NotFoundException(None));
|
return Err(crate::Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ impl AbstractExpandedDecoder for AI013x0x1xDecoder<'_> {
|
|||||||
if self.information.getSize()
|
if self.information.getSize()
|
||||||
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE + Self::DATE_SIZE
|
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE + Self::DATE_SIZE
|
||||||
{
|
{
|
||||||
return Err(crate::Exceptions::NotFoundException(None));
|
return Err(crate::Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ impl AbstractExpandedDecoder for AI013x0xDecoder<'_> {
|
|||||||
if self.information.getSize()
|
if self.information.getSize()
|
||||||
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE
|
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE
|
||||||
{
|
{
|
||||||
return Err(crate::Exceptions::NotFoundException(None));
|
return Err(crate::Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl DecodedNumeric {
|
|||||||
if
|
if
|
||||||
/*firstDigit < 0 ||*/
|
/*firstDigit < 0 ||*/
|
||||||
firstDigit > 10 || /*secondDigit < 0 ||*/ secondDigit > 10 {
|
firstDigit > 10 || /*secondDigit < 0 ||*/ secondDigit > 10 {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
|||||||
// Processing 2-digit AIs
|
// Processing 2-digit AIs
|
||||||
|
|
||||||
if rawInformation.chars().count() < 2 {
|
if rawInformation.chars().count() < 2 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let lookup: String = rawInformation.chars().take(2).collect();
|
let lookup: String = rawInformation.chars().take(2).collect();
|
||||||
@@ -158,7 +158,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rawInformation.chars().count() < 3 {
|
if rawInformation.chars().count() < 3 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let firstThreeDigits: String = rawInformation.chars().take(3).collect();
|
let firstThreeDigits: String = rawInformation.chars().take(3).collect();
|
||||||
@@ -171,7 +171,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rawInformation.chars().count() < 4 {
|
if rawInformation.chars().count() < 4 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let threeDigitPlusDigitDataLength = THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.get(&firstThreeDigits);
|
let threeDigitPlusDigitDataLength = THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.get(&firstThreeDigits);
|
||||||
@@ -191,7 +191,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
|||||||
return processFixedAI(4, ffdl.length, rawInformation);
|
return processFixedAI(4, ffdl.length, rawInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn processFixedAI(
|
fn processFixedAI(
|
||||||
@@ -200,13 +200,13 @@ fn processFixedAI(
|
|||||||
rawInformation: &str,
|
rawInformation: &str,
|
||||||
) -> Result<String, Exceptions> {
|
) -> Result<String, Exceptions> {
|
||||||
if rawInformation.chars().count() < aiSize {
|
if rawInformation.chars().count() < aiSize {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let ai: String = rawInformation.chars().take(aiSize).collect();
|
let ai: String = rawInformation.chars().take(aiSize).collect();
|
||||||
|
|
||||||
if rawInformation.chars().count() < aiSize + fieldSize {
|
if rawInformation.chars().count() < aiSize + fieldSize {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let field: String = rawInformation
|
let field: String = rawInformation
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
|||||||
if let Some(r) = result.getDecodedInformation() {
|
if let Some(r) = result.getDecodedInformation() {
|
||||||
Ok(r.clone())
|
Ok(r.clone())
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,8 +345,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
|||||||
if (5..15).contains(&fiveBitValue) {
|
if (5..15).contains(&fiveBitValue) {
|
||||||
return Ok(DecodedChar::new(
|
return Ok(DecodedChar::new(
|
||||||
pos + 5,
|
pos + 5,
|
||||||
char::from_u32('0' as u32 + fiveBitValue - 5)
|
char::from_u32('0' as u32 + fiveBitValue - 5).ok_or(Exceptions::parseEmpty())?,
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,14 +354,14 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
|||||||
if (64..90).contains(&sevenBitValue) {
|
if (64..90).contains(&sevenBitValue) {
|
||||||
return Ok(DecodedChar::new(
|
return Ok(DecodedChar::new(
|
||||||
pos + 7,
|
pos + 7,
|
||||||
char::from_u32(sevenBitValue + 1).ok_or(Exceptions::ParseException(None))?,
|
char::from_u32(sevenBitValue + 1).ok_or(Exceptions::parseEmpty())?,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (90..116).contains(&sevenBitValue) {
|
if (90..116).contains(&sevenBitValue) {
|
||||||
return Ok(DecodedChar::new(
|
return Ok(DecodedChar::new(
|
||||||
pos + 7,
|
pos + 7,
|
||||||
char::from_u32(sevenBitValue + 7).ok_or(Exceptions::ParseException(None))?,
|
char::from_u32(sevenBitValue + 7).ok_or(Exceptions::parseEmpty())?,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +388,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
|||||||
250 => '?',
|
250 => '?',
|
||||||
251 => '_',
|
251 => '_',
|
||||||
252 => ' ',
|
252 => ' ',
|
||||||
_ => return Err(Exceptions::FormatException(None)),
|
_ => return Err(Exceptions::formatEmpty()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(DecodedChar::new(pos + 8, c))
|
Ok(DecodedChar::new(pos + 8, c))
|
||||||
@@ -424,8 +423,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
|||||||
if (5..15).contains(&fiveBitValue) {
|
if (5..15).contains(&fiveBitValue) {
|
||||||
return Ok(DecodedChar::new(
|
return Ok(DecodedChar::new(
|
||||||
pos + 5,
|
pos + 5,
|
||||||
char::from_u32('0' as u32 + fiveBitValue - 5)
|
char::from_u32('0' as u32 + fiveBitValue - 5).ok_or(Exceptions::parseEmpty())?,
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +432,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
|||||||
if (32..58).contains(&sixBitValue) {
|
if (32..58).contains(&sixBitValue) {
|
||||||
return Ok(DecodedChar::new(
|
return Ok(DecodedChar::new(
|
||||||
pos + 6,
|
pos + 6,
|
||||||
char::from_u32(sixBitValue + 33).ok_or(Exceptions::ParseException(None))?,
|
char::from_u32(sixBitValue + 33).ok_or(Exceptions::parseEmpty())?,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,9 +443,9 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
|||||||
61 => '.',
|
61 => '.',
|
||||||
62 => '/',
|
62 => '/',
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Exceptions::IllegalStateException(Some(format!(
|
return Err(Exceptions::illegalState(format!(
|
||||||
"Decoding invalid alphanumeric value: {sixBitValue}"
|
"Decoding invalid alphanumeric value: {sixBitValue}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ impl Reader for RSSExpandedReader {
|
|||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,9 +297,7 @@ impl RSSExpandedReader {
|
|||||||
if let Ok(to_add) = to_add_res {
|
if let Ok(to_add) = to_add_res {
|
||||||
self.pairs.push(to_add);
|
self.pairs.push(to_add);
|
||||||
} else if self.pairs.is_empty() {
|
} else if self.pairs.is_empty() {
|
||||||
return Err(to_add_res
|
return Err(to_add_res.err().unwrap_or(Exceptions::illegalStateEmpty()));
|
||||||
.err()
|
|
||||||
.unwrap_or(Exceptions::IllegalStateException(None)));
|
|
||||||
} else {
|
} else {
|
||||||
// exit this loop when retrieveNextPair() fails and throws
|
// exit this loop when retrieveNextPair() fails and throws
|
||||||
done = true;
|
done = true;
|
||||||
@@ -331,7 +329,7 @@ impl RSSExpandedReader {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkRows(&mut self, reverse: bool) -> Option<Vec<ExpandedPair>> {
|
fn checkRows(&mut self, reverse: bool) -> Option<Vec<ExpandedPair>> {
|
||||||
@@ -378,7 +376,7 @@ impl RSSExpandedReader {
|
|||||||
let row = self
|
let row = self
|
||||||
.rows
|
.rows
|
||||||
.get(i)
|
.get(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
self.pairs.clear();
|
self.pairs.clear();
|
||||||
for collectedRow in &collectedRows.clone() {
|
for collectedRow in &collectedRows.clone() {
|
||||||
// for (ExpandedRow collectedRow : collectedRows) {
|
// for (ExpandedRow collectedRow : collectedRows) {
|
||||||
@@ -406,7 +404,7 @@ impl RSSExpandedReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the pairs form a valid find pattern sequence,
|
/// Whether the pairs form a valid find pattern sequence,
|
||||||
@@ -537,24 +535,24 @@ impl RSSExpandedReader {
|
|||||||
// Not private for unit testing
|
// Not private for unit testing
|
||||||
pub(crate) fn constructRXingResult(pairs: &[ExpandedPair]) -> Result<RXingResult, Exceptions> {
|
pub(crate) fn constructRXingResult(pairs: &[ExpandedPair]) -> Result<RXingResult, Exceptions> {
|
||||||
let binary = bit_array_builder::buildBitArray(&pairs.to_vec())
|
let binary = bit_array_builder::buildBitArray(&pairs.to_vec())
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?;
|
.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
|
|
||||||
let mut decoder = abstract_expanded_decoder::createDecoder(&binary)?;
|
let mut decoder = abstract_expanded_decoder::createDecoder(&binary)?;
|
||||||
let resultingString = decoder.parseInformation()?;
|
let resultingString = decoder.parseInformation()?;
|
||||||
|
|
||||||
let firstPoints = pairs
|
let firstPoints = pairs
|
||||||
.get(0)
|
.get(0)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.getFinderPattern()
|
.getFinderPattern()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getRXingResultPoints();
|
.getRXingResultPoints();
|
||||||
let lastPoints = pairs
|
let lastPoints = pairs
|
||||||
.last()
|
.last()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.getFinderPattern()
|
.getFinderPattern()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getRXingResultPoints();
|
.getRXingResultPoints();
|
||||||
|
|
||||||
let mut result = RXingResult::new(
|
let mut result = RXingResult::new(
|
||||||
@@ -653,9 +651,7 @@ impl RSSExpandedReader {
|
|||||||
|
|
||||||
let leftChar = self.decodeDataCharacter(
|
let leftChar = self.decodeDataCharacter(
|
||||||
row,
|
row,
|
||||||
pattern
|
pattern.as_ref().ok_or(Exceptions::notFoundEmpty())?,
|
||||||
.as_ref()
|
|
||||||
.ok_or(Exceptions::NotFoundException(None))?,
|
|
||||||
isOddPattern,
|
isOddPattern,
|
||||||
true,
|
true,
|
||||||
)?;
|
)?;
|
||||||
@@ -663,18 +659,16 @@ impl RSSExpandedReader {
|
|||||||
if !previousPairs.is_empty()
|
if !previousPairs.is_empty()
|
||||||
&& previousPairs
|
&& previousPairs
|
||||||
.last()
|
.last()
|
||||||
.ok_or(Exceptions::NotFoundException(None))?
|
.ok_or(Exceptions::notFoundEmpty())?
|
||||||
.mustBeLast()
|
.mustBeLast()
|
||||||
{
|
{
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let rightChar = self
|
let rightChar = self
|
||||||
.decodeDataCharacter(
|
.decodeDataCharacter(
|
||||||
row,
|
row,
|
||||||
pattern
|
pattern.as_ref().ok_or(Exceptions::notFoundEmpty())?,
|
||||||
.as_ref()
|
|
||||||
.ok_or(Exceptions::NotFoundException(None))?,
|
|
||||||
isOddPattern,
|
isOddPattern,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
@@ -706,11 +700,11 @@ impl RSSExpandedReader {
|
|||||||
} else {
|
} else {
|
||||||
let lastPair = previousPairs
|
let lastPair = previousPairs
|
||||||
.last()
|
.last()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
rowOffset = lastPair
|
rowOffset = lastPair
|
||||||
.getFinderPattern()
|
.getFinderPattern()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.getStartEnd()[1] as i32;
|
.getStartEnd()[1] as i32;
|
||||||
}
|
}
|
||||||
let mut searchingEvenPair = previousPairs.len() % 2 != 0;
|
let mut searchingEvenPair = previousPairs.len() % 2 != 0;
|
||||||
@@ -762,7 +756,7 @@ impl RSSExpandedReader {
|
|||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reverseCounters(counters: &mut [u32]) {
|
fn reverseCounters(counters: &mut [u32]) {
|
||||||
@@ -859,7 +853,7 @@ impl RSSExpandedReader {
|
|||||||
let expectedElementWidth: f32 =
|
let expectedElementWidth: f32 =
|
||||||
(pattern.getStartEnd()[1] - pattern.getStartEnd()[0]) as f32 / 15.0;
|
(pattern.getStartEnd()[1] - pattern.getStartEnd()[0]) as f32 / 15.0;
|
||||||
if (elementWidth - expectedElementWidth).abs() / expectedElementWidth > 0.3 {
|
if (elementWidth - expectedElementWidth).abs() / expectedElementWidth > 0.3 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, counter) in counters.iter().enumerate() {
|
for (i, counter) in counters.iter().enumerate() {
|
||||||
@@ -868,12 +862,12 @@ impl RSSExpandedReader {
|
|||||||
let mut count = (value + 0.5) as i32; // Round
|
let mut count = (value + 0.5) as i32; // Round
|
||||||
if count < 1 {
|
if count < 1 {
|
||||||
if value < 0.3 {
|
if value < 0.3 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
count = 1;
|
count = 1;
|
||||||
} else if count > 8 {
|
} else if count > 8 {
|
||||||
if value > 8.7 {
|
if value > 8.7 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
count = 8;
|
count = 8;
|
||||||
}
|
}
|
||||||
@@ -913,7 +907,7 @@ impl RSSExpandedReader {
|
|||||||
let checksumPortion = oddChecksumPortion + evenChecksumPortion;
|
let checksumPortion = oddChecksumPortion + evenChecksumPortion;
|
||||||
|
|
||||||
if (oddSum & 0x01) != 0 || !(4..=13).contains(&oddSum) {
|
if (oddSum & 0x01) != 0 || !(4..=13).contains(&oddSum) {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let group = ((13 - oddSum) / 2) as usize;
|
let group = ((13 - oddSum) / 2) as usize;
|
||||||
@@ -961,12 +955,12 @@ impl RSSExpandedReader {
|
|||||||
1 => {
|
1 => {
|
||||||
if oddParityBad {
|
if oddParityBad {
|
||||||
if evenParityBad {
|
if evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
decrementOdd = true;
|
decrementOdd = true;
|
||||||
} else {
|
} else {
|
||||||
if !evenParityBad {
|
if !evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
decrementEven = true;
|
decrementEven = true;
|
||||||
}
|
}
|
||||||
@@ -974,12 +968,12 @@ impl RSSExpandedReader {
|
|||||||
-1 => {
|
-1 => {
|
||||||
if oddParityBad {
|
if oddParityBad {
|
||||||
if evenParityBad {
|
if evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
incrementOdd = true;
|
incrementOdd = true;
|
||||||
} else {
|
} else {
|
||||||
if !evenParityBad {
|
if !evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
incrementEven = true;
|
incrementEven = true;
|
||||||
}
|
}
|
||||||
@@ -987,7 +981,7 @@ impl RSSExpandedReader {
|
|||||||
0 => {
|
0 => {
|
||||||
if oddParityBad {
|
if oddParityBad {
|
||||||
if !evenParityBad {
|
if !evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
// Both bad
|
// Both bad
|
||||||
if oddSum < evenSum {
|
if oddSum < evenSum {
|
||||||
@@ -998,16 +992,16 @@ impl RSSExpandedReader {
|
|||||||
incrementEven = true;
|
incrementEven = true;
|
||||||
}
|
}
|
||||||
} else if evenParityBad {
|
} else if evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => return Err(Exceptions::NotFoundException(None)),
|
_ => return Err(Exceptions::notFoundEmpty()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if incrementOdd {
|
if incrementOdd {
|
||||||
if decrementOdd {
|
if decrementOdd {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
|
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
|
||||||
}
|
}
|
||||||
@@ -1016,7 +1010,7 @@ impl RSSExpandedReader {
|
|||||||
}
|
}
|
||||||
if incrementEven {
|
if incrementEven {
|
||||||
if decrementEven {
|
if decrementEven {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
Self::increment(&mut self.evenCounts, &self.oddRoundingErrors);
|
Self::increment(&mut self.evenCounts, &self.oddRoundingErrors);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,12 +64,12 @@ impl OneDReader for RSS14Reader {
|
|||||||
if right.getCount() > 1 && self.checkChecksum(left, right) {
|
if right.getCount() > 1 && self.checkChecksum(left, right) {
|
||||||
return self
|
return self
|
||||||
.constructRXingResult(left, right)
|
.constructRXingResult(left, right)
|
||||||
.ok_or(Exceptions::IllegalStateException(None));
|
.ok_or(Exceptions::illegalStateEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Reader for RSS14Reader {
|
impl Reader for RSS14Reader {
|
||||||
@@ -126,7 +126,7 @@ impl Reader for RSS14Reader {
|
|||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,7 +343,7 @@ impl RSS14Reader {
|
|||||||
|
|
||||||
if outsideChar {
|
if outsideChar {
|
||||||
if (oddSum & 0x01) != 0 || !(4..=12).contains(&oddSum) {
|
if (oddSum & 0x01) != 0 || !(4..=12).contains(&oddSum) {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
let group = ((12 - oddSum) / 2) as usize;
|
let group = ((12 - oddSum) / 2) as usize;
|
||||||
let oddWidest = Self::OUTSIDE_ODD_WIDEST[group];
|
let oddWidest = Self::OUTSIDE_ODD_WIDEST[group];
|
||||||
@@ -358,7 +358,7 @@ impl RSS14Reader {
|
|||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
if (evenSum & 0x01) != 0 || !(4..=10).contains(&evenSum) {
|
if (evenSum & 0x01) != 0 || !(4..=10).contains(&evenSum) {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
let group = ((10 - evenSum) / 2) as usize;
|
let group = ((10 - evenSum) / 2) as usize;
|
||||||
let oddWidest = Self::INSIDE_ODD_WIDEST[group];
|
let oddWidest = Self::INSIDE_ODD_WIDEST[group];
|
||||||
@@ -417,7 +417,7 @@ impl RSS14Reader {
|
|||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseFoundFinderPattern(
|
fn parseFoundFinderPattern(
|
||||||
@@ -518,12 +518,12 @@ impl RSS14Reader {
|
|||||||
1 => {
|
1 => {
|
||||||
if oddParityBad {
|
if oddParityBad {
|
||||||
if evenParityBad {
|
if evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
decrementOdd = true;
|
decrementOdd = true;
|
||||||
} else {
|
} else {
|
||||||
if !evenParityBad {
|
if !evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
decrementEven = true;
|
decrementEven = true;
|
||||||
}
|
}
|
||||||
@@ -531,12 +531,12 @@ impl RSS14Reader {
|
|||||||
-1 => {
|
-1 => {
|
||||||
if oddParityBad {
|
if oddParityBad {
|
||||||
if evenParityBad {
|
if evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
incrementOdd = true;
|
incrementOdd = true;
|
||||||
} else {
|
} else {
|
||||||
if !evenParityBad {
|
if !evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
incrementEven = true;
|
incrementEven = true;
|
||||||
}
|
}
|
||||||
@@ -544,7 +544,7 @@ impl RSS14Reader {
|
|||||||
0 => {
|
0 => {
|
||||||
if oddParityBad {
|
if oddParityBad {
|
||||||
if !evenParityBad {
|
if !evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
// Both bad
|
// Both bad
|
||||||
if oddSum < evenSum {
|
if oddSum < evenSum {
|
||||||
@@ -555,15 +555,15 @@ impl RSS14Reader {
|
|||||||
incrementEven = true;
|
incrementEven = true;
|
||||||
}
|
}
|
||||||
} else if evenParityBad {
|
} else if evenParityBad {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return Err(Exceptions::NotFoundException(None)),
|
_ => return Err(Exceptions::notFoundEmpty()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if incrementOdd {
|
if incrementOdd {
|
||||||
if decrementOdd {
|
if decrementOdd {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
|
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
|
||||||
}
|
}
|
||||||
@@ -572,7 +572,7 @@ impl RSS14Reader {
|
|||||||
}
|
}
|
||||||
if incrementEven {
|
if incrementEven {
|
||||||
if decrementEven {
|
if decrementEven {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
Self::increment(&mut self.evenCounts, &self.evenRoundingErrors);
|
Self::increment(&mut self.evenCounts, &self.evenRoundingErrors);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ impl UPCAReader {
|
|||||||
|
|
||||||
Ok(upcaRXingResult)
|
Ok(upcaRXingResult)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ impl Writer for UPCAWriter {
|
|||||||
hints: &crate::EncodingHintDictionary,
|
hints: &crate::EncodingHintDictionary,
|
||||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||||
if format != &BarcodeFormat::UPC_A {
|
if format != &BarcodeFormat::UPC_A {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Can only encode UPC-A, but got {format:?}"
|
"Can only encode UPC-A, but got {format:?}"
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
// Transform a UPC-A code into the equivalent EAN-13 code and write it that way
|
// Transform a UPC-A code into the equivalent EAN-13 code and write it that way
|
||||||
self.0.encode_with_hints(
|
self.0.encode_with_hints(
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl UPCEANReader for UPCEReader {
|
|||||||
let bestMatch = self.decodeDigit(row, &mut counters, rowOffset, &L_AND_G_PATTERNS)?;
|
let bestMatch = self.decodeDigit(row, &mut counters, rowOffset, &L_AND_G_PATTERNS)?;
|
||||||
resultString.push(
|
resultString.push(
|
||||||
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ impl UPCEANReader for UPCEReader {
|
|||||||
|
|
||||||
fn checkChecksum(&self, s: &str) -> Result<bool, Exceptions> {
|
fn checkChecksum(&self, s: &str) -> Result<bool, Exceptions> {
|
||||||
self.checkStandardUPCEANChecksum(
|
self.checkStandardUPCEANChecksum(
|
||||||
&convertUPCEtoUPCA(s).ok_or(Exceptions::IllegalArgumentException(None))?,
|
&convertUPCEtoUPCA(s).ok_or(Exceptions::illegalArgumentEmpty())?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,17 +133,16 @@ impl UPCEReader {
|
|||||||
resultString.insert(
|
resultString.insert(
|
||||||
0,
|
0,
|
||||||
char::from_u32('0' as u32 + numSys as u32)
|
char::from_u32('0' as u32 + numSys as u32)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
resultString.push(
|
resultString.push(
|
||||||
char::from_u32('0' as u32 + d as u32)
|
char::from_u32('0' as u32 + d as u32).ok_or(Exceptions::parseEmpty())?,
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,24 +46,24 @@ impl OneDimensionalCodeWriter for UPCEWriter {
|
|||||||
// No check digit present, calculate it and add it
|
// No check digit present, calculate it and add it
|
||||||
let check = reader.getStandardUPCEANChecksum(
|
let check = reader.getStandardUPCEANChecksum(
|
||||||
&upc_e_reader::convertUPCEtoUPCA(&contents)
|
&upc_e_reader::convertUPCEtoUPCA(&contents)
|
||||||
.ok_or(Exceptions::IllegalArgumentException(None))?,
|
.ok_or(Exceptions::illegalArgumentEmpty())?,
|
||||||
)?;
|
)?;
|
||||||
contents.push_str(&check.to_string());
|
contents.push_str(&check.to_string());
|
||||||
}
|
}
|
||||||
8 => {
|
8 => {
|
||||||
if !reader.checkStandardUPCEANChecksum(
|
if !reader.checkStandardUPCEANChecksum(
|
||||||
&upc_e_reader::convertUPCEtoUPCA(&contents)
|
&upc_e_reader::convertUPCEtoUPCA(&contents)
|
||||||
.ok_or(Exceptions::IllegalArgumentException(None))?,
|
.ok_or(Exceptions::illegalArgumentEmpty())?,
|
||||||
)? {
|
)? {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Contents do not pass checksum".to_owned(),
|
"Contents do not pass checksum".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::illegalArgument(format!(
|
||||||
"Requested contents should be 7 or 8 digits long, but got {length}"
|
"Requested contents should be 7 or 8 digits long, but got {length}"
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,21 +72,21 @@ impl OneDimensionalCodeWriter for UPCEWriter {
|
|||||||
let firstDigit = contents
|
let firstDigit = contents
|
||||||
.chars()
|
.chars()
|
||||||
.next()
|
.next()
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))? as usize; //Character.digit(contents.charAt(0), 10);
|
.ok_or(Exceptions::parseEmpty())? as usize; //Character.digit(contents.charAt(0), 10);
|
||||||
if firstDigit != 0 && firstDigit != 1 {
|
if firstDigit != 0 && firstDigit != 1 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(
|
return Err(Exceptions::illegalArgument(
|
||||||
"Number system must be 0 or 1".to_owned(),
|
"Number system must be 0 or 1".to_owned(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let checkDigit = contents
|
let checkDigit = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(7)
|
.nth(7)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))? as usize; //Character.digit(contents.charAt(7), 10);
|
.ok_or(Exceptions::parseEmpty())? as usize; //Character.digit(contents.charAt(7), 10);
|
||||||
let parities = UPCEReader::NUMSYS_AND_CHECK_DIGIT_PATTERNS[firstDigit][checkDigit];
|
let parities = UPCEReader::NUMSYS_AND_CHECK_DIGIT_PATTERNS[firstDigit][checkDigit];
|
||||||
let mut result = [false; CODE_WIDTH];
|
let mut result = [false; CODE_WIDTH];
|
||||||
|
|
||||||
@@ -98,9 +98,9 @@ impl OneDimensionalCodeWriter for UPCEWriter {
|
|||||||
let mut digit = contents
|
let mut digit = contents
|
||||||
.chars()
|
.chars()
|
||||||
.nth(i)
|
.nth(i)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))? as usize; //Character.digit(contents.charAt(i), 10);
|
.ok_or(Exceptions::parseEmpty())? as usize; //Character.digit(contents.charAt(i), 10);
|
||||||
if (parities >> (6 - i) & 1) == 1 {
|
if (parities >> (6 - i) & 1) == 1 {
|
||||||
digit += 10;
|
digit += 10;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ impl UPCEANExtension2Support {
|
|||||||
)?;
|
)?;
|
||||||
resultString.push(
|
resultString.push(
|
||||||
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
|
|
||||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||||
@@ -105,15 +105,16 @@ impl UPCEANExtension2Support {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resultString.chars().count() != 2 {
|
if resultString.chars().count() != 2 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if resultString.parse::<u32>().map_err(|e| {
|
if resultString
|
||||||
Exceptions::ParseException(Some(format!("could not parse {resultString}: {e}")))
|
.parse::<u32>()
|
||||||
})? % 4
|
.map_err(|e| Exceptions::parse(format!("could not parse {resultString}: {e}")))?
|
||||||
|
% 4
|
||||||
!= checkParity
|
!= checkParity
|
||||||
{
|
{
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(rowOffset as u32)
|
Ok(rowOffset as u32)
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl UPCEANExtension5Support {
|
|||||||
)?;
|
)?;
|
||||||
resultString.push(
|
resultString.push(
|
||||||
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
char::from_u32('0' as u32 + bestMatch as u32 % 10)
|
||||||
.ok_or(Exceptions::ParseException(None))?,
|
.ok_or(Exceptions::parseEmpty())?,
|
||||||
);
|
);
|
||||||
|
|
||||||
rowOffset += counters.iter().sum::<u32>() as usize;
|
rowOffset += counters.iter().sum::<u32>() as usize;
|
||||||
@@ -105,15 +105,14 @@ impl UPCEANExtension5Support {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resultString.chars().count() != 5 {
|
if resultString.chars().count() != 5 {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let checkDigit = Self::determineCheckDigit(lgPatternFound)?;
|
let checkDigit = Self::determineCheckDigit(lgPatternFound)?;
|
||||||
if Self::extensionChecksum(resultString)
|
if Self::extensionChecksum(resultString).ok_or(Exceptions::illegalArgumentEmpty())?
|
||||||
.ok_or(Exceptions::IllegalArgumentException(None))?
|
|
||||||
!= checkDigit as u32
|
!= checkDigit as u32
|
||||||
{
|
{
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(rowOffset as u32)
|
Ok(rowOffset as u32)
|
||||||
@@ -148,7 +147,7 @@ impl UPCEANExtension5Support {
|
|||||||
return Ok(d);
|
return Ok(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -182,18 +182,18 @@ pub trait UPCEANReader: OneDReader {
|
|||||||
let end = endRange[1];
|
let end = endRange[1];
|
||||||
let quietEnd = end + (end - endRange[0]);
|
let quietEnd = end + (end - endRange[0]);
|
||||||
if quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)? {
|
if quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)? {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let resultString = result;
|
let resultString = result;
|
||||||
|
|
||||||
// UPC/EAN should never be less than 8 chars anyway
|
// UPC/EAN should never be less than 8 chars anyway
|
||||||
if resultString.chars().count() < 8 {
|
if resultString.chars().count() < 8 {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.checkChecksum(&resultString)? {
|
if !self.checkChecksum(&resultString)? {
|
||||||
return Err(Exceptions::ChecksumException(None));
|
return Err(Exceptions::checksumEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let left = (startGuardRange[1] + startGuardRange[0]) as f32 / 2.0;
|
let left = (startGuardRange[1] + startGuardRange[0]) as f32 / 2.0;
|
||||||
@@ -241,7 +241,7 @@ pub trait UPCEANReader: OneDReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !valid {
|
if !valid {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ pub trait UPCEANReader: OneDReader {
|
|||||||
let char_in_question = s
|
let char_in_question = s
|
||||||
.chars()
|
.chars()
|
||||||
.nth(length - 1)
|
.nth(length - 1)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())?;
|
||||||
let check = char_in_question.is_ascii_digit();
|
let check = char_in_question.is_ascii_digit();
|
||||||
|
|
||||||
let check_against = &s[..length - 1]; //s.subSequence(0, length - 1);
|
let check_against = &s[..length - 1]; //s.subSequence(0, length - 1);
|
||||||
@@ -302,7 +302,7 @@ pub trait UPCEANReader: OneDReader {
|
|||||||
== if check {
|
== if check {
|
||||||
char_in_question
|
char_in_question
|
||||||
.to_digit(10)
|
.to_digit(10)
|
||||||
.ok_or(Exceptions::ParseException(None))?
|
.ok_or(Exceptions::parseEmpty())?
|
||||||
} else {
|
} else {
|
||||||
u32::MAX
|
u32::MAX
|
||||||
})
|
})
|
||||||
@@ -314,13 +314,13 @@ pub trait UPCEANReader: OneDReader {
|
|||||||
let mut i = length as isize - 1;
|
let mut i = length as isize - 1;
|
||||||
while i >= 0 {
|
while i >= 0 {
|
||||||
// for (int i = length - 1; i >= 0; i -= 2) {
|
// for (int i = length - 1; i >= 0; i -= 2) {
|
||||||
let digit =
|
let digit = (s
|
||||||
(s.chars()
|
.chars()
|
||||||
.nth(i as usize)
|
.nth(i as usize)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as i32)
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as i32)
|
||||||
- ('0' as i32);
|
- ('0' as i32);
|
||||||
if !(0..=9).contains(&digit) {
|
if !(0..=9).contains(&digit) {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
sum += digit;
|
sum += digit;
|
||||||
|
|
||||||
@@ -330,13 +330,13 @@ pub trait UPCEANReader: OneDReader {
|
|||||||
let mut i = length as isize - 2;
|
let mut i = length as isize - 2;
|
||||||
while i >= 0 {
|
while i >= 0 {
|
||||||
// for (int i = length - 2; i >= 0; i -= 2) {
|
// for (int i = length - 2; i >= 0; i -= 2) {
|
||||||
let digit =
|
let digit = (s
|
||||||
(s.chars()
|
.chars()
|
||||||
.nth(i as usize)
|
.nth(i as usize)
|
||||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))? as i32)
|
.ok_or(Exceptions::indexOutOfBoundsEmpty())? as i32)
|
||||||
- ('0' as i32);
|
- ('0' as i32);
|
||||||
if !(0..=9).contains(&digit) {
|
if !(0..=9).contains(&digit) {
|
||||||
return Err(Exceptions::FormatException(None));
|
return Err(Exceptions::formatEmpty());
|
||||||
}
|
}
|
||||||
sum += digit;
|
sum += digit;
|
||||||
|
|
||||||
@@ -423,7 +423,7 @@ pub trait UPCEANReader: OneDReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -460,7 +460,7 @@ pub trait UPCEANReader: OneDReader {
|
|||||||
if bestMatch >= 0 {
|
if bestMatch >= 0 {
|
||||||
Ok(bestMatch as usize)
|
Ok(bestMatch as usize)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::NotFoundException(None))
|
Err(Exceptions::notFoundEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ impl BoundingBox {
|
|||||||
let leftUnspecified = topLeft.is_none() || bottomLeft.is_none();
|
let leftUnspecified = topLeft.is_none() || bottomLeft.is_none();
|
||||||
let rightUnspecified = topRight.is_none() || bottomRight.is_none();
|
let rightUnspecified = topRight.is_none() || bottomRight.is_none();
|
||||||
if leftUnspecified && rightUnspecified {
|
if leftUnspecified && rightUnspecified {
|
||||||
return Err(Exceptions::NotFoundException(None));
|
return Err(Exceptions::notFoundEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let newTopLeft;
|
let newTopLeft;
|
||||||
@@ -53,21 +53,21 @@ impl BoundingBox {
|
|||||||
let newBottomRight;
|
let newBottomRight;
|
||||||
|
|
||||||
if leftUnspecified {
|
if leftUnspecified {
|
||||||
newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?;
|
newTopRight = topRight.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?;
|
newBottomRight = bottomRight.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
newTopLeft = RXingResultPoint::new(0.0, newTopRight.getY());
|
newTopLeft = RXingResultPoint::new(0.0, newTopRight.getY());
|
||||||
newBottomLeft = RXingResultPoint::new(0.0, newBottomRight.getY());
|
newBottomLeft = RXingResultPoint::new(0.0, newBottomRight.getY());
|
||||||
} else if rightUnspecified {
|
} else if rightUnspecified {
|
||||||
newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?;
|
newTopLeft = topLeft.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
newBottomLeft = bottomLeft.ok_or(Exceptions::IllegalStateException(None))?;
|
newBottomLeft = bottomLeft.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
newTopRight = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newTopLeft.getY());
|
newTopRight = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newTopLeft.getY());
|
||||||
newBottomRight =
|
newBottomRight =
|
||||||
RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY());
|
RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY());
|
||||||
} else {
|
} else {
|
||||||
newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?;
|
newTopLeft = topLeft.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?;
|
newTopRight = topRight.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
newBottomLeft = bottomLeft.ok_or(Exceptions::IllegalStateException(None))?;
|
newBottomLeft = bottomLeft.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?;
|
newBottomRight = bottomRight.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(BoundingBox {
|
Ok(BoundingBox {
|
||||||
@@ -104,17 +104,17 @@ impl BoundingBox {
|
|||||||
if leftBox.is_none() {
|
if leftBox.is_none() {
|
||||||
return Ok(rightBox
|
return Ok(rightBox
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.clone());
|
.clone());
|
||||||
}
|
}
|
||||||
if rightBox.is_none() {
|
if rightBox.is_none() {
|
||||||
return Ok(leftBox
|
return Ok(leftBox
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or(Exceptions::IllegalStateException(None))?
|
.ok_or(Exceptions::illegalStateEmpty())?
|
||||||
.clone());
|
.clone());
|
||||||
}
|
}
|
||||||
let leftBox = leftBox.ok_or(Exceptions::IllegalStateException(None))?;
|
let leftBox = leftBox.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
let rightBox = rightBox.ok_or(Exceptions::IllegalStateException(None))?;
|
let rightBox = rightBox.ok_or(Exceptions::illegalStateEmpty())?;
|
||||||
|
|
||||||
BoundingBox::new(
|
BoundingBox::new(
|
||||||
leftBox.image,
|
leftBox.image,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user