repurpose CharacterSetECI as encoding abstraction

This commit is contained in:
Henry Schimke
2023-03-02 15:50:56 -06:00
parent c4fec7d2ee
commit a0b8b68869
29 changed files with 304 additions and 337 deletions

View File

@@ -16,16 +16,14 @@
use std::{fmt, rc::Rc};
use encoding::{self, EncodingRef};
use crate::{
common::{ECIInput, MinimalECIInput, Result},
common::{ECIInput, MinimalECIInput, Result, CharacterSetECI},
Exceptions,
};
use super::{high_level_encoder, SymbolShapeHint};
const ISO_8859_1_ENCODER: EncodingRef = encoding::all::ISO_8859_1;
const ISO_8859_1_ENCODER: CharacterSetECI = CharacterSetECI::ISO8859_1;
/**
* Encoder that encodes minimally
@@ -153,7 +151,7 @@ pub fn encodeHighLevel(msg: &str) -> Result<String> {
*/
pub fn encodeHighLevelWithDetails(
msg: &str,
priorityCharset: Option<EncodingRef>,
priorityCharset: Option<CharacterSetECI>,
fnc1: Option<char>,
shape: SymbolShapeHint,
) -> Result<String> {
@@ -174,8 +172,8 @@ pub fn encodeHighLevelWithDetails(
}
Ok(ISO_8859_1_ENCODER
.decode(
&encode(msg, priorityCharset, fnc1, shape, macroId)?,
encoding::DecoderTrap::Strict,
&encode(msg, priorityCharset, fnc1, shape, macroId)?
)
.expect("should decode"))
// return new String(encode(msg, priorityCharset, fnc1, shape, macroId), StandardCharsets.ISO_8859_1);
@@ -197,7 +195,7 @@ pub fn encodeHighLevelWithDetails(
*/
fn encode(
input: &str,
priorityCharset: Option<EncodingRef>,
priorityCharset: Option<CharacterSetECI>,
fnc1: Option<char>,
shape: SymbolShapeHint,
macroId: i32,
@@ -1398,7 +1396,7 @@ struct Input {
impl Input {
pub fn new(
stringToEncode: &str,
priorityCharset: Option<EncodingRef>,
priorityCharset: Option<CharacterSetECI>,
fnc1: Option<char>,
shape: SymbolShapeHint,
macroId: i32,