cargo fmt

This commit is contained in:
Henry Schimke
2023-01-29 16:07:49 -06:00
parent fb8d534f9e
commit 12007fdde0
2 changed files with 93 additions and 53 deletions

View File

@@ -107,7 +107,11 @@ 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()); 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,8 +129,9 @@ impl ECIStringBuilder {
// result = currentBytes; // result = currentBytes;
// currentBytes = new StringBuilder(); // currentBytes = new StringBuilder();
// } else { // } else {
self.result self.result.push_str(
.push_str(&String::from_utf8(std::mem::take(&mut self.current_bytes)).unwrap()); &String::from_utf8(std::mem::take(&mut self.current_bytes)).unwrap(),
);
self.current_bytes.clear(); self.current_bytes.clear();
// } // }
} }

View File

@@ -223,7 +223,7 @@ 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);
}, }
129 => return Ok(Mode::PAD_ENCODE), // Pad 129 => return Ok(Mode::PAD_ENCODE), // Pad
129..=229 => { 129..=229 => {
// 2-digit data 00-99 (Numeric Value + 130) // 2-digit data 00-99 (Numeric Value + 130)
@@ -234,57 +234,92 @@ 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}"));
}, }
230=> // Latch to C40 encodation 230 =>
return Ok(Mode::C40_ENCODE), // Latch to C40 encodation
231=> // Latch to Base 256 encodation {
return Ok(Mode::BASE256_ENCODE), return Ok(Mode::C40_ENCODE)
232=> {// FNC1 }
if bits.getByteOffset() == firstFNC1Position 231 =>
{/*result.symbology.modifier = '2';*/} // GS1 // Latch to Base 256 encodation
else if bits.getByteOffset() == firstFNC1Position + 1 {
{/*result.symbology.modifier = '3';*/} // AIM, note no AIM Application Indicator format defined, ISO 16022:2006 11.2 return Ok(Mode::BASE256_ENCODE)
else }
{fnc1positions.push(result.len()); 232 => {
result.append_char( 29 as char); }// translate as ASCII 29 // FNC1
}, if bits.getByteOffset() == firstFNC1Position { /*result.symbology.modifier = '2';*/
233 => // Structured Append }
{ // GS1
if !firstCodeword // Must be first ISO 16022:2006 5.6.1 else if bits.getByteOffset() == firstFNC1Position + 1 { /*result.symbology.modifier = '3';*/
{return Err(Exceptions::FormatException(Some("structured append tag must be first code word".to_owned())));} }
parse_structured_append(bits, &mut sai)?; // AIM, note no AIM Application Indicator format defined, ISO 16022:2006 11.2
firstFNC1Position = 5; else {
}, fnc1positions.push(result.len());
234=> // Reader Programming result.append_char(29 as char);
} // translate as ASCII 29
}
233 =>
// Structured Append
{
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(),
)));
}
parse_structured_append(bits, &mut sai)?;
firstFNC1Position = 5;
}
234 =>
// Reader Programming
// Ignore these symbols for now // Ignore these symbols for now
//throw ReaderException.getInstance(); //throw ReaderException.getInstance();
{}, {}
235=> // Upper Shift (shift to Extended ASCII) 235 =>
upperShift = true, // Upper Shift (shift to Extended ASCII)
236=> {// 05 Macro {
result.append_string(VALUE_236); upperShift = true
resultTrailer.replace_range(0..0, INSERT_STRING_CONST); }
// resultTrailer.insert(0, "\u{001E}\u{0004}"); 236 => {
}, // 05 Macro
237=>{ // 06 Macro result.append_string(VALUE_236);
result.append_string(VALUE_237); resultTrailer.replace_range(0..0, INSERT_STRING_CONST);
resultTrailer.replace_range(0..0, INSERT_STRING_CONST); // resultTrailer.insert(0, "\u{001E}\u{0004}");
// resultTrailer.insert(0, "\u{001E}\u{0004}"); }
}, 237 => {
238=> // Latch to ANSI X12 encodation // 06 Macro
return Ok(Mode::ANSIX12_ENCODE), result.append_string(VALUE_237);
239=> // Latch to Text encodation resultTrailer.replace_range(0..0, INSERT_STRING_CONST);
return Ok(Mode::TEXT_ENCODE), // resultTrailer.insert(0, "\u{001E}\u{0004}");
240=> // Latch to EDIFACT encodation }
return Ok(Mode::EDIFACT_ENCODE), 238 =>
241=> // ECI Character // Latch to ANSI X12 encodation
return Ok(Mode::ECI_ENCODE), {
_=>{ return Ok(Mode::ANSIX12_ENCODE)
// Not to be used in ASCII encodation }
// but work around encoders that end with 254, latch back to ASCII 239 =>
if oneByte != 254 || bits.available() != 0 { // Latch to Text encodation
return Err(Exceptions::FormatException(None)) {
}}, return Ok(Mode::TEXT_ENCODE)
}
240 =>
// Latch to EDIFACT encodation
{
return Ok(Mode::EDIFACT_ENCODE)
}
241 =>
// ECI Character
{
return Ok(Mode::ECI_ENCODE)
}
_ => {
// Not to be used in ASCII encodation
// but work around encoders that end with 254, latch back to ASCII
if oneByte != 254 || bits.available() != 0 {
return Err(Exceptions::FormatException(None));
}
}
} }
if bits.available() == 0 { if bits.available() == 0 {