Merge branch 'main' into pr/exception_helpers

This commit is contained in:
Vukašin Stepanović
2023-02-16 07:15:51 +00:00
161 changed files with 900 additions and 933 deletions

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
use crate::common::Result;
use crate::Exceptions;
use super::{high_level_encoder, Encoder};
@@ -21,7 +22,7 @@ use super::{high_level_encoder, Encoder};
pub struct ASCIIEncoder;
impl Encoder for ASCIIEncoder {
fn encode(&self, context: &mut super::EncoderContext) -> Result<(), Exceptions> {
fn encode(&self, context: &mut super::EncoderContext) -> Result<()> {
//step B
let n =
high_level_encoder::determineConsecutiveDigitCount(context.getMessage(), context.pos);
@@ -99,7 +100,7 @@ impl ASCIIEncoder {
pub fn new() -> Self {
Self
}
fn encodeASCIIDigits(digit1: char, digit2: char) -> Result<char, Exceptions> {
fn encodeASCIIDigits(digit1: char, digit2: char) -> Result<char> {
if high_level_encoder::isDigit(digit1) && high_level_encoder::isDigit(digit2) {
let num = (digit1 as u8 - 48) * 10 + (digit2 as u8 - 48);
Ok((num + 130) as char)

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
use crate::common::Result;
use crate::Exceptions;
use super::{
@@ -27,7 +28,7 @@ impl Encoder for Base256Encoder {
BASE256_ENCODATION
}
fn encode(&self, context: &mut super::EncoderContext) -> Result<(), crate::Exceptions> {
fn encode(&self, context: &mut super::EncoderContext) -> Result<()> {
let mut buffer = String::new();
buffer.push('\0'); //Initialize length field
while context.hasMoreCharacters() {

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
use crate::common::Result;
use crate::Exceptions;
use super::high_level_encoder::{
@@ -25,7 +26,7 @@ use super::{Encoder, EncoderContext};
pub struct C40Encoder;
impl Encoder for C40Encoder {
fn encode(&self, context: &mut super::EncoderContext) -> Result<(), Exceptions> {
fn encode(&self, context: &mut super::EncoderContext) -> Result<()> {
self.encode_with_encode_char_fn(
context,
&Self::encodeChar_c40,
@@ -48,9 +49,9 @@ impl C40Encoder {
&self,
context: &mut super::EncoderContext,
encodeChar: &dyn Fn(char, &mut String) -> u32,
handleEOD: &dyn Fn(&mut EncoderContext, &mut String) -> Result<(), Exceptions>,
handleEOD: &dyn Fn(&mut EncoderContext, &mut String) -> Result<()>,
getEncodingMode: &dyn Fn() -> usize,
) -> Result<(), Exceptions> {
) -> Result<()> {
//step C
let mut buffer = String::new();
while context.hasMoreCharacters() {
@@ -110,7 +111,7 @@ impl C40Encoder {
handleEOD(context, &mut buffer)
}
pub fn encodeMaximalC40(&self, context: &mut EncoderContext) -> Result<(), Exceptions> {
pub fn encodeMaximalC40(&self, context: &mut EncoderContext) -> Result<()> {
self.encodeMaximal(context, &Self::encodeChar_c40, &Self::handleEOD_c40)
}
@@ -118,8 +119,8 @@ impl C40Encoder {
&self,
context: &mut EncoderContext,
encodeChar: &dyn Fn(char, &mut String) -> u32,
handleEOD: &dyn Fn(&mut EncoderContext, &mut String) -> Result<(), Exceptions>,
) -> Result<(), Exceptions> {
handleEOD: &dyn Fn(&mut EncoderContext, &mut String) -> Result<()>,
) -> Result<()> {
let mut buffer = String::new();
let mut lastCharSize = 0;
let mut backtrackStartPosition = context.pos;
@@ -181,8 +182,10 @@ impl C40Encoder {
pub(super) fn writeNextTriplet(
context: &mut EncoderContext,
buffer: &mut String,
) -> Result<(), Exceptions> {
context.writeCodewords(&Self::encodeToCodewords(buffer).ok_or(Exceptions::format)?);
) -> Result<()> {
context.writeCodewords(
&Self::encodeToCodewords(buffer).ok_or(Exceptions::FormatException(None))?,
);
buffer.replace_range(0..3, "");
// buffer.delete(0, 3);
Ok(())
@@ -194,10 +197,7 @@ impl C40Encoder {
* @param context the encoder context
* @param buffer the buffer with the remaining encoded characters
*/
pub fn handleEOD_c40(
context: &mut EncoderContext,
buffer: &mut String,
) -> Result<(), Exceptions> {
pub fn handleEOD_c40(context: &mut EncoderContext, buffer: &mut String) -> Result<()> {
let unwritten = (buffer.chars().count() / 3) * 2;
let rest = buffer.chars().count() % 3;

View File

@@ -14,12 +14,12 @@
* limitations under the License.
*/
use crate::Exceptions;
use crate::common::Result;
use super::EncoderContext;
pub trait Encoder {
fn getEncodingMode(&self) -> usize;
fn encode(&self, context: &mut EncoderContext) -> Result<(), Exceptions>;
fn encode(&self, context: &mut EncoderContext) -> Result<()>;
}

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
use crate::common::Result;
use crate::Exceptions;
const EMPTY_BIT_VAL: u8 = 13;
@@ -73,7 +74,7 @@ impl DefaultPlacement {
self.bits[row * self.numcols + col] == EMPTY_BIT_VAL
}
pub fn place(&mut self) -> Result<(), Exceptions> {
pub fn place(&mut self) -> Result<()> {
let mut pos = 0;
let mut row = 4_isize;
let mut col = 0_isize;
@@ -147,7 +148,7 @@ impl DefaultPlacement {
Ok(())
}
fn module(&mut self, row: isize, col: isize, pos: usize, bit: u32) -> Result<(), Exceptions> {
fn module(&mut self, row: isize, col: isize, pos: usize, bit: u32) -> Result<()> {
let mut row = row;
let mut col = col;
@@ -178,7 +179,7 @@ impl DefaultPlacement {
* @param col the column
* @param pos character position
*/
fn utah(&mut self, row: isize, col: isize, pos: usize) -> Result<(), Exceptions> {
fn utah(&mut self, row: isize, col: isize, pos: usize) -> Result<()> {
self.module(row - 2, col - 2, pos, 1)?;
self.module(row - 2, col - 1, pos, 2)?;
self.module(row - 1, col - 2, pos, 3)?;
@@ -190,7 +191,7 @@ impl DefaultPlacement {
Ok(())
}
fn corner1(&mut self, pos: usize) -> Result<(), Exceptions> {
fn corner1(&mut self, pos: usize) -> Result<()> {
self.module(self.numrows as isize - 1, 0, pos, 1)?;
self.module(self.numrows as isize - 1, 1, pos, 2)?;
self.module(self.numrows as isize - 1, 2, pos, 3)?;
@@ -202,7 +203,7 @@ impl DefaultPlacement {
Ok(())
}
fn corner2(&mut self, pos: usize) -> Result<(), Exceptions> {
fn corner2(&mut self, pos: usize) -> Result<()> {
self.module(self.numrows as isize - 3, 0, pos, 1)?;
self.module(self.numrows as isize - 2, 0, pos, 2)?;
self.module(self.numrows as isize - 1, 0, pos, 3)?;
@@ -214,7 +215,7 @@ impl DefaultPlacement {
Ok(())
}
fn corner3(&mut self, pos: usize) -> Result<(), Exceptions> {
fn corner3(&mut self, pos: usize) -> Result<()> {
self.module(self.numrows as isize - 3, 0, pos, 1)?;
self.module(self.numrows as isize - 2, 0, pos, 2)?;
self.module(self.numrows as isize - 1, 0, pos, 3)?;
@@ -226,7 +227,7 @@ impl DefaultPlacement {
Ok(())
}
fn corner4(&mut self, pos: usize) -> Result<(), Exceptions> {
fn corner4(&mut self, pos: usize) -> Result<()> {
self.module(self.numrows as isize - 1, 0, pos, 1)?;
self.module(self.numrows as isize - 1, self.numcols as isize - 1, pos, 2)?;
self.module(0, self.numcols as isize - 3, pos, 3)?;

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
use crate::common::Result;
use crate::Exceptions;
use super::{high_level_encoder, Encoder, EncoderContext};
@@ -24,7 +25,7 @@ impl Encoder for EdifactEncoder {
high_level_encoder::EDIFACT_ENCODATION
}
fn encode(&self, context: &mut super::EncoderContext) -> Result<(), crate::Exceptions> {
fn encode(&self, context: &mut super::EncoderContext) -> Result<()> {
//step F
let mut buffer = String::new();
while context.hasMoreCharacters() {
@@ -65,8 +66,8 @@ impl EdifactEncoder {
* @param context the encoder context
* @param buffer the buffer with the remaining encoded characters
*/
fn handleEOD(context: &mut EncoderContext, buffer: &mut str) -> Result<(), Exceptions> {
let mut runner = || -> Result<(), Exceptions> {
fn handleEOD(context: &mut EncoderContext, buffer: &mut str) -> Result<()> {
let mut runner = || -> Result<()> {
let count = buffer.chars().count();
if count == 0 {
return Ok(()); //Already finished
@@ -133,7 +134,7 @@ impl EdifactEncoder {
res
}
fn encodeChar(c: char, sb: &mut String) -> Result<(), Exceptions> {
fn encodeChar(c: char, sb: &mut String) -> Result<()> {
if (' '..='?').contains(&c) {
sb.push(c);
} else if ('@'..='^').contains(&c) {
@@ -144,7 +145,7 @@ impl EdifactEncoder {
Ok(())
}
fn encodeToCodewords(sb: &str) -> Result<String, Exceptions> {
fn encodeToCodewords(sb: &str) -> Result<String> {
let len = sb.chars().count();
if len == 0 {
return Err(Exceptions::illegalStateWith(

View File

@@ -16,6 +16,7 @@
use std::rc::Rc;
use crate::common::Result;
use crate::{Dimension, Exceptions};
use super::{SymbolInfo, SymbolInfoLookup, SymbolShapeHint};
@@ -40,13 +41,13 @@ impl<'a> EncoderContext<'_> {
pub fn with_symbol_info_lookup(
msg: &str,
symbol_lookup: Rc<SymbolInfoLookup<'a>>,
) -> Result<EncoderContext<'a>, Exceptions> {
) -> Result<EncoderContext<'a>> {
let mut new_self = EncoderContext::new(msg)?;
new_self.symbol_lookup = symbol_lookup.clone();
Ok(new_self)
}
pub fn new(msg: &str) -> Result<Self, Exceptions> {
pub fn new(msg: &str) -> Result<Self> {
//From this point on Strings are not Unicode anymore!
// let msgBinary = ISO_8859_1_ENCODER.encode(msg, encoding::EncoderTrap::Strict).expect("encode to bytes");//msg.getBytes(StandardCharsets.ISO_8859_1);
// let sb = String::with_capacity(msgBinary.len());

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
use crate::common::Result;
use crate::Exceptions;
use super::SymbolInfo;
@@ -152,7 +153,7 @@ const ALOG: [u32; 255] = {
* @param symbolInfo information about the symbol to be encoded
* @return the codewords with interleaved error correction.
*/
pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String, Exceptions> {
pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String> {
if codewords.chars().count() != symbolInfo.getDataCapacity() as usize {
return Err(Exceptions::illegalArgumentWith(
"The number of codewords does not match the selected symbol",
@@ -217,7 +218,7 @@ pub fn encodeECC200(codewords: &str, symbolInfo: &SymbolInfo) -> Result<String,
Ok(sb)
}
fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String, Exceptions> {
fn createECCBlock(codewords: &str, numECWords: usize) -> Result<String> {
let mut table = -1_isize;
for (i, set) in FACTOR_SETS.iter().enumerate() {
// for i in 0..FACTOR_SETS.len() {

View File

@@ -18,6 +18,7 @@ use std::rc::Rc;
use encoding::{self, EncodingRef};
use crate::common::Result;
use crate::{Dimension, Exceptions};
use super::{
@@ -134,7 +135,7 @@ fn randomize253State(codewordPosition: u32) -> String {
* @param msg the message
* @return the encoded message (the char values range from 0 to 255)
*/
pub fn encodeHighLevel(msg: &str) -> Result<String, Exceptions> {
pub fn encodeHighLevel(msg: &str) -> Result<String> {
encodeHighLevelWithDimensionForceC40(msg, SymbolShapeHint::FORCE_NONE, None, None, false)
}
@@ -148,7 +149,7 @@ pub fn encodeHighLevel(msg: &str) -> Result<String, Exceptions> {
pub fn encodeHighLevelSIL(
msg: &str,
symbol_lookup: Option<Rc<SymbolInfoLookup>>,
) -> Result<String, Exceptions> {
) -> Result<String> {
encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
msg,
SymbolShapeHint::FORCE_NONE,
@@ -175,7 +176,7 @@ pub fn encodeHighLevelWithDimension(
shape: SymbolShapeHint,
minSize: Option<Dimension>,
maxSize: Option<Dimension>,
) -> Result<String, Exceptions> {
) -> Result<String> {
encodeHighLevelWithDimensionForceC40(msg, shape, minSize, maxSize, false)
}
@@ -186,7 +187,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
maxSize: Option<Dimension>,
forceC40: bool,
symbol_lookup: Option<Rc<SymbolInfoLookup>>,
) -> Result<String, Exceptions> {
) -> Result<String> {
//the codewords 0..255 are encoded as Unicode characters
let c40Encoder = Rc::new(C40Encoder::new());
let encoders: [Rc<dyn Encoder>; 6] = [
@@ -280,7 +281,7 @@ pub fn encodeHighLevelWithDimensionForceC40(
minSize: Option<Dimension>,
maxSize: Option<Dimension>,
forceC40: bool,
) -> Result<String, Exceptions> {
) -> Result<String> {
encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
msg, shape, minSize, maxSize, forceC40, None,
)
@@ -604,7 +605,7 @@ pub fn determineConsecutiveDigitCount(msg: &str, startpos: u32) -> u32 {
idx - startpos
}
pub fn illegalCharacter(c: char) -> Result<(), Exceptions> {
pub fn illegalCharacter(c: char) -> Result<()> {
// let hex = Integer.toHexString(c);
// hex = "0000".substring(0, 4 - hex.length()) + hex;
Err(Exceptions::illegalArgumentWith(format!(

View File

@@ -19,7 +19,7 @@ use std::{fmt, rc::Rc};
use encoding::{self, EncodingRef};
use crate::{
common::{ECIInput, MinimalECIInput},
common::{ECIInput, MinimalECIInput, Result},
Exceptions,
};
@@ -134,7 +134,7 @@ fn isInTextShift2Set(ch: char, fnc1: Option<char>) -> bool {
* @param msg the message
* @return the encoded message (the char values range from 0 to 255)
*/
pub fn encodeHighLevel(msg: &str) -> Result<String, Exceptions> {
pub fn encodeHighLevel(msg: &str) -> Result<String> {
encodeHighLevelWithDetails(msg, None, None, SymbolShapeHint::FORCE_NONE)
}
@@ -156,7 +156,7 @@ pub fn encodeHighLevelWithDetails(
priorityCharset: Option<EncodingRef>,
fnc1: Option<char>,
shape: SymbolShapeHint,
) -> Result<String, Exceptions> {
) -> Result<String> {
let mut msg = msg;
let mut macroId = 0;
if msg.starts_with(high_level_encoder::MACRO_05_HEADER)
@@ -201,7 +201,7 @@ fn encode(
fnc1: Option<char>,
shape: SymbolShapeHint,
macroId: i32,
) -> Result<Vec<u8>, Exceptions> {
) -> Result<Vec<u8>> {
Ok(encodeMinimally(Rc::new(Input::new(
input,
priorityCharset,
@@ -213,7 +213,7 @@ fn encode(
.to_vec())
}
fn addEdge(edges: &mut [Vec<Option<Rc<Edge>>>], edge: Rc<Edge>) -> Result<(), Exceptions> {
fn addEdge(edges: &mut [Vec<Option<Rc<Edge>>>], edge: Rc<Edge>) -> Result<()> {
let vertexIndex = (edge.fromPosition + edge.characterLength) as usize;
if edges[vertexIndex][edge.getEndMode()?.ordinal()].is_none()
|| edges[vertexIndex][edge.getEndMode()?.ordinal()]
@@ -239,7 +239,7 @@ fn getNumberOfC40Words(
from: u32,
c40: bool,
characterLength: &mut [u32],
) -> Result<u32, Exceptions> {
) -> Result<u32> {
let mut thirdsCount = 0;
for i in (from as usize)..input.length() {
// for (int i = from; i < input.length(); i++) {
@@ -282,7 +282,7 @@ fn addEdges(
edges: &mut [Vec<Option<Rc<Edge>>>],
from: u32,
previous: Option<Rc<Edge>>,
) -> Result<(), Exceptions> {
) -> Result<()> {
if input.isECI(from)? {
addEdge(
edges,
@@ -409,7 +409,7 @@ fn addEdges(
Ok(())
}
fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult, Exceptions> {
fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult> {
// @SuppressWarnings("checkstyle:lineLength")
/* The minimal encoding is computed by Dijkstra. The acyclic graph is modeled as follows:
* A vertex represents a combination of a position in the input and an encoding mode where position 0
@@ -667,7 +667,7 @@ impl Edge {
fromPosition: u32,
characterLength: u32,
previous: Option<Rc<Edge>>,
) -> Result<Self, Exceptions> {
) -> Result<Self> {
if fromPosition + characterLength > input.length() as u32 {
return Err(Exceptions::format);
}
@@ -804,7 +804,7 @@ impl Edge {
// if previous.is_none() { Mode::ASCII} else {previous.as_ref().unwrap().mode}
}
pub fn getPreviousMode(previous: Option<Rc<Edge>>) -> Result<Mode, Exceptions> {
pub fn getPreviousMode(previous: Option<Rc<Edge>>) -> Result<Mode> {
if let Some(prev) = previous {
prev.getEndMode()
} else {
@@ -819,7 +819,7 @@ impl Edge {
* - Mode is C40, TEXT or X12 and the remaining characters can be encoded in at most 1 ASCII byte.
* Returns mode in all other cases.
* */
pub fn getEndMode(&self) -> Result<Mode, Exceptions> {
pub fn getEndMode(&self) -> Result<Mode> {
let mode = self.mode;
if mode == Mode::Edf {
if self.characterLength < 4 {
@@ -856,7 +856,7 @@ impl Edge {
* two consecutive digits and a non extended character or of 4 digits.
* Returns 0 in any other case
**/
pub fn getLastASCII(&self) -> Result<u32, Exceptions> {
pub fn getLastASCII(&self) -> Result<u32> {
let length = self.input.length() as u32;
let from = self.fromPosition + self.characterLength;
if length - from > 4 || from >= length {
@@ -1000,7 +1000,7 @@ impl Edge {
}
}
pub fn getX12Words(&self) -> Result<Vec<u8>, Exceptions> {
pub fn getX12Words(&self) -> Result<Vec<u8>> {
assert!(self.characterLength % 3 == 0);
let mut result = vec![0u8; self.characterLength as usize / 3 * 2];
let mut i = 0;
@@ -1096,7 +1096,7 @@ impl Edge {
}
}
pub fn getC40Words(&self, c40: bool, fnc1: Option<char>) -> Result<Vec<u8>, Exceptions> {
pub fn getC40Words(&self, c40: bool, fnc1: Option<char>) -> Result<Vec<u8>> {
let mut c40Values: Vec<u8> = Vec::new();
let fromPosition = self.fromPosition as usize;
for i in 0..self.characterLength as usize {
@@ -1156,7 +1156,7 @@ impl Edge {
Ok(result)
}
pub fn getEDFBytes(&self) -> Result<Vec<u8>, Exceptions> {
pub fn getEDFBytes(&self) -> Result<Vec<u8>> {
let numberOfThirds = (self.characterLength as f32 / 4.0).ceil() as usize;
let mut result = vec![0u8; numberOfThirds * 3];
let mut pos = self.fromPosition as usize;
@@ -1190,7 +1190,7 @@ impl Edge {
Ok(result)
}
pub fn getLatchBytes(&self) -> Result<Vec<u8>, Exceptions> {
pub fn getLatchBytes(&self) -> Result<Vec<u8>> {
match Self::getPreviousMode(self.previous.clone())? {
Mode::Ascii | Mode::B256 =>
//after B256 ends (via length) we are back to ASCII
@@ -1224,7 +1224,7 @@ impl Edge {
}
// Important: The function does not return the length bytes (one or two) in case of B256 encoding
pub fn getDataBytes(&self) -> Result<Vec<u8>, Exceptions> {
pub fn getDataBytes(&self) -> Result<Vec<u8>> {
match self.mode {
Mode::Ascii => {
if self.input.isECI(self.fromPosition)? {
@@ -1272,7 +1272,7 @@ struct RXingResult {
bytes: Vec<u8>,
}
impl RXingResult {
pub fn new(solution: Option<Rc<Edge>>) -> Result<Self, Exceptions> {
pub fn new(solution: Option<Rc<Edge>>) -> Result<Self> {
let solution = if let Some(edge) = solution {
edge
} else {
@@ -1427,10 +1427,10 @@ impl Input {
pub fn length(&self) -> usize {
self.internal.length()
}
pub fn isECI(&self, index: u32) -> Result<bool, Exceptions> {
pub fn isECI(&self, index: u32) -> Result<bool> {
self.internal.isECI(index)
}
pub fn charAt(&self, index: usize) -> Result<char, Exceptions> {
pub fn charAt(&self, index: usize) -> Result<char> {
self.internal.charAt(index)
}
pub fn getFNC1Character(&self) -> Option<char> {
@@ -1440,13 +1440,13 @@ impl Input {
Some(self.internal.getFNC1Character() as u8 as char)
}
}
fn haveNCharacters(&self, index: usize, n: usize) -> Result<bool, Exceptions> {
fn haveNCharacters(&self, index: usize, n: usize) -> Result<bool> {
self.internal.haveNCharacters(index, n)
}
fn isFNC1(&self, index: usize) -> Result<bool, Exceptions> {
fn isFNC1(&self, index: usize) -> Result<bool> {
self.internal.isFNC1(index)
}
fn getECIValue(&self, index: usize) -> Result<i32, Exceptions> {
fn getECIValue(&self, index: usize) -> Result<i32> {
self.internal.getECIValue(index)
}
}

View File

@@ -16,6 +16,7 @@
use std::fmt;
use crate::common::Result;
use crate::{Dimension, Exceptions};
use super::SymbolShapeHint;
@@ -122,7 +123,7 @@ impl SymbolInfo {
new_symbol
}
fn getHorizontalDataRegions(&self) -> Result<u32, Exceptions> {
fn getHorizontalDataRegions(&self) -> Result<u32> {
match self.dataRegions {
1 => Ok(1),
2 | 4 => Ok(2),
@@ -134,7 +135,7 @@ impl SymbolInfo {
}
}
fn getVerticalDataRegions(&self) -> Result<u32, Exceptions> {
fn getVerticalDataRegions(&self) -> Result<u32> {
match self.dataRegions {
1 | 2 => Ok(1),
4 => Ok(2),
@@ -146,19 +147,19 @@ impl SymbolInfo {
}
}
pub fn getSymbolDataWidth(&self) -> Result<u32, Exceptions> {
pub fn getSymbolDataWidth(&self) -> Result<u32> {
Ok(self.getHorizontalDataRegions()? * self.matrixWidth)
}
pub fn getSymbolDataHeight(&self) -> Result<u32, Exceptions> {
pub fn getSymbolDataHeight(&self) -> Result<u32> {
Ok(self.getVerticalDataRegions()? * self.matrixHeight)
}
pub fn getSymbolWidth(&self) -> Result<u32, Exceptions> {
pub fn getSymbolWidth(&self) -> Result<u32> {
Ok(self.getSymbolDataWidth()? + (self.getHorizontalDataRegions()? * 2))
}
pub fn getSymbolHeight(&self) -> Result<u32, Exceptions> {
pub fn getSymbolHeight(&self) -> Result<u32> {
Ok(self.getSymbolDataHeight()? + (self.getVerticalDataRegions()? * 2))
}
@@ -236,7 +237,7 @@ impl<'a> SymbolInfoLookup<'a> {
self.0 = Some(override_symbols);
}
pub fn lookup(&self, dataCodewords: u32) -> Result<Option<&'a SymbolInfo>, Exceptions> {
pub fn lookup(&self, dataCodewords: u32) -> Result<Option<&'a SymbolInfo>> {
self.lookup_with_codewords_shape_fail(dataCodewords, SymbolShapeHint::FORCE_NONE, true)
}
@@ -244,7 +245,7 @@ impl<'a> SymbolInfoLookup<'a> {
&self,
dataCodewords: u32,
shape: SymbolShapeHint,
) -> Result<Option<&'a SymbolInfo>, Exceptions> {
) -> Result<Option<&'a SymbolInfo>> {
self.lookup_with_codewords_shape_fail(dataCodewords, shape, true)
}
@@ -253,7 +254,7 @@ impl<'a> SymbolInfoLookup<'a> {
dataCodewords: u32,
allowRectangular: bool,
fail: bool,
) -> Result<Option<&'a SymbolInfo>, Exceptions> {
) -> Result<Option<&'a SymbolInfo>> {
let shape = if allowRectangular {
SymbolShapeHint::FORCE_NONE
} else {
@@ -267,7 +268,7 @@ impl<'a> SymbolInfoLookup<'a> {
dataCodewords: u32,
shape: SymbolShapeHint,
fail: bool,
) -> Result<Option<&'a SymbolInfo>, Exceptions> {
) -> Result<Option<&'a SymbolInfo>> {
self.lookup_with_codewords_shape_size_fail(dataCodewords, shape, &None, &None, fail)
}
@@ -279,7 +280,7 @@ impl<'a> SymbolInfoLookup<'a> {
maxSize: &Option<Dimension>,
fail: bool,
// alternate_symbols_chart: Option<&'a Vec<SymbolInfo>>,
) -> Result<Option<&'a SymbolInfo>, Exceptions> {
) -> Result<Option<&'a SymbolInfo>> {
let symbol_search_chart: &Vec<SymbolInfo> = if self.0.is_none() {
&PROD_SYMBOLS
} else {

View File

@@ -15,6 +15,7 @@
*/
use super::{high_level_encoder, C40Encoder, Encoder};
use crate::common::Result;
pub struct TextEncoder(C40Encoder);
impl Encoder for TextEncoder {
@@ -22,7 +23,7 @@ impl Encoder for TextEncoder {
high_level_encoder::TEXT_ENCODATION
}
fn encode(&self, context: &mut super::EncoderContext) -> Result<(), crate::Exceptions> {
fn encode(&self, context: &mut super::EncoderContext) -> Result<()> {
self.0.encode_with_encode_char_fn(
context,
&Self::encodeChar,

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
use crate::common::Result;
use crate::Exceptions;
use super::{high_level_encoder, C40Encoder, Encoder, EncoderContext};
@@ -24,7 +25,7 @@ impl Encoder for X12Encoder {
high_level_encoder::X12_ENCODATION
}
fn encode(&self, context: &mut super::EncoderContext) -> Result<(), crate::Exceptions> {
fn encode(&self, context: &mut super::EncoderContext) -> Result<()> {
//step C
let mut buffer = String::new();
while context.hasMoreCharacters() {
@@ -58,7 +59,7 @@ impl X12Encoder {
Self(C40Encoder::new())
}
fn encodeChar(c: char, sb: &mut String) -> Result<u32, Exceptions> {
fn encodeChar(c: char, sb: &mut String) -> Result<u32> {
match c {
'\r' => sb.push('\0'),
'*' => sb.push('\u{1}'),
@@ -77,7 +78,7 @@ impl X12Encoder {
Ok(1)
}
fn handleEOD(context: &mut EncoderContext, buffer: &mut str) -> Result<(), Exceptions> {
fn handleEOD(context: &mut EncoderContext, buffer: &mut str) -> Result<()> {
context.updateSymbolInfo();
let available = context
.getSymbolInfo()