remove .to_owned() calls on &str in exceptions

This commit is contained in:
Vukašin Stepanović
2023-02-15 11:03:27 +00:00
parent 722ce78fd0
commit 528ddea41c
47 changed files with 107 additions and 167 deletions

View File

@@ -170,11 +170,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
decoded_bytes.clear();
match n {
0 => result.push(29 as char), // translate FNC1 as ASCII 29
7 => {
return Err(Exceptions::format(
"FLG(7) is reserved and illegal".to_owned(),
))
} // FLG(7) is reserved and illegal
7 => return Err(Exceptions::format("FLG(7) is reserved and illegal")), // FLG(7) is reserved and illegal
_ => {
// ECI is decimal integer encoded as 1-6 codes in DIGIT mode
let mut eci = 0;
@@ -186,7 +182,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
let next_digit = read_code(corrected_bits, index, 4);
index += 4;
if !(2..=11).contains(&next_digit) {
return Err(Exceptions::format("Not a decimal digit".to_owned()));
return Err(Exceptions::format("Not a decimal digit"));
// Not a decimal digit
}
eci = eci * 10 + (next_digit - 2);
@@ -194,7 +190,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
}
let charset_eci = CharacterSetECI::getCharacterSetECIByValue(eci);
if charset_eci.is_err() {
return Err(Exceptions::format("Charset must exist".to_owned()));
return Err(Exceptions::format("Charset must exist"));
}
encdr = CharacterSetECI::getCharset(&charset_eci?);
}
@@ -238,7 +234,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
if let Ok(str) = encdr.decode(&decoded_bytes, encoding::DecoderTrap::Strict) {
result.push_str(&str);
} else {
return Err(Exceptions::illegalState("bad encoding".to_owned()));
return Err(Exceptions::illegalState("bad encoding"));
}
// result.push_str(decodedBytes.toString(encoding.name()));
//} catch (UnsupportedEncodingException uee) {
@@ -290,7 +286,7 @@ fn get_character(table: Table, code: u32) -> Result<&'static str, Exceptions> {
Table::Mixed => Ok(MIXED_TABLE[code as usize]),
Table::Digit => Ok(DIGIT_TABLE[code as usize]),
Table::Punct => Ok(PUNCT_TABLE[code as usize]),
_ => Err(Exceptions::illegalState("Bad table".to_owned())),
_ => Err(Exceptions::illegalState("Bad table")),
}
// switch (table) {
// case UPPER:

View File

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

View File

