From d98c5ca59666f857903b06371cd072c30adbb7f7 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Thu, 4 Jan 2024 11:23:23 -0600 Subject: [PATCH] fix: remove unecessary arrayContains function frome coda_bar_reader and writer --- src/oned/coda_bar_reader.rs | 18 ++++-------------- src/oned/coda_bar_writer.rs | 13 +++++-------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/oned/coda_bar_reader.rs b/src/oned/coda_bar_reader.rs index 4e24e7b..886603d 100644 --- a/src/oned/coda_bar_reader.rs +++ b/src/oned/coda_bar_reader.rs @@ -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; diff --git a/src/oned/coda_bar_writer.rs b/src/oned/coda_bar_writer.rs index d67de79..64764a9 100644 --- a/src/oned/coda_bar_writer.rs +++ b/src/oned/coda_bar_writer.rs @@ -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!(