mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
remove .to_owned() calls on &str in exceptions
This commit is contained in:
@@ -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++) {
|
||||
|
||||
@@ -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",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ",
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user