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

@@ -21,7 +21,7 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::common::Result;
use crate::Exceptions;
use super::{CharacterSet, ECIEncoderSet, ECIInput};
use super::{CharacterSet, ECIEncoderSet, ECIInput, Eci};
//* approximated (latch + 2 codewords)
pub const COST_PER_ECI: usize = 3;
@@ -154,7 +154,7 @@ impl ECIInput for MinimalECIInput {
* @throws IllegalArgumentException
* if the value at the {@code index} argument is not an ECI (@see #isECI)
*/
fn getECIValue(&self, index: usize) -> Result<i32> {
fn getECIValue(&self, index: usize) -> Result<Eci> {
if index >= self.length() {
return Err(Exceptions::INDEX_OUT_OF_BOUNDS);
}
@@ -163,7 +163,7 @@ impl ECIInput for MinimalECIInput {
"value at {index} is not an ECI but a character"
)));
}
Ok((self.bytes[index] as u32 - 256) as i32)
Ok(Eci::from(self.bytes[index] as u32 - 256))
}
fn haveNCharacters(&self, index: usize, n: usize) -> Result<bool> {
@@ -383,7 +383,7 @@ impl MinimalECIInput {
// 0..0,
// [256 as u16 + encoderSet.getECIValue(c.encoderIndex) as u16],
// );
intsAL.insert(0, 256_u16 + encoderSet.getECIValue(c.encoderIndex) as u16);
intsAL.insert(0, 256_u16 + encoderSet.get_eci(c.encoderIndex) as u16);
}
current = c.previous.clone();
}