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

View File

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