basic high_level_encoder pass

This commit is contained in:
Henry Schimke
2022-11-01 08:52:53 -05:00
parent e6ef49c4e5
commit c925d32e78
2 changed files with 5 additions and 4 deletions

View File

@@ -26,7 +26,7 @@ pub struct C40Encoder;
impl Encoder for C40Encoder {
fn encode(&self, context: &mut super::EncoderContext) -> Result<(), Exceptions> {
self.encode_with_encode_char_fn(context, &Self::encodeChar_c40, &Self::handleEOD_c40)
self.encode_with_encode_char_fn(context, &Self::encodeChar_c40, &Self::handleEOD_c40, &||{self.getEncodingMode()})
}
fn getEncodingMode(&self) -> usize {
@@ -44,6 +44,7 @@ impl C40Encoder {
context: &mut super::EncoderContext,
encodeChar: &dyn Fn(char, &mut String) -> u32,
handleEOD: &dyn Fn(&mut EncoderContext, &mut String) -> Result<(), Exceptions>,
getEncodingMode: &dyn Fn() -> usize,
) -> Result<(), Exceptions> {
//step C
let mut buffer = String::new();
@@ -89,9 +90,9 @@ impl C40Encoder {
let newMode = high_level_encoder::lookAheadTest(
context.getMessage(),
context.pos,
self.getEncodingMode() as u32,
getEncodingMode() as u32,
);
if newMode != self.getEncodingMode() {
if newMode != getEncodingMode() {
// Return to ASCII encodation, which will actually handle latch to new mode
context.signalEncoderChange(ASCII_ENCODATION);
break;

View File

@@ -24,7 +24,7 @@ impl Encoder for TextEncoder {
fn encode(&self, context: &mut super::EncoderContext) -> Result<(), crate::Exceptions> {
self.0
.encode_with_encode_char_fn(context, &Self::encodeChar, &C40Encoder::handleEOD_c40)
.encode_with_encode_char_fn(context, &Self::encodeChar, &C40Encoder::handleEOD_c40, &||{self.getEncodingMode()})
}
}
impl TextEncoder {