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

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