move to using Eci enum

Decouples the Eci and CharacterSet concepts within the library. Character sets can now exist independently from Eci encodation schemes.
This commit is contained in:
Henry Schimke
2023-03-04 14:13:50 -06:00
parent 15859b9f10
commit 8a0744e534
21 changed files with 403 additions and 182 deletions

View File

@@ -148,7 +148,7 @@ fn testAztecWriter() {
testWriter("\u{20AC} 1 sample data.", Some(ISO_8859_15), 0, true, 2);
testWriter(
"\u{20AC} 1 sample data.",
Some(CharacterSet::UnicodeBigUnmarked),
Some(CharacterSet::UTF16BE),
0,
true,
3,

View File

@@ -19,7 +19,7 @@ use crate::{
reedsolomon::{
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonDecoder,
},
BitMatrix, CharacterSet, DecoderRXingResult, DetectorRXingResult, Result,
BitMatrix, CharacterSet, DecoderRXingResult, DetectorRXingResult, Result, Eci,
},
exceptions::Exceptions,
};
@@ -182,11 +182,11 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
eci = eci * 10 + (next_digit - 2);
n -= 1;
}
let charset_eci = CharacterSet::get_character_set_by_eci(eci);
if charset_eci.is_err() {
let charset_eci : Eci= eci.into();
if charset_eci == Eci::Unknown {
return Err(Exceptions::format_with("Charset must exist"));
}
encdr = charset_eci?;
encdr = charset_eci.into();
}
}
// Go back to whatever mode we had been in

View File

@@ -242,7 +242,7 @@ impl HighLevelEncoder {
//if let Some(eci) = CharacterSetECI::getCharacterSetECI(self.charset) {
if self.charset != CharacterSet::ISO8859_1 {
//} && eci != CharacterSetECI::Cp1252 {
initial_state = initial_state.appendFLGn(self.charset.get_eci_value())?;
initial_state = initial_state.appendFLGn(self.charset.into())?;
}
// } else {
// return Err(Exceptions::illegal_argument_with(

View File

@@ -17,7 +17,7 @@
use std::fmt;
use crate::{
common::{BitArray, CharacterSet, Result},
common::{BitArray, CharacterSet, Result, Eci},
exceptions::Exceptions,
};
@@ -71,7 +71,7 @@ impl State {
self.bit_count
}
pub fn appendFLGn(self, eci: u32) -> Result<Self> {
pub fn appendFLGn(self, eci: Eci) -> Result<Self> {
let bit_count = self.bit_count;
let mode = self.mode;
let result = self.shiftAndAppend(HighLevelEncoder::MODE_PUNCT as u32, 0); // 0: FLG(n)
@@ -80,7 +80,7 @@ impl State {
/*if eci < 0 {
token.add(0, 3); // 0: FNC1
} else */
if eci > 999999 {
if eci as u32 > 999999 {
return Err(Exceptions::illegal_argument_with(
"ECI code must be between 0 and 999999",
));