From 9b25b08745709517ed53dcfd2590e0f5779dd64c Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Wed, 2 Nov 2022 10:42:10 -0500 Subject: [PATCH] more minimal encoder functions pass --- src/common/minimal_eci_input.rs | 3 ++- src/datamatrix/encoder/high_level_encode_test_case.rs | 2 +- src/datamatrix/encoder/minimal_encoder.rs | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/minimal_eci_input.rs b/src/common/minimal_eci_input.rs index 175174b..f107166 100644 --- a/src/common/minimal_eci_input.rs +++ b/src/common/minimal_eci_input.rs @@ -312,7 +312,8 @@ impl MinimalECIInput { encoderSet: &ECIEncoderSet, fnc1: Option<&str>, ) -> Vec { - let inputLength = stringToEncode.chars().count(); + // let inputLength = stringToEncode.chars().count(); + let inputLength = stringToEncode.graphemes(true).count(); // Array that represents vertices. There is a vertex for every character and encoding. let mut edges = vec![vec![None; encoderSet.len()]; inputLength + 1]; //InputEdge[inputLength + 1][encoderSet.length()]; diff --git a/src/datamatrix/encoder/high_level_encode_test_case.rs b/src/datamatrix/encoder/high_level_encode_test_case.rs index a3af23d..f908044 100644 --- a/src/datamatrix/encoder/high_level_encode_test_case.rs +++ b/src/datamatrix/encoder/high_level_encode_test_case.rs @@ -557,7 +557,7 @@ fn encodeHighLevel(msg: &str) -> String { fn encodeHighLevelCompare(msg: &str, compareSizeToMinimalEncoder: bool) -> String { let encoded = high_level_encoder::encodeHighLevel(msg).expect("encodes"); let encoded2 = minimal_encoder::encodeHighLevel(msg).expect("encodes"); - assert!(!compareSizeToMinimalEncoder || encoded2.len() <= encoded.len(), "{} <= {}", encoded2.len() , encoded.len()); + assert!(!compareSizeToMinimalEncoder || encoded2.chars().count() <= encoded.chars().count(), "{} <= {}", encoded2.chars().count() , encoded.chars().count()); visualize(&encoded) } diff --git a/src/datamatrix/encoder/minimal_encoder.rs b/src/datamatrix/encoder/minimal_encoder.rs index 99681cc..1c23af1 100755 --- a/src/datamatrix/encoder/minimal_encoder.rs +++ b/src/datamatrix/encoder/minimal_encoder.rs @@ -1017,7 +1017,7 @@ impl Edge { assert!(self.characterLength % 3 == 0); let mut result = vec![0u8; self.characterLength as usize / 3 * 2]; let mut i = 0; - while i <= result.len() { + while i < result.len() { // for (int i = 0; i < result.length; i += 2) { Self::setC40Word( &mut result, @@ -1322,7 +1322,8 @@ impl RXingResult { randomizeLengths.push(size); } if Edge::getPreviousStartMode(current.previous.clone()) != current.getMode() { - Self::prepend(¤t.getLatchBytes()?, &mut bytesAL);} + Self::prepend(¤t.getLatchBytes()?, &mut bytesAL); + } size = 0; } @@ -1450,7 +1451,7 @@ impl Input { pub fn getFNC1Character(&self) -> Option { if self.internal.getFNC1Character() == 1000 { None - }else { + } else { Some(self.internal.getFNC1Character() as u8 as char) } }