fix: remove unecessary arrayContains function frome coda_bar_reader and writer

This commit is contained in:
Henry Schimke
2024-01-04 11:23:23 -06:00
parent 501a51f754
commit d98c5ca596
2 changed files with 9 additions and 22 deletions

View File

@@ -75,10 +75,7 @@ impl OneDReader for CodaBarReader {
nextStart += 8;
// Stop as soon as we see the end character.
if self.decodeRowRXingResult.chars().count() > 1
&& Self::arrayContains(
&Self::STARTEND_ENCODING,
Self::ALPHABET[charOffset as usize],
)
&& Self::STARTEND_ENCODING.contains(&Self::ALPHABET[charOffset as usize])
{
break;
}
@@ -124,7 +121,7 @@ impl OneDReader for CodaBarReader {
.chars()
.next()
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?;
if !Self::arrayContains(&Self::STARTEND_ENCODING, startchar) {
if !Self::STARTEND_ENCODING.contains(&startchar) {
return Err(Exceptions::NOT_FOUND);
}
let endchar = self
@@ -132,7 +129,7 @@ impl OneDReader for CodaBarReader {
.chars()
.nth(self.decodeRowRXingResult.chars().count() - 1)
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?;
if !Self::arrayContains(&Self::STARTEND_ENCODING, endchar) {
if !Self::STARTEND_ENCODING.contains(&endchar) {
return Err(Exceptions::NOT_FOUND);
}
@@ -345,10 +342,7 @@ impl CodaBarReader {
// for (int i = 1; i < counterLength; i += 2) {
let charOffset = self.toNarrowWidePattern(i);
if charOffset != -1
&& Self::arrayContains(
&Self::STARTEND_ENCODING,
Self::ALPHABET[charOffset as usize],
)
&& Self::STARTEND_ENCODING.contains(&Self::ALPHABET[charOffset as usize])
{
// Look for whitespace before start pattern, >= 50% of width of start pattern
// We make an exception if the whitespace is the first element.
@@ -366,10 +360,6 @@ impl CodaBarReader {
Err(Exceptions::NOT_FOUND)
}
pub fn arrayContains(array: &[char], key: char) -> bool {
array.contains(&key)
}
// Assumes that counters[position] is a bar.
fn toNarrowWidePattern(&mut self, position: usize) -> i32 {
let end = position + 7;

View File

@@ -51,10 +51,10 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
.nth(contents.chars().count() - 1)
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?
.to_ascii_uppercase();
let startsNormal = CodaBarReader::arrayContains(&START_END_CHARS, firstChar);
let endsNormal = CodaBarReader::arrayContains(&START_END_CHARS, lastChar);
let startsAlt = CodaBarReader::arrayContains(&ALT_START_END_CHARS, firstChar);
let endsAlt = CodaBarReader::arrayContains(&ALT_START_END_CHARS, lastChar);
let startsNormal = START_END_CHARS.contains(&firstChar);
let endsNormal = START_END_CHARS.contains(&lastChar);
let startsAlt = ALT_START_END_CHARS.contains(&firstChar);
let endsAlt = ALT_START_END_CHARS.contains(&lastChar);
if startsNormal {
if !endsNormal {
return Err(Exceptions::illegal_argument_with(format!(
@@ -88,10 +88,7 @@ impl OneDimensionalCodeWriter for CodaBarWriter {
for ch in contents[1..contents.chars().count() - 1].chars() {
if ch.is_ascii_digit() || ch == '-' || ch == '$' {
resultLength += 9;
} else if CodaBarReader::arrayContains(
&CHARS_WHICH_ARE_TEN_LENGTH_EACH_AFTER_DECODED,
ch,
) {
} else if CHARS_WHICH_ARE_TEN_LENGTH_EACH_AFTER_DECODED.contains(&ch) {
resultLength += 10;
} else {
return Err(Exceptions::illegal_argument_with(format!(