fix some high level eci parsing

This commit is contained in:
Henry Schimke
2023-01-29 16:07:37 -06:00
parent f38e294481
commit fb8d534f9e
3 changed files with 97 additions and 83 deletions

View File

@@ -105,10 +105,11 @@ impl ECIStringBuilder {
*/
pub fn appendECI(&mut self, value: u32) -> Result<(), Exceptions> {
self.encodeCurrentBytesIfAny();
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));
}else {
} else {
self.current_charset = None
}
@@ -118,35 +119,35 @@ impl ECIStringBuilder {
pub fn encodeCurrentBytesIfAny(&mut self) {
if let Some(encoder) = self.current_charset {
if encoder.name() == encoding::all::UTF_8.name() {
if !self.current_bytes.is_empty() {
// if result == null {
// result = currentBytes;
// currentBytes = new StringBuilder();
// } else {
self.result
.push_str(&String::from_utf8(self.current_bytes.clone()).unwrap());
if encoder.name() == encoding::all::UTF_8.name() {
if !self.current_bytes.is_empty() {
// if result == null {
// result = currentBytes;
// currentBytes = new StringBuilder();
// } else {
self.result
.push_str(&String::from_utf8(std::mem::take(&mut self.current_bytes)).unwrap());
self.current_bytes.clear();
// }
}
} else if !self.current_bytes.is_empty() {
let bytes = std::mem::take(&mut self.current_bytes);
self.current_bytes.clear();
// }
// if (result == null) {
// result = new StringBuilder(new String(bytes, currentCharset));
// } else {
let encoded_value = encoder
.decode(&bytes, encoding::DecoderTrap::Strict)
.unwrap();
self.result.push_str(&encoded_value);
// }
}
} else {
for byte in &self.current_bytes {
self.result.push(char::from(*byte))
}
} else if !self.current_bytes.is_empty() {
let bytes = self.current_bytes.clone();
self.current_bytes.clear();
// if (result == null) {
// result = new StringBuilder(new String(bytes, currentCharset));
// } else {
let encoded_value = encoder
.decode(&bytes, encoding::DecoderTrap::Replace)
.unwrap();
self.result.push_str(&encoded_value);
// }
}
}else {
for byte in &self.current_bytes {
self.result.push(char::from(*byte))
}
self.current_bytes.clear();
}
}
/**