@@ -188,13 +188,13 @@ pub fn encode_bytes_with_charset(
stuffed_bits = stuffBits(&bits, word_size as usize)?;
if stuffed_bits.getSize() as u32 + ecc_bits > usable_bits_in_layers {
return Err(Exceptions::illegalArgument(
"Data to large for user specified layer".to_owned(),
"Data to large for user specified layer",
));
}
if compact && stuffed_bits.getSize() as u32 > word_size * 64 {
// Compact format only allows 64 data words, though C4 can hold more words than that
return Err(Exceptions::illegalArgument(
"Data to large for user specified layer".to_owned(),
"Data to large for user specified layer",
));
}
} else {
@@ -208,7 +208,7 @@ pub fn encode_bytes_with_charset(
// for (int i = 0; ; i++) {
if i > MAX_NB_BITS {
return Err(Exceptions::illegalArgument(
"Data too large for an Aztec code".to_owned(),
"Data too large for an Aztec code",
));
}
compact = i <= 3;

View File

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

View File

@@ -81,7 +81,7 @@ impl State {
} else */
if eci > 999999 {
return Err(Exceptions::illegalArgument(
"ECI code must be between 0 and 999999".to_owned(),
"ECI code must be between 0 and 999999",
));
// throw new IllegalArgumentException("ECI code must be between 0 and 999999");
} else {

View File

@@ -121,17 +121,17 @@ impl AddressBookParsedRXingResult {
) -> Result<Self, Exceptions> {
if phone_numbers.len() != phone_types.len() && !phone_types.is_empty() {
return Err(Exceptions::illegalArgument(
"Phone numbers and types lengths differ".to_owned(),
"Phone numbers and types lengths differ",
));
}
if emails.len() != email_types.len() && !email_types.is_empty() {
return Err(Exceptions::illegalArgument(
"Emails and types lengths differ".to_owned(),
"Emails and types lengths differ",
));
}
if addresses.len() != address_types.len() && !address_types.is_empty() {
return Err(Exceptions::illegalArgument(
"Addresses and types lengths differ".to_owned(),
"Addresses and types lengths differ",
));
}
Ok(Self {

View File

@@ -91,9 +91,7 @@ fn vin_char_value(c: char) -> Result<u32, Exceptions> {
'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),
'0'..='9' => Ok(c as u8 as u32 - b'0' as u32),
_ => Err(Exceptions::illegalArgument(
"vin char out of range".to_owned(),
)),
_ => Err(Exceptions::illegalArgument("vin char out of range")),
}
}
@@ -104,7 +102,7 @@ fn vin_position_weight(position: usize) -> Result<usize, Exceptions> {
9 => Ok(0),
10..=17 => Ok(19 - position),
_ => Err(Exceptions::illegalArgument(
"vin position weight out of bounds".to_owned(),
"vin position weight out of bounds",
)),
}
}
@@ -113,7 +111,7 @@ fn check_char(remainder: u8) -> Result<char, Exceptions> {
match remainder {
0..=9 => Ok((b'0' + remainder) as char),
10 => Ok('X'),
_ => Err(Exceptions::illegalArgument("remainder too high".to_owned())),
_ => Err(Exceptions::illegalArgument("remainder too high")),
}
}

View File

@@ -254,7 +254,7 @@ impl BitArray {
pub fn appendBits(&mut self, value: u32, num_bits: usize) -> Result<(), Exceptions> {
if num_bits > 32 {
return Err(Exceptions::illegalArgument(
"num bits must be between 0 and 32".to_owned(),
"num bits must be between 0 and 32",
));
}
@@ -286,7 +286,7 @@ impl BitArray {
pub fn xor(&mut self, other: &BitArray) -> Result<(), Exceptions> {
if self.size != other.size {
return Err(Exceptions::illegalArgument("Sizes don't match".to_owned()));
return Err(Exceptions::illegalArgument("Sizes don't match"));
}
for i in 0..self.bits.len() {
//for (int i = 0; i < bits.length; i++) {

View File

@@ -66,7 +66,7 @@ impl BitMatrix {
pub fn new(width: u32, height: u32) -> Result<Self, Exceptions> {
if width < 1 || height < 1 {
return Err(Exceptions::illegalArgument(
"Both dimensions must be greater than 0".to_owned(),
"Both dimensions must be greater than 0",
));
}
Ok(Self {
@@ -151,9 +151,7 @@ impl BitMatrix {
first_run = false;
rowLength = bitsPos - rowStartPos;
} else if bitsPos - rowStartPos != rowLength {
return Err(Exceptions::illegalArgument(
"row lengths do not match".to_owned(),
));
return Err(Exceptions::illegalArgument("row lengths do not match"));
}
rowStartPos = bitsPos;
nRows += 1;
@@ -182,9 +180,7 @@ impl BitMatrix {
// first_run = false;
rowLength = bitsPos - rowStartPos;
} else if bitsPos - rowStartPos != rowLength {
return Err(Exceptions::illegalArgument(
"row lengths do not match".to_owned(),
));
return Err(Exceptions::illegalArgument("row lengths do not match"));
}
nRows += 1;
}
@@ -312,7 +308,7 @@ impl BitMatrix {
if self.width != mask.width || self.height != mask.height || self.row_size != mask.row_size
{
return Err(Exceptions::illegalArgument(
"input matrix dimensions do not match".to_owned(),
"input matrix dimensions do not match",
));
}
// let mut rowArray = BitArray::with_size(self.width as usize);
@@ -364,14 +360,14 @@ impl BitMatrix {
// }
if height < 1 || width < 1 {
return Err(Exceptions::illegalArgument(
"height and width must be at least 1".to_owned(),
"height and width must be at least 1",
));
}
let right = left + width;
let bottom = top + height;
if bottom > self.height || right > self.width {
return Err(Exceptions::illegalArgument(
"the region must fit inside the matrix".to_owned(),
"the region must fit inside the matrix",
));
}
for y in top..bottom {
@@ -445,7 +441,7 @@ impl BitMatrix {
Ok(())
}
_ => 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",
)),
}
}

View File

@@ -244,7 +244,7 @@ impl CharacterSetECI {
28 => Ok(CharacterSetECI::Big5),
29 => Ok(CharacterSetECI::GB18030),
30 => Ok(CharacterSetECI::EUC_KR),
_ => Err(Exceptions::notFound("Bad ECI Value".to_owned())),
_ => Err(Exceptions::notFound("Bad ECI Value")),
}
}

View File

@@ -99,7 +99,7 @@ impl GridSampler for DefaultGridSampler {
if image
.try_get(points[x] as u32, points[x + 1] as u32)
.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",
))?
{
// Black(-ish) pixel

View File

@@ -234,7 +234,7 @@ impl GlobalHistogramBinarizer {
// than waste time trying to decode the image, and risk false positives.
if secondPeak - firstPeak <= numBuckets / 16 {
return Err(Exceptions::notFound(
"secondPeak - firstPeak <= numBuckets / 16 ".to_owned(),
"secondPeak - firstPeak <= numBuckets / 16 ",
));
}

View File

@@ -141,7 +141,7 @@ impl GenericGFPoly {
pub fn addOrSubtract(&self, other: &GenericGFPoly) -> Result<GenericGFPoly, Exceptions> {
if self.field != other.field {
return Err(Exceptions::illegalArgument(
"GenericGFPolys do not have same GenericGF field".to_owned(),
"GenericGFPolys do not have same GenericGF field",
));
}
if self.isZero() {
@@ -178,7 +178,7 @@ impl GenericGFPoly {
if self.field != other.field {
//if (!field.equals(other.field)) {
return Err(Exceptions::illegalArgument(
"GenericGFPolys do not have same GenericGF field".to_owned(),
"GenericGFPolys do not have same GenericGF field",
));
}
if self.isZero() || other.isZero() {
@@ -253,11 +253,11 @@ impl GenericGFPoly {
) -> Result<(GenericGFPoly, GenericGFPoly), Exceptions> {
if self.field != other.field {
return Err(Exceptions::illegalArgument(
"GenericGFPolys do not have same GenericGF field".to_owned(),
"GenericGFPolys do not have same GenericGF field",
));
}
if other.isZero() {
return Err(Exceptions::illegalArgument("Divide by 0".to_owned()));
return Err(Exceptions::illegalArgument("Divide by 0"));
}
let mut quotient = self.getZero();
@@ -266,7 +266,7 @@ impl GenericGFPoly {
let denominator_leading_term = other.getCoefficient(other.getDegree());
let inverse_denominator_leading_term = match self.field.inverse(denominator_leading_term) {
Ok(val) => val,
Err(_issue) => return Err(Exceptions::illegalArgument("arithmetic issue".to_owned())),
Err(_issue) => return Err(Exceptions::illegalArgument("arithmetic issue")),
};
while remainder.getDegree() >= other.getDegree() && !remainder.isZero() {

View File

@@ -92,11 +92,11 @@ impl ReedSolomonDecoder {
//for (int i = 0; i < errorLocations.length; i++) {
let log_value = self.field.log(errorLocations[i] as i32)?;
if log_value > received.len() as i32 - 1 {
return Err(Exceptions::reedSolomon("Bad error location".to_owned()));
return Err(Exceptions::reedSolomon("Bad error location"));
}
let position: isize = received.len() as isize - 1 - log_value as isize;
if position < 0 {
return Err(Exceptions::reedSolomon("Bad error location".to_owned()));
return Err(Exceptions::reedSolomon("Bad error location"));
}
received[position as usize] =
GenericGF::addOrSubtract(received[position as usize], errorMagnitudes[i]);
@@ -134,7 +134,7 @@ impl ReedSolomonDecoder {
// Divide rLastLast by rLast, with quotient in q and remainder in r
if rLast.isZero() {
// Oops, Euclidean algorithm already terminated?
return Err(Exceptions::reedSolomon("r_{i-1} was zero".to_owned()));
return Err(Exceptions::reedSolomon("r_{i-1} was zero"));
}
r = rLastLast;
let mut q = r.getZero();
@@ -160,12 +160,12 @@ impl ReedSolomonDecoder {
let sigmaTildeAtZero = t.getCoefficient(0);
if sigmaTildeAtZero == 0 {
return Err(Exceptions::reedSolomon("sigmaTilde(0) was zero".to_owned()));
return Err(Exceptions::reedSolomon("sigmaTilde(0) was zero"));
}
let inverse = match self.field.inverse(sigmaTildeAtZero) {
Ok(res) => res,
Err(_err) => return Err(Exceptions::reedSolomon("ArithmetricException".to_owned())),
Err(_err) => return Err(Exceptions::reedSolomon("ArithmetricException")),
};
let sigma = t.multiply_with_scalar(inverse);
let omega = r.multiply_with_scalar(inverse);
@@ -194,7 +194,7 @@ impl ReedSolomonDecoder {
}
if e != numErrors {
return Err(Exceptions::reedSolomon(
"Error locator degree does not match number of roots".to_owned(),
"Error locator degree does not match number of roots",
));
}
Ok(result)

View File

@@ -73,15 +73,11 @@ impl ReedSolomonEncoder {
pub fn encode(&mut self, to_encode: &mut Vec<i32>, ec_bytes: usize) -> Result<(), Exceptions> {
if ec_bytes == 0 {
return Err(Exceptions::illegalArgument(
"No error correction bytes".to_owned(),
));
return Err(Exceptions::illegalArgument("No error correction bytes"));
}
let data_bytes = to_encode.len() - ec_bytes;
if data_bytes == 0 {
return Err(Exceptions::illegalArgument(
"No data bytes provided".to_owned(),
));
return Err(Exceptions::illegalArgument("No data bytes provided"));
}
let fld = self.field;
let generator = self.buildGenerator(ec_bytes);

View File

@@ -60,9 +60,7 @@ impl Writer for DataMatrixWriter {
hints: &crate::EncodingHintDictionary,
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
if contents.is_empty() {
return Err(Exceptions::illegalArgument(
"Found empty contents".to_owned(),
));
return Err(Exceptions::illegalArgument("Found empty contents"));
}
if format != &BarcodeFormat::DATA_MATRIX {
@@ -123,7 +121,7 @@ impl Writer for DataMatrixWriter {
if hasEncodingHint {
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
hints.get(&EncodeHintType::CHARACTER_SET) else {
return Err(Exceptions::illegalArgument("charset does not exist".to_owned()))
return Err(Exceptions::illegalArgument("charset does not exist"))
};
charset = encoding::label::encoding_from_whatwg_label(char_set_name);
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
@@ -157,7 +155,7 @@ impl Writer for DataMatrixWriter {
let symbol_lookup = SymbolInfoLookup::new();
let Some(symbolInfo) = symbol_lookup.lookup_with_codewords_shape_size_fail(encoded.chars().count() as u32, *shape, &minSize, &maxSize, true)? else {
return Err(Exceptions::notFound("symbol info is bad".to_owned()))
return Err(Exceptions::notFound("symbol info is bad"))
};
//2. step: ECC generation

View File

@@ -457,7 +457,7 @@ impl BitMatrixParser {
if bitMatrix.getHeight() != symbolSizeRows {
return Err(Exceptions::illegalArgument(
"Dimension of bitMatrix must match the version size".to_owned(),
"Dimension of bitMatrix must match the version size",
));
}

View File

@@ -279,7 +279,7 @@ fn decodeAsciiSegment(
// Must be first ISO 16022:2006 5.6.1
{
return Err(Exceptions::format(
"structured append tag must be first code word".to_owned(),
"structured append tag must be first code word",
));
}
parse_structured_append(bits, &mut sai)?;

View File

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

View File

@@ -234,9 +234,7 @@ impl C40Encoder {
context.writeCodeword(C40_UNLATCH);
}
} else {
return Err(Exceptions::illegalState(
"Unexpected case. Please report!".to_owned(),
));
return Err(Exceptions::illegalState("Unexpected case. Please report!"));
}
context.signalEncoderChange(ASCII_ENCODATION);

View File

@@ -95,9 +95,7 @@ impl EdifactEncoder {
}
if count > 4 {
return Err(Exceptions::illegalState(
"Count must not exceed 4".to_owned(),
));
return Err(Exceptions::illegalState("Count must not exceed 4"));
}
let restChars = count - 1;
let encoded = Self::encodeToCodewords(buffer)?;
@@ -149,9 +147,7 @@ impl EdifactEncoder {
fn encodeToCodewords(sb: &str) -> Result<String, Exceptions> {
let len = sb.chars().count();
if len == 0 {
return Err(Exceptions::illegalState(
"StringBuilder must not be empty".to_owned(),
));
return Err(Exceptions::illegalState("StringBuilder must not be empty"));
}
let c1 = sb
.chars()

View File

@@ -67,7 +67,7 @@ impl<'a> EncoderContext<'_> {
})?
} else {
return Err(Exceptions::illegalArgument(
"Message contains characters outside ISO-8859-1 encoding.".to_owned(),
"Message contains characters outside ISO-8859-1 encoding.",
));
};
Ok(Self {

View File

@@ -155,7 +155,7 @@ const ALOG: [u32; 255] = {
pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String, Exceptions> {
if codewords.chars().count() != symbolInfo.getDataCapacity() as usize {
return Err(Exceptions::illegalArgument(
"The number of codewords does not match the selected symbol".to_owned(),
"The number of codewords does not match the selected symbol",
));
}
let mut sb = String::with_capacity(

View File

@@ -129,7 +129,7 @@ impl SymbolInfo {
16 => Ok(4),
36 => Ok(6),
_ => Err(Exceptions::illegalState(
"Cannot handle this number of data regions".to_owned(),
"Cannot handle this number of data regions",
)),
}
}
@@ -141,7 +141,7 @@ impl SymbolInfo {
16 => Ok(4),
36 => Ok(6),
_ => Err(Exceptions::illegalState(
"Cannot handle this number of data regions".to_owned(),
"Cannot handle this number of data regions",
)),
}
}

View File

@@ -35,20 +35,16 @@ pub fn detect_in_svg_with_hints(
let path = PathBuf::from(file_name);
if !path.exists() {
return Err(Exceptions::illegalArgument(
"file does not exist".to_owned(),
));
return Err(Exceptions::illegalArgument("file does not exist"));
}
let Ok(mut file) = File::open(path) else {
return Err(Exceptions::illegalArgument("file cannot be opened".to_owned()));
return Err(Exceptions::illegalArgument("file cannot be opened"));
};
let mut svg_data = Vec::new();
if file.read_to_end(&mut svg_data).is_err() {
return Err(Exceptions::illegalArgument(
"file cannot be read".to_owned(),
));
return Err(Exceptions::illegalArgument("file cannot be read"));
}
let mut multi_format_reader = MultiFormatReader::default();
@@ -88,20 +84,16 @@ pub fn detect_multiple_in_svg_with_hints(
let path = PathBuf::from(file_name);
if !path.exists() {
return Err(Exceptions::illegalArgument(
"file does not exist".to_owned(),
));
return Err(Exceptions::illegalArgument("file does not exist"));
}
let Ok(mut file) = File::open(path) else {
return Err(Exceptions::illegalArgument("file cannot be opened".to_owned()));
return Err(Exceptions::illegalArgument("file cannot be opened"));
};
let mut svg_data = Vec::new();
if file.read_to_end(&mut svg_data).is_err() {
return Err(Exceptions::illegalArgument(
"file cannot be read".to_owned(),
));
return Err(Exceptions::illegalArgument("file cannot be read"));
}
let multi_format_reader = MultiFormatReader::default();

View File

@@ -96,7 +96,7 @@ impl LuminanceSource for Luma8LuminanceSource {
fn rotateCounterClockwise45(&self) -> Result<Box<dyn LuminanceSource>, crate::Exceptions> {
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.",
))
}
}

View File

@@ -92,7 +92,7 @@ pub trait LuminanceSource {
_height: usize,
) -> Result<Box<dyn LuminanceSource>, Exceptions> {
Err(Exceptions::unsupportedOperation(
"This luminance source does not support cropping.".to_owned(),
"This luminance source does not support cropping.",
))
}
@@ -119,7 +119,7 @@ pub trait LuminanceSource {
*/
fn rotateCounterClockwise(&self) -> Result<Box<dyn LuminanceSource>, Exceptions> {
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.",
))
}
@@ -131,7 +131,7 @@ pub trait LuminanceSource {
*/
fn rotateCounterClockwise45(&self) -> Result<Box<dyn LuminanceSource>, Exceptions> {
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.",
))
}

View File

@@ -93,9 +93,7 @@ impl<'a> MultiFinderPatternFinder<'_> {
if size < 3 {
// Couldn't find enough finder patterns
return Err(Exceptions::notFound(
"Couldn't find enough finder patterns".to_owned(),
));
return Err(Exceptions::notFound("Couldn't find enough finder patterns"));
}
/*

View File

@@ -249,7 +249,7 @@ fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>, Exception
if position + 1 == length {
// this is the last character, but the encoding is C, which always encodes two characers
return Err(Exceptions::illegalArgument(
"Bad number of characters for digit only encoding.".to_owned(),
"Bad number of characters for digit only encoding.",
));
}
let s: String = contents

View File

@@ -45,9 +45,7 @@ impl OneDimensionalCodeWriter for EAN13Writer {
}
13 => {
if !reader.checkStandardUPCEANChecksum(&contents)? {
return Err(Exceptions::illegalArgument(
"Contents do not pass checksum".to_owned(),
));
return Err(Exceptions::illegalArgument("Contents do not pass checksum"));
}
}
_ => {

View File

@@ -55,9 +55,7 @@ impl OneDimensionalCodeWriter for EAN8Writer {
}
8 => {
if !EAN8Reader.checkStandardUPCEANChecksum(&contents)? {
return Err(Exceptions::illegalArgument(
"Contents do not pass checksum".to_owned(),
));
return Err(Exceptions::illegalArgument("Contents do not pass checksum"));
}
}
_ => {

View File

@@ -33,7 +33,7 @@ impl OneDimensionalCodeWriter for ITFWriter {
let length = contents.chars().count();
if length % 2 != 0 {
return Err(Exceptions::illegalArgument(
"The length of the input should be even".to_owned(),
"The length of the input should be even",
));
}
if length > 80 {

View File

@@ -101,7 +101,7 @@ pub trait OneDimensionalCodeWriter: Writer {
fn checkNumeric(contents: &str) -> Result<(), Exceptions> {
if !NUMERIC.is_match(contents) {
Err(Exceptions::illegalArgument(
"Input should only contain digits 0-9".to_owned(),
"Input should only contain digits 0-9",
))
} else {
Ok(())
@@ -163,9 +163,7 @@ impl Writer for L {
hints: &crate::EncodingHintDictionary,
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
if contents.is_empty() {
return Err(Exceptions::illegalArgument(
"Found empty contents".to_owned(),
));
return Err(Exceptions::illegalArgument("Found empty contents"));
}
if width < 0 || height < 0 {

View File

@@ -51,7 +51,7 @@ pub fn buildBitArrayFromString(data: &str) -> Result<BitArray, Exceptions> {
if i % 9 == 0 {
// spaces
if dotsAndXs.chars().nth(i).ok_or(Exceptions::parseEmpty())? != ' ' {
return Err(Exceptions::illegalState("space expected".to_owned()));
return Err(Exceptions::illegalState("space expected"));
}
continue;
}

View File

@@ -55,9 +55,7 @@ impl OneDimensionalCodeWriter for UPCEWriter {
&upc_e_reader::convertUPCEtoUPCA(&contents)
.ok_or(Exceptions::illegalArgumentEmpty())?,
)? {
return Err(Exceptions::illegalArgument(
"Contents do not pass checksum".to_owned(),
));
return Err(Exceptions::illegalArgument("Contents do not pass checksum"));
}
}
_ => {
@@ -76,9 +74,7 @@ impl OneDimensionalCodeWriter for UPCEWriter {
.to_digit(10)
.ok_or(Exceptions::parseEmpty())? as usize; //Character.digit(contents.charAt(0), 10);
if firstDigit != 0 && firstDigit != 1 {
return Err(Exceptions::illegalArgument(
"Number system must be 0 or 1".to_owned(),
));
return Err(Exceptions::illegalArgument("Number system must be 0 or 1"));
}
let checkDigit = contents

View File

@@ -127,7 +127,7 @@ impl ModulusPoly {
pub fn add(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>, Exceptions> {
if self.field != other.field {
return Err(Exceptions::illegalArgument(
"ModulusPolys do not have same ModulusGF field".to_owned(),
"ModulusPolys do not have same ModulusGF field",
));
}
if self.isZero() {
@@ -161,7 +161,7 @@ impl ModulusPoly {
pub fn subtract(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>, Exceptions> {
if self.field != other.field {
return Err(Exceptions::illegalArgument(
"ModulusPolys do not have same ModulusGF field".to_owned(),
"ModulusPolys do not have same ModulusGF field",
));
}
if other.isZero() {
@@ -173,7 +173,7 @@ impl ModulusPoly {
pub fn multiply(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>, Exceptions> {
if !(self.field == other.field) {
return Err(Exceptions::illegalArgument(
"ModulusPolys do not have same ModulusGF field".to_owned(),
"ModulusPolys do not have same ModulusGF field",
));
}
if self.isZero() || other.isZero() {

View File

@@ -315,9 +315,7 @@ impl PDF417 {
}
}
dimension.ok_or(Exceptions::writer(
"Unable to fit message in columns".to_owned(),
))
dimension.ok_or(Exceptions::writer("Unable to fit message in columns"))
}
/**

View File

@@ -120,7 +120,7 @@ static EC_COEFFICIENTS: Lazy<[Vec<u32>; 9]> = Lazy::new(|| {
pub fn getErrorCorrectionCodewordCount(errorCorrectionLevel: u32) -> Result<u32, Exceptions> {
if errorCorrectionLevel > 8 {
return Err(Exceptions::illegalArgument(
"Error correction level must be between 0 and 8!".to_owned(),
"Error correction level must be between 0 and 8!",
));
}
Ok(1 << (errorCorrectionLevel + 1))
@@ -135,7 +135,7 @@ pub fn getErrorCorrectionCodewordCount(errorCorrectionLevel: u32) -> Result<u32,
*/
pub fn getRecommendedMinimumErrorCorrectionLevel(n: u32) -> Result<u32, Exceptions> {
if n == 0 {
Err(Exceptions::illegalArgument("n must be > 0".to_owned()))
Err(Exceptions::illegalArgument("n must be > 0"))
} else if n <= 40 {
Ok(2)
} else if n <= 160 {
@@ -145,7 +145,7 @@ pub fn getRecommendedMinimumErrorCorrectionLevel(n: u32) -> Result<u32, Exceptio
} else if n <= 863 {
Ok(5)
} else {
Err(Exceptions::writer("No recommendation possible".to_owned()))
Err(Exceptions::writer("No recommendation possible"))
}
}

View File

@@ -179,7 +179,7 @@ pub fn encodeHighLevel(
) -> Result<String, Exceptions> {
let mut encoding = encoding;
if msg.is_empty() {
return Err(Exceptions::writer("Empty message not allowed".to_owned()));
return Err(Exceptions::writer("Empty message not allowed"));
}
if encoding.is_none() && !autoECI {
@@ -797,9 +797,7 @@ fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
if !can_encode {
if TypeId::of::<T>() != TypeId::of::<NoECIInput>() {
return Err(Exceptions::illegalState(
"expected NoECIInput type".to_owned(),
));
return Err(Exceptions::illegalState("expected NoECIInput type"));
}
let ch = input.charAt(idx)?;
return Err(Exceptions::writer(format!(

View File

@@ -167,7 +167,7 @@ impl PlanarYUVLuminanceSource {
) -> Result<Self, Exceptions> {
if left + width > data_width || top + height > data_height {
return Err(Exceptions::illegalArgument(
"Crop rectangle does not fit within image data.".to_owned(),
"Crop rectangle does not fit within image data.",
));
}

View File

@@ -101,16 +101,14 @@ impl Version {
dimension: u32,
) -> Result<&'static Version, Exceptions> {
if dimension % 4 != 1 {
return Err(Exceptions::format("dimension incorrect".to_owned()));
return Err(Exceptions::format("dimension incorrect"));
}
Self::getVersionForNumber((dimension - 17) / 4)
}
pub fn getVersionForNumber(versionNumber: u32) -> Result<&'static Version, Exceptions> {
if !(1..=40).contains(&versionNumber) {
return Err(Exceptions::illegalArgument(
"version out of spec".to_owned(),
));
return Err(Exceptions::illegalArgument("version out of spec"));
}
Ok(&VERSIONS[versionNumber as usize - 1])
}

View File

@@ -323,7 +323,7 @@ pub fn findMSBSet(value: u32) -> u32 {
// operations. We don't care if coefficients are positive or negative.
pub fn calculateBCHCode(value: u32, poly: u32) -> Result<u32, Exceptions> {
if poly == 0 {
return Err(Exceptions::illegalArgument("0 polynomial".to_owned()));
return Err(Exceptions::illegalArgument("0 polynomial"));
}
let mut value = value;
// If poly is "1 1111 0010 0101" (version info poly), msbSetInPoly is 13. We'll subtract 1
@@ -347,7 +347,7 @@ pub fn makeTypeInfoBits(
bits: &mut BitArray,
) -> Result<(), Exceptions> {
if !QRCode::isValidMaskPattern(maskPattern as i32) {
return Err(Exceptions::writer("Invalid mask pattern".to_owned()));
return Err(Exceptions::writer("Invalid mask pattern"));
}
let typeInfo = (ecLevel.get_value() << 3) as u32 | maskPattern;
bits.appendBits(typeInfo, 5)?;

View File

@@ -186,9 +186,7 @@ impl MinimalEncoder {
}
}
if smallestRXingResult < 0 {
return Err(Exceptions::writer(
"Data too big for any version".to_owned(),
));
return Err(Exceptions::writer("Data too big for any version"));
}
Ok(results[smallestRXingResult as usize].clone())
}

View File

@@ -180,9 +180,7 @@ pub fn encode_with_hints(
version = Version::getVersionForNumber(versionNumber)?;
let bitsNeeded = calculateBitsNeeded(mode, &header_bits, &data_bits, version);
if !willFit(bitsNeeded, version, &ec_level) {
return Err(Exceptions::writer(
"Data too big for requested version".to_owned(),
));
return Err(Exceptions::writer("Data too big for requested version"));
}
} else {
version = recommendVersion(&ec_level, mode, &header_bits, &data_bits)?;
@@ -446,9 +444,7 @@ pub fn terminateBits(num_data_bytes: u32, bits: &mut BitArray) -> Result<(), Exc
bits.appendBits(if (i & 0x01) == 0 { 0xEC } else { 0x11 }, 8)?;
}
if bits.getSize() != capacity as usize {
return Err(Exceptions::writer(
"Bits size does not equal capacity".to_owned(),
));
return Err(Exceptions::writer("Bits size does not equal capacity"));
}
Ok(())
}
@@ -467,7 +463,7 @@ pub fn getNumDataBytesAndNumECBytesForBlockID(
// numECBytesInBlock: &mut [u32],
) -> Result<(u32, u32), Exceptions> {
if block_id >= num_rsblocks {
return Err(Exceptions::writer("Block ID too large".to_owned()));
return Err(Exceptions::writer("Block ID too large"));
}
// numRsBlocksInGroup2 = 196 % 5 = 1
let num_rs_blocks_in_group2 = num_total_bytes % num_rsblocks;
@@ -488,18 +484,18 @@ pub fn getNumDataBytesAndNumECBytesForBlockID(
// Sanity checks.
// 26 = 26
if num_ec_bytes_in_group1 != numEcBytesInGroup2 {
return Err(Exceptions::writer("EC bytes mismatch".to_owned()));
return Err(Exceptions::writer("EC bytes mismatch"));
}
// 5 = 4 + 1.
if num_rsblocks != num_rs_blocks_in_group1 + num_rs_blocks_in_group2 {
return Err(Exceptions::writer("RS blocks mismatch".to_owned()));
return Err(Exceptions::writer("RS blocks mismatch"));
}
// 196 = (13 + 26) * 4 + (14 + 26) * 1
if num_total_bytes
!= ((num_data_bytes_in_group1 + num_ec_bytes_in_group1) * num_rs_blocks_in_group1)
+ ((num_data_bytes_in_group2 + numEcBytesInGroup2) * num_rs_blocks_in_group2)
{
return Err(Exceptions::writer("total bytes mismatch".to_owned()));
return Err(Exceptions::writer("total bytes mismatch"));
}
Ok(if block_id < num_rs_blocks_in_group1 {
@@ -522,7 +518,7 @@ pub fn interleaveWithECBytes(
// "bits" must have "getNumDataBytes" bytes of data.
if bits.getSizeInBytes() as u32 != num_data_bytes {
return Err(Exceptions::writer(
"Number of bits and data bytes does not match".to_owned(),
"Number of bits and data bytes does not match",
));
}
@@ -556,9 +552,7 @@ pub fn interleaveWithECBytes(
data_bytes_offset += numDataBytesInBlock as usize;
}
if num_data_bytes != data_bytes_offset as u32 {
return Err(Exceptions::writer(
"Data bytes does not match offset".to_owned(),
));
return Err(Exceptions::writer("Data bytes does not match offset"));
}
let mut result = BitArray::new();
@@ -757,7 +751,7 @@ pub fn appendKanjiBytes(content: &str, bits: &mut BitArray) -> Result<(), Except
.encode(content, encoding::EncoderTrap::Strict)
.map_err(|e| Exceptions::writer(format!("error {e}")))?;
if bytes.len() % 2 != 0 {
return Err(Exceptions::writer("Kanji byte size not even".to_owned()));
return Err(Exceptions::writer("Kanji byte size not even"));
}
let max_i = bytes.len() - 1; // bytes.length must be even
let mut i = 0;
@@ -772,7 +766,7 @@ pub fn appendKanjiBytes(content: &str, bits: &mut BitArray) -> Result<(), Except
subtracted = code as i32 - 0xc140;
}
if subtracted == -1 {
return Err(Exceptions::writer("Invalid byte sequence".to_owned()));
return Err(Exceptions::writer("Invalid byte sequence"));
}
let encoded = ((subtracted >> 8) * 0xc0) + (subtracted & 0xff);
bits.appendBits(encoded as u32, 13)?;

View File

@@ -58,9 +58,7 @@ impl Writer for QRCodeWriter {
hints: &crate::EncodingHintDictionary,
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
if contents.is_empty() {
return Err(Exceptions::illegalArgument(
"found empty contents".to_owned(),
));
return Err(Exceptions::illegalArgument("found empty contents"));
}
if format != &BarcodeFormat::QR_CODE {
@@ -110,7 +108,7 @@ impl QRCodeWriter {
) -> Result<BitMatrix, Exceptions> {
let input = code.getMatrix();
if input.is_none() {
return Err(Exceptions::illegalState("matrix is empty".to_owned()));
return Err(Exceptions::illegalState("matrix is empty"));
}
let input = input.as_ref().ok_or(Exceptions::illegalStateEmpty())?;

View File

@@ -180,7 +180,7 @@ impl RGBLuminanceSource {
) -> Result<Self, Exceptions> {
if left + width > data_width || top + height > data_height {
return Err(Exceptions::illegalArgument(
"Crop rectangle does not fit within image data.".to_owned(),
"Crop rectangle does not fit within image data.",
));
}
Ok(Self {

View File

@@ -60,7 +60,7 @@ impl SVGLuminanceSource {
};
let Some(mut pixmap) = resvg::tiny_skia::Pixmap::new(tree.size.width() as u32, tree.size.height() as u32) else {
return Err(Exceptions::format("could not create pixmap".to_owned()));
return Err(Exceptions::format("could not create pixmap"));
};
resvg::render(
@@ -71,11 +71,11 @@ impl SVGLuminanceSource {
);
let Some(buffer) = RgbaImage::from_raw(tree.size.width() as u32, tree.size.height() as u32, pixmap.data().to_vec()) else {
return Err(Exceptions::format("could not create image buffer".to_owned()));
return Err(Exceptions::format("could not create image buffer"));
};
// let Ok(image) = image::load_from_memory_with_format(pixmap.data(), image::ImageFormat::Bmp) else {
// return Err(Exceptions::format("could not generate image".to_owned()));
// return Err(Exceptions::format("could not generate image"));
// };
Ok(Self(BufferedImageLuminanceSource::new(DynamicImage::from(