From 18d1ed6b2dc25175930c1aa4e393811c33ecc33f Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Mon, 17 Oct 2022 09:48:40 -0500 Subject: [PATCH] move private struct back into mod --- src/common/input_edge.rs | 115 ------------------------------- src/common/minimal_eci_input.rs | 116 +++++++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 117 deletions(-) delete mode 100644 src/common/input_edge.rs diff --git a/src/common/input_edge.rs b/src/common/input_edge.rs deleted file mode 100644 index 33f5699..0000000 --- a/src/common/input_edge.rs +++ /dev/null @@ -1,115 +0,0 @@ -use std::{fmt, rc::Rc}; - -use super::{MinimalECIInput, ECIEncoderSet, ECIInput, COST_PER_ECI}; - -pub struct InputEdge { - pub c: String, - pub encoderIndex: usize, //the encoding of this edge - pub previous: Option>, - pub cachedTotalSize: usize, -} -impl InputEdge { - pub fn new( - c: &str, - encoderSet: &ECIEncoderSet, - encoderIndex: usize, - previous: Option>, - fnc1: u16, - ) -> Self { - let mut size = if c == "\u{1000}" { - 1 - } else { - encoderSet.encode_char(c, encoderIndex).len() - }; - - let fnc1Str = String::from_utf16(&[fnc1]).unwrap(); - - if let Some(prev) = previous { - let previousEncoderIndex = prev.encoderIndex; - if previousEncoderIndex != encoderIndex { - size += COST_PER_ECI; - } - size += prev.cachedTotalSize; - - Self { - c: if c == fnc1Str { - String::from("\u{1000}") - } else { - String::from(c) - }, - encoderIndex, - previous: Some(prev.clone()), - cachedTotalSize: size, - } - } else { - let previousEncoderIndex = 0; - if previousEncoderIndex != encoderIndex { - size += COST_PER_ECI; - } - - Self { - c: if c == fnc1Str { - String::from("\u{1000}") - } else { - String::from(c) - }, - encoderIndex, - previous: None, - cachedTotalSize: size, - } - } - - // int size = this.c == 1000 ? 1 : encoderSet.encode(c, encoderIndex).length; - // let previousEncoderIndex = if previous.is_none() { - // 0 - // } else { - // previous.unwrap().encoderIndex - // }; - // int previousEncoderIndex = previous == null ? 0 : previous.encoderIndex; - // if previousEncoderIndex != encoderIndex { - // size += COST_PER_ECI; - // } - // if prev_is_some { - // size += previous.unwrap().cachedTotalSize; - // } - - // Self { - // c: if c == fnc1 { 1000 as char } else { c }, - // encoderIndex, - // previous: previous, - // cachedTotalSize: size, - // } - // this.c = c == fnc1 ? 1000 : c; - // this.encoderIndex = encoderIndex; - // this.previous = previous; - // this.cachedTotalSize = size; - } - - pub fn isFNC1(&self) -> bool { - self.c == "\u{1000}" - } -} - -impl fmt::Display for MinimalECIInput { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut result = String::new(); - for i in 0..self.length() { - // for (int i = 0; i < length(); i++) { - if i > 0 { - result.push_str(", "); - } - if self.isECI(i as u32).unwrap() { - result.push_str("ECI("); - result.push_str(&self.getECIValue(i).unwrap().to_string()); - result.push(')'); - } else if (self.charAt(i).unwrap() as u8) < 128 { - result.push('\''); - result.push(self.charAt(i).unwrap()); - result.push('\''); - } else { - result.push(self.charAt(i).unwrap()); - } - } - write!(f, "{}", result) - } -} \ No newline at end of file diff --git a/src/common/minimal_eci_input.rs b/src/common/minimal_eci_input.rs index a72782c..4a9baf4 100644 --- a/src/common/minimal_eci_input.rs +++ b/src/common/minimal_eci_input.rs @@ -20,14 +20,14 @@ // import java.util.ArrayList; // import java.util.List; -use std::rc::Rc; +use std::{rc::Rc, fmt}; use encoding::EncodingRef; use unicode_segmentation::UnicodeSegmentation; use crate::Exceptions; -use super::{ECIEncoderSet, InputEdge, ECIInput}; +use super::{ECIEncoderSet, ECIInput}; //* approximated (latch + 2 codewords) pub const COST_PER_ECI: usize = 3; @@ -381,4 +381,116 @@ impl MinimalECIInput { } return ints; } +} + + struct InputEdge { + c: String, + encoderIndex: usize, //the encoding of this edge + previous: Option>, + cachedTotalSize: usize, +} +impl InputEdge { + pub fn new( + c: &str, + encoderSet: &ECIEncoderSet, + encoderIndex: usize, + previous: Option>, + fnc1: u16, + ) -> Self { + let mut size = if c == "\u{1000}" { + 1 + } else { + encoderSet.encode_char(c, encoderIndex).len() + }; + + let fnc1Str = String::from_utf16(&[fnc1]).unwrap(); + + if let Some(prev) = previous { + let previousEncoderIndex = prev.encoderIndex; + if previousEncoderIndex != encoderIndex { + size += COST_PER_ECI; + } + size += prev.cachedTotalSize; + + Self { + c: if c == fnc1Str { + String::from("\u{1000}") + } else { + String::from(c) + }, + encoderIndex, + previous: Some(prev.clone()), + cachedTotalSize: size, + } + } else { + let previousEncoderIndex = 0; + if previousEncoderIndex != encoderIndex { + size += COST_PER_ECI; + } + + Self { + c: if c == fnc1Str { + String::from("\u{1000}") + } else { + String::from(c) + }, + encoderIndex, + previous: None, + cachedTotalSize: size, + } + } + + // int size = this.c == 1000 ? 1 : encoderSet.encode(c, encoderIndex).length; + // let previousEncoderIndex = if previous.is_none() { + // 0 + // } else { + // previous.unwrap().encoderIndex + // }; + // int previousEncoderIndex = previous == null ? 0 : previous.encoderIndex; + // if previousEncoderIndex != encoderIndex { + // size += COST_PER_ECI; + // } + // if prev_is_some { + // size += previous.unwrap().cachedTotalSize; + // } + + // Self { + // c: if c == fnc1 { 1000 as char } else { c }, + // encoderIndex, + // previous: previous, + // cachedTotalSize: size, + // } + // this.c = c == fnc1 ? 1000 : c; + // this.encoderIndex = encoderIndex; + // this.previous = previous; + // this.cachedTotalSize = size; + } + + pub fn isFNC1(&self) -> bool { + self.c == "\u{1000}" + } +} + +impl fmt::Display for MinimalECIInput { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut result = String::new(); + for i in 0..self.length() { + // for (int i = 0; i < length(); i++) { + if i > 0 { + result.push_str(", "); + } + if self.isECI(i as u32).unwrap() { + result.push_str("ECI("); + result.push_str(&self.getECIValue(i).unwrap().to_string()); + result.push(')'); + } else if (self.charAt(i).unwrap() as u8) < 128 { + result.push('\''); + result.push(self.charAt(i).unwrap()); + result.push('\''); + } else { + result.push(self.charAt(i).unwrap()); + } + } + write!(f, "{}", result) + } } \ No newline at end of file