mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-28 05:12:34 +00:00
some tests with minimal pass
This commit is contained in:
@@ -224,7 +224,7 @@ impl MinimalECIInput {
|
|||||||
Self::encodeMinimally(
|
Self::encodeMinimally(
|
||||||
stringToEncodeInput,
|
stringToEncodeInput,
|
||||||
&encoderSet,
|
&encoderSet,
|
||||||
fnc1.as_ref().unwrap().chars().nth(0).unwrap() as u16,
|
fnc1
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -279,24 +279,25 @@ impl MinimalECIInput {
|
|||||||
edges: &mut Vec<Vec<Option<Rc<InputEdge>>>>,
|
edges: &mut Vec<Vec<Option<Rc<InputEdge>>>>,
|
||||||
from: usize,
|
from: usize,
|
||||||
previous: Option<Rc<InputEdge>>,
|
previous: Option<Rc<InputEdge>>,
|
||||||
fnc1: u16,
|
fnc1: Option<&str>,
|
||||||
) {
|
) {
|
||||||
// let ch = stringToEncode.chars().nth(from).unwrap() as i16;
|
// let ch = stringToEncode.chars().nth(from).unwrap() as i16;
|
||||||
let ch = stringToEncode.graphemes(true).nth(from).unwrap();
|
let ch = stringToEncode.graphemes(true).nth(from).unwrap();
|
||||||
|
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
let mut end = encoderSet.len();
|
let mut end = encoderSet.len();
|
||||||
|
if let Some(fnc1) = fnc1 {
|
||||||
if encoderSet.getPriorityEncoderIndex().is_some()
|
if encoderSet.getPriorityEncoderIndex().is_some()
|
||||||
&& (ch.chars().nth(0).unwrap() as u16 == fnc1
|
&& (ch.chars().nth(0).unwrap() == fnc1.chars().nth(1).unwrap()
|
||||||
|| encoderSet.canEncode(ch, encoderSet.getPriorityEncoderIndex().unwrap()))
|
|| encoderSet.canEncode(ch, encoderSet.getPriorityEncoderIndex().unwrap()))
|
||||||
{
|
{
|
||||||
start = encoderSet.getPriorityEncoderIndex().unwrap();
|
start = encoderSet.getPriorityEncoderIndex().unwrap();
|
||||||
end = start + 1;
|
end = start + 1;
|
||||||
}
|
}}
|
||||||
|
|
||||||
for i in start..end {
|
for i in start..end {
|
||||||
// for (int i = start; i < end; i++) {
|
// for (int i = start; i < end; i++) {
|
||||||
if ch.chars().nth(0).unwrap() as u16 == fnc1 || encoderSet.canEncode(ch, i) {
|
if (fnc1.is_some() && ch.chars().nth(0).unwrap() == fnc1.as_ref().unwrap().chars().nth(0).unwrap()) || encoderSet.canEncode(ch, i) {
|
||||||
Self::addEdge(
|
Self::addEdge(
|
||||||
edges,
|
edges,
|
||||||
from + 1,
|
from + 1,
|
||||||
@@ -309,15 +310,15 @@ impl MinimalECIInput {
|
|||||||
pub fn encodeMinimally(
|
pub fn encodeMinimally(
|
||||||
stringToEncode: &str,
|
stringToEncode: &str,
|
||||||
encoderSet: &ECIEncoderSet,
|
encoderSet: &ECIEncoderSet,
|
||||||
fnc1: u16,
|
fnc1: Option<&str>,
|
||||||
) -> Vec<u16> {
|
) -> Vec<u16> {
|
||||||
let inputLength = stringToEncode.len();
|
let inputLength = stringToEncode.chars().count();
|
||||||
|
|
||||||
// Array that represents vertices. There is a vertex for every character and encoding.
|
// 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()];
|
let mut edges = vec![vec![None; encoderSet.len()]; inputLength + 1]; //InputEdge[inputLength + 1][encoderSet.length()];
|
||||||
Self::addEdges(stringToEncode, encoderSet, &mut edges, 0, None, fnc1);
|
Self::addEdges(stringToEncode, encoderSet, &mut edges, 0, None, fnc1);
|
||||||
|
|
||||||
for i in 0..=inputLength {
|
for i in 1..=inputLength {
|
||||||
// for (int i = 1; i <= inputLength; i++) {
|
// for (int i = 1; i <= inputLength; i++) {
|
||||||
for j in 0..encoderSet.len() {
|
for j in 0..encoderSet.len() {
|
||||||
// for (int j = 0; j < encoderSet.length(); j++) {
|
// for (int j = 0; j < encoderSet.length(); j++) {
|
||||||
@@ -400,7 +401,7 @@ impl InputEdge {
|
|||||||
encoderSet: &ECIEncoderSet,
|
encoderSet: &ECIEncoderSet,
|
||||||
encoderIndex: usize,
|
encoderIndex: usize,
|
||||||
previous: Option<Rc<InputEdge>>,
|
previous: Option<Rc<InputEdge>>,
|
||||||
fnc1: u16,
|
fnc1: Option<&str>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut size = if c == "\u{1000}" {
|
let mut size = if c == "\u{1000}" {
|
||||||
1
|
1
|
||||||
@@ -408,7 +409,7 @@ impl InputEdge {
|
|||||||
encoderSet.encode_char(c, encoderIndex).len()
|
encoderSet.encode_char(c, encoderIndex).len()
|
||||||
};
|
};
|
||||||
|
|
||||||
let fnc1Str = String::from_utf16(&[fnc1]).unwrap();
|
//let fnc1Str = String::from_utf16(&[fnc1]).unwrap();
|
||||||
|
|
||||||
if let Some(prev) = previous {
|
if let Some(prev) = previous {
|
||||||
let previousEncoderIndex = prev.encoderIndex;
|
let previousEncoderIndex = prev.encoderIndex;
|
||||||
@@ -418,7 +419,7 @@ impl InputEdge {
|
|||||||
size += prev.cachedTotalSize;
|
size += prev.cachedTotalSize;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
c: if c == fnc1Str {
|
c: if fnc1.is_some() && &c == fnc1.as_ref().unwrap() {
|
||||||
String::from("\u{1000}")
|
String::from("\u{1000}")
|
||||||
} else {
|
} else {
|
||||||
String::from(c)
|
String::from(c)
|
||||||
@@ -434,7 +435,7 @@ impl InputEdge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
c: if c == fnc1Str {
|
c: if fnc1.is_some() && &c == fnc1.as_ref().unwrap() {
|
||||||
String::from("\u{1000}")
|
String::from("\u{1000}")
|
||||||
} else {
|
} else {
|
||||||
String::from(c)
|
String::from(c)
|
||||||
|
|||||||
@@ -556,8 +556,8 @@ fn encodeHighLevel(msg: &str) -> String {
|
|||||||
|
|
||||||
fn encodeHighLevelCompare(msg: &str, compareSizeToMinimalEncoder: bool) -> String {
|
fn encodeHighLevelCompare(msg: &str, compareSizeToMinimalEncoder: bool) -> String {
|
||||||
let encoded = high_level_encoder::encodeHighLevel(msg).expect("encodes");
|
let encoded = high_level_encoder::encodeHighLevel(msg).expect("encodes");
|
||||||
// let encoded2 = minimal_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.len() <= encoded.len(), "{} <= {}", encoded2.len() , encoded.len());
|
||||||
visualize(&encoded)
|
visualize(&encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -164,13 +164,13 @@ pub fn encodeHighLevelWithDetails(
|
|||||||
{
|
{
|
||||||
macroId = 5;
|
macroId = 5;
|
||||||
// msg = msg.substring(high_level_encoder::MACRO_05_HEADER.len(), msg.len() - 2);
|
// msg = msg.substring(high_level_encoder::MACRO_05_HEADER.len(), msg.len() - 2);
|
||||||
msg = &msg[high_level_encoder::MACRO_05_HEADER.len()..(msg.len() - 2)];
|
msg = &msg[high_level_encoder::MACRO_05_HEADER.chars().count()..(msg.chars().count() - 2)];
|
||||||
} else if msg.starts_with(high_level_encoder::MACRO_06_HEADER)
|
} else if msg.starts_with(high_level_encoder::MACRO_06_HEADER)
|
||||||
&& msg.ends_with(high_level_encoder::MACRO_TRAILER)
|
&& msg.ends_with(high_level_encoder::MACRO_TRAILER)
|
||||||
{
|
{
|
||||||
macroId = 6;
|
macroId = 6;
|
||||||
// msg = msg.substring(high_level_encoder::MACRO_06_HEADER.len(), msg.len() - 2);
|
// msg = msg.substring(high_level_encoder::MACRO_06_HEADER.len(), msg.len() - 2);
|
||||||
msg = &msg[high_level_encoder::MACRO_06_HEADER.len()..(msg.len() - 2)];
|
msg = &msg[high_level_encoder::MACRO_06_HEADER.chars().count()..(msg.chars().count() - 2)];
|
||||||
}
|
}
|
||||||
Ok(ISO_8859_1_ENCODER
|
Ok(ISO_8859_1_ENCODER
|
||||||
.decode(
|
.decode(
|
||||||
@@ -253,7 +253,7 @@ fn getNumberOfC40Words(
|
|||||||
|| !c40 && high_level_encoder::isNativeText(ci)
|
|| !c40 && high_level_encoder::isNativeText(ci)
|
||||||
{
|
{
|
||||||
thirdsCount += 1; //native
|
thirdsCount += 1; //native
|
||||||
} else if !isExtendedASCII(ci, Some(input.getFNC1Character())) {
|
} else if !isExtendedASCII(ci, input.getFNC1Character()) {
|
||||||
thirdsCount += 2; //shift
|
thirdsCount += 2; //shift
|
||||||
} else {
|
} else {
|
||||||
let asciiValue = ci as u8 & 0xff;
|
let asciiValue = ci as u8 & 0xff;
|
||||||
@@ -711,7 +711,7 @@ impl Edge {
|
|||||||
input
|
input
|
||||||
.charAt(fromPosition as usize)
|
.charAt(fromPosition as usize)
|
||||||
.expect("char must exist)"),
|
.expect("char must exist)"),
|
||||||
Some(input.getFNC1Character()),
|
input.getFNC1Character(),
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
size += 1;
|
size += 1;
|
||||||
@@ -878,7 +878,7 @@ impl Edge {
|
|||||||
if length - from == 1 {
|
if length - from == 1 {
|
||||||
if isExtendedASCII(
|
if isExtendedASCII(
|
||||||
self.input.charAt(from as usize)?,
|
self.input.charAt(from as usize)?,
|
||||||
Some(self.input.getFNC1Character()),
|
self.input.getFNC1Character(),
|
||||||
) {
|
) {
|
||||||
return Ok(0);
|
return Ok(0);
|
||||||
}
|
}
|
||||||
@@ -887,10 +887,10 @@ impl Edge {
|
|||||||
if length - from == 2 {
|
if length - from == 2 {
|
||||||
if isExtendedASCII(
|
if isExtendedASCII(
|
||||||
self.input.charAt(from as usize)?,
|
self.input.charAt(from as usize)?,
|
||||||
Some(self.input.getFNC1Character()),
|
self.input.getFNC1Character(),
|
||||||
) || isExtendedASCII(
|
) || isExtendedASCII(
|
||||||
self.input.charAt(from as usize + 1)?,
|
self.input.charAt(from as usize + 1)?,
|
||||||
Some(self.input.getFNC1Character()),
|
self.input.getFNC1Character(),
|
||||||
) {
|
) {
|
||||||
return Ok(0);
|
return Ok(0);
|
||||||
}
|
}
|
||||||
@@ -906,7 +906,7 @@ impl Edge {
|
|||||||
&& high_level_encoder::isDigit(self.input.charAt(from as usize + 1)?)
|
&& high_level_encoder::isDigit(self.input.charAt(from as usize + 1)?)
|
||||||
&& !isExtendedASCII(
|
&& !isExtendedASCII(
|
||||||
self.input.charAt(from as usize + 2)?,
|
self.input.charAt(from as usize + 2)?,
|
||||||
Some(self.input.getFNC1Character()),
|
self.input.getFNC1Character(),
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return Ok(2);
|
return Ok(2);
|
||||||
@@ -915,7 +915,7 @@ impl Edge {
|
|||||||
&& high_level_encoder::isDigit(self.input.charAt(from as usize + 2)?)
|
&& high_level_encoder::isDigit(self.input.charAt(from as usize + 2)?)
|
||||||
&& !isExtendedASCII(
|
&& !isExtendedASCII(
|
||||||
self.input.charAt(from as usize)?,
|
self.input.charAt(from as usize)?,
|
||||||
Some(self.input.getFNC1Character()),
|
self.input.getFNC1Character(),
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return Ok(2);
|
return Ok(2);
|
||||||
@@ -1246,7 +1246,7 @@ impl Edge {
|
|||||||
));
|
));
|
||||||
} else if isExtendedASCII(
|
} else if isExtendedASCII(
|
||||||
self.input.charAt(self.fromPosition as usize)?,
|
self.input.charAt(self.fromPosition as usize)?,
|
||||||
Some(self.input.getFNC1Character()),
|
self.input.getFNC1Character(),
|
||||||
) {
|
) {
|
||||||
return Ok(Self::getBytes2(
|
return Ok(Self::getBytes2(
|
||||||
235,
|
235,
|
||||||
@@ -1272,8 +1272,8 @@ impl Edge {
|
|||||||
self.input.charAt(self.fromPosition as usize)? as u32,
|
self.input.charAt(self.fromPosition as usize)? as u32,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
Mode::C40 => return self.getC40Words(true, Some(self.input.getFNC1Character())),
|
Mode::C40 => return self.getC40Words(true, self.input.getFNC1Character()),
|
||||||
Mode::TEXT => return self.getC40Words(false, Some(self.input.getFNC1Character())),
|
Mode::TEXT => return self.getC40Words(false, self.input.getFNC1Character()),
|
||||||
Mode::X12 => return self.getX12Words(),
|
Mode::X12 => return self.getX12Words(),
|
||||||
Mode::EDF => return self.getEDFBytes(),
|
Mode::EDF => return self.getEDFBytes(),
|
||||||
}
|
}
|
||||||
@@ -1321,7 +1321,8 @@ impl RXingResult {
|
|||||||
randomizePostfixLength.push(bytesAL.len());
|
randomizePostfixLength.push(bytesAL.len());
|
||||||
randomizeLengths.push(size);
|
randomizeLengths.push(size);
|
||||||
}
|
}
|
||||||
Self::prepend(¤t.getLatchBytes()?, &mut bytesAL);
|
if Edge::getPreviousStartMode(current.previous.clone()) != current.getMode() {
|
||||||
|
Self::prepend(¤t.getLatchBytes()?, &mut bytesAL);}
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1333,7 +1334,7 @@ impl RXingResult {
|
|||||||
size += Self::prepend(&Edge::getBytes1(237), &mut bytesAL);
|
size += Self::prepend(&Edge::getBytes1(237), &mut bytesAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.getFNC1Character() as u8 > 0 {
|
if input.getFNC1Character().is_some() {
|
||||||
size += Self::prepend(&Edge::getBytes1(232), &mut bytesAL);
|
size += Self::prepend(&Edge::getBytes1(232), &mut bytesAL);
|
||||||
}
|
}
|
||||||
for i in 0..randomizePostfixLength.len() {
|
for i in 0..randomizePostfixLength.len() {
|
||||||
@@ -1427,9 +1428,6 @@ impl Input {
|
|||||||
macroId,
|
macroId,
|
||||||
internal: MinimalECIInput::new(stringToEncode, priorityCharset, v),
|
internal: MinimalECIInput::new(stringToEncode, priorityCharset, v),
|
||||||
}
|
}
|
||||||
// super(stringToEncode, priorityCharset, fnc1);
|
|
||||||
// this.shape = shape;
|
|
||||||
// this.macroId = macroId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getMacroId(&self) -> i32 {
|
pub fn getMacroId(&self) -> i32 {
|
||||||
@@ -1449,8 +1447,12 @@ impl Input {
|
|||||||
pub fn charAt(&self, index: usize) -> Result<char, Exceptions> {
|
pub fn charAt(&self, index: usize) -> Result<char, Exceptions> {
|
||||||
self.internal.charAt(index)
|
self.internal.charAt(index)
|
||||||
}
|
}
|
||||||
pub fn getFNC1Character(&self) -> char {
|
pub fn getFNC1Character(&self) -> Option<char> {
|
||||||
self.internal.getFNC1Character() as u8 as char
|
if self.internal.getFNC1Character() == 1000 {
|
||||||
|
None
|
||||||
|
}else {
|
||||||
|
Some(self.internal.getFNC1Character() as u8 as char)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn haveNCharacters(&self, index: usize, n: usize) -> bool {
|
fn haveNCharacters(&self, index: usize, n: usize) -> bool {
|
||||||
self.internal.haveNCharacters(index, n)
|
self.internal.haveNCharacters(index, n)
|
||||||
|
|||||||
Reference in New Issue
Block a user