mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
fix some high level eci parsing
This commit is contained in:
@@ -107,6 +107,7 @@ impl ECIStringBuilder {
|
|||||||
self.encodeCurrentBytesIfAny();
|
self.encodeCurrentBytesIfAny();
|
||||||
|
|
||||||
if let Ok(character_set_eci) = CharacterSetECI::getCharacterSetECIByValue(value) {
|
if let Ok(character_set_eci) = CharacterSetECI::getCharacterSetECIByValue(value) {
|
||||||
|
dbg!(character_set_eci, CharacterSetECI::getCharset(&character_set_eci).name(), CharacterSetECI::getCharset(&character_set_eci).whatwg_name());
|
||||||
self.current_charset = Some(CharacterSetECI::getCharset(&character_set_eci));
|
self.current_charset = Some(CharacterSetECI::getCharset(&character_set_eci));
|
||||||
} else {
|
} else {
|
||||||
self.current_charset = None
|
self.current_charset = None
|
||||||
@@ -125,18 +126,18 @@ impl ECIStringBuilder {
|
|||||||
// currentBytes = new StringBuilder();
|
// currentBytes = new StringBuilder();
|
||||||
// } else {
|
// } else {
|
||||||
self.result
|
self.result
|
||||||
.push_str(&String::from_utf8(self.current_bytes.clone()).unwrap());
|
.push_str(&String::from_utf8(std::mem::take(&mut self.current_bytes)).unwrap());
|
||||||
self.current_bytes.clear();
|
self.current_bytes.clear();
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
} else if !self.current_bytes.is_empty() {
|
} else if !self.current_bytes.is_empty() {
|
||||||
let bytes = self.current_bytes.clone();
|
let bytes = std::mem::take(&mut self.current_bytes);
|
||||||
self.current_bytes.clear();
|
self.current_bytes.clear();
|
||||||
// if (result == null) {
|
// if (result == null) {
|
||||||
// result = new StringBuilder(new String(bytes, currentCharset));
|
// result = new StringBuilder(new String(bytes, currentCharset));
|
||||||
// } else {
|
// } else {
|
||||||
let encoded_value = encoder
|
let encoded_value = encoder
|
||||||
.decode(&bytes, encoding::DecoderTrap::Replace)
|
.decode(&bytes, encoding::DecoderTrap::Strict)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.result.push_str(&encoded_value);
|
self.result.push_str(&encoded_value);
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -121,30 +121,43 @@ pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
|
|||||||
let symbologyModifier;
|
let symbologyModifier;
|
||||||
let mut isECIencoded = false;
|
let mut isECIencoded = false;
|
||||||
loop {
|
loop {
|
||||||
if mode == Mode::ASCII_ENCODE {
|
match mode {
|
||||||
|
Mode::ASCII_ENCODE => {
|
||||||
mode = decodeAsciiSegment(
|
mode = decodeAsciiSegment(
|
||||||
&mut bits,
|
&mut bits,
|
||||||
&mut result,
|
&mut result,
|
||||||
&mut resultTrailer,
|
&mut resultTrailer,
|
||||||
&mut fnc1Positions,
|
&mut fnc1Positions,
|
||||||
)?;
|
)?
|
||||||
} else {
|
}
|
||||||
match mode {
|
Mode::C40_ENCODE => {
|
||||||
Mode::C40_ENCODE => decodeC40Segment(&mut bits, &mut result, &mut fnc1Positions)?,
|
decodeC40Segment(&mut bits, &mut result, &mut fnc1Positions)?;
|
||||||
Mode::TEXT_ENCODE => decodeTextSegment(&mut bits, &mut result, &mut fnc1Positions)?,
|
mode = Mode::ASCII_ENCODE;
|
||||||
Mode::ANSIX12_ENCODE => decodeAnsiX12Segment(&mut bits, &mut result)?,
|
}
|
||||||
Mode::EDIFACT_ENCODE => decodeEdifactSegment(&mut bits, &mut result)?,
|
Mode::TEXT_ENCODE => {
|
||||||
|
decodeTextSegment(&mut bits, &mut result, &mut fnc1Positions)?;
|
||||||
|
mode = Mode::ASCII_ENCODE;
|
||||||
|
}
|
||||||
|
Mode::ANSIX12_ENCODE => {
|
||||||
|
decodeAnsiX12Segment(&mut bits, &mut result)?;
|
||||||
|
mode = Mode::ASCII_ENCODE;
|
||||||
|
}
|
||||||
|
Mode::EDIFACT_ENCODE => {
|
||||||
|
decodeEdifactSegment(&mut bits, &mut result)?;
|
||||||
|
mode = Mode::ASCII_ENCODE;
|
||||||
|
}
|
||||||
Mode::BASE256_ENCODE => {
|
Mode::BASE256_ENCODE => {
|
||||||
decodeBase256Segment(&mut bits, &mut result, &mut byteSegments)?
|
decodeBase256Segment(&mut bits, &mut result, &mut byteSegments)?;
|
||||||
|
mode = Mode::ASCII_ENCODE;
|
||||||
}
|
}
|
||||||
Mode::ECI_ENCODE => {
|
Mode::ECI_ENCODE => {
|
||||||
decodeECISegment(&mut bits, &mut result)?;
|
decodeECISegment(&mut bits, &mut result)?;
|
||||||
isECIencoded = true; // ECI detection only, atm continue decoding as ASCII
|
isECIencoded = true; // ECI detection only, atm continue decoding as ASCII
|
||||||
}
|
|
||||||
_ => return Err(Exceptions::FormatException(None)),
|
|
||||||
};
|
|
||||||
mode = Mode::ASCII_ENCODE;
|
mode = Mode::ASCII_ENCODE;
|
||||||
}
|
}
|
||||||
|
_ => return Err(Exceptions::FormatException(None)),
|
||||||
|
}
|
||||||
|
|
||||||
if !(mode != Mode::PAD_ENCODE && bits.available() > 0) {
|
if !(mode != Mode::PAD_ENCODE && bits.available() > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -200,9 +213,9 @@ fn decodeAsciiSegment(
|
|||||||
let mut sai = StructuredAppendInfo::default();
|
let mut sai = StructuredAppendInfo::default();
|
||||||
loop {
|
loop {
|
||||||
let mut oneByte = bits.readBits(8)?;
|
let mut oneByte = bits.readBits(8)?;
|
||||||
if oneByte == 0 {
|
match oneByte {
|
||||||
return Err(Exceptions::FormatException(None));
|
0 => return Err(Exceptions::FormatException(None)),
|
||||||
} else if oneByte <= 128 {
|
1..=128 => {
|
||||||
// ASCII data (ASCII value + 1)
|
// ASCII data (ASCII value + 1)
|
||||||
if upperShift {
|
if upperShift {
|
||||||
oneByte += 128;
|
oneByte += 128;
|
||||||
@@ -210,10 +223,9 @@ fn decodeAsciiSegment(
|
|||||||
}
|
}
|
||||||
result.append_char(char::from_u32(oneByte - 1).unwrap());
|
result.append_char(char::from_u32(oneByte - 1).unwrap());
|
||||||
return Ok(Mode::ASCII_ENCODE);
|
return Ok(Mode::ASCII_ENCODE);
|
||||||
} else if oneByte == 129 {
|
},
|
||||||
// Pad
|
129 => return Ok(Mode::PAD_ENCODE), // Pad
|
||||||
return Ok(Mode::PAD_ENCODE);
|
129..=229 => {
|
||||||
} else if oneByte <= 229 {
|
|
||||||
// 2-digit data 00-99 (Numeric Value + 130)
|
// 2-digit data 00-99 (Numeric Value + 130)
|
||||||
let value = oneByte - 130;
|
let value = oneByte - 130;
|
||||||
if value < 10 {
|
if value < 10 {
|
||||||
@@ -222,8 +234,7 @@ fn decodeAsciiSegment(
|
|||||||
}
|
}
|
||||||
//result.append_char(char::from_u32(value).unwrap());
|
//result.append_char(char::from_u32(value).unwrap());
|
||||||
result.append_string(&format!("{value}"));
|
result.append_string(&format!("{value}"));
|
||||||
} else {
|
},
|
||||||
match oneByte {
|
|
||||||
230=> // Latch to C40 encodation
|
230=> // Latch to C40 encodation
|
||||||
return Ok(Mode::C40_ENCODE),
|
return Ok(Mode::C40_ENCODE),
|
||||||
231=> // Latch to Base 256 encodation
|
231=> // Latch to Base 256 encodation
|
||||||
@@ -237,16 +248,17 @@ fn decodeAsciiSegment(
|
|||||||
{fnc1positions.push(result.len());
|
{fnc1positions.push(result.len());
|
||||||
result.append_char( 29 as char); }// translate as ASCII 29
|
result.append_char( 29 as char); }// translate as ASCII 29
|
||||||
},
|
},
|
||||||
233| // Structured Append
|
233 => // Structured Append
|
||||||
234=> // Reader Programming
|
|
||||||
// Ignore these symbols for now
|
|
||||||
//throw ReaderException.getInstance();
|
|
||||||
{
|
{
|
||||||
if !firstCodeword // Must be first ISO 16022:2006 5.6.1
|
if !firstCodeword // Must be first ISO 16022:2006 5.6.1
|
||||||
{return Err(Exceptions::FormatException(Some("structured append tag must be first code word".to_owned())));}
|
{return Err(Exceptions::FormatException(Some("structured append tag must be first code word".to_owned())));}
|
||||||
parse_structured_append(bits, &mut sai)?;
|
parse_structured_append(bits, &mut sai)?;
|
||||||
firstFNC1Position = 5;
|
firstFNC1Position = 5;
|
||||||
},
|
},
|
||||||
|
234=> // Reader Programming
|
||||||
|
// Ignore these symbols for now
|
||||||
|
//throw ReaderException.getInstance();
|
||||||
|
{},
|
||||||
235=> // Upper Shift (shift to Extended ASCII)
|
235=> // Upper Shift (shift to Extended ASCII)
|
||||||
upperShift = true,
|
upperShift = true,
|
||||||
236=> {// 05 Macro
|
236=> {// 05 Macro
|
||||||
@@ -274,7 +286,7 @@ fn decodeAsciiSegment(
|
|||||||
return Err(Exceptions::FormatException(None))
|
return Err(Exceptions::FormatException(None))
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if bits.available() == 0 {
|
if bits.available() == 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
1
test_resources/blackbox/datamatrix-1/eci-mixed.txt
Normal file
1
test_resources/blackbox/datamatrix-1/eci-mixed.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
á¡¡ĦĦͱð¶@@@@@@@@@@_
|
||||||
Reference in New Issue
Block a user