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

@@ -15,7 +15,7 @@
*/
use crate::{
common::{BitSource, CharacterSetECI, DecoderRXingResult, StringUtils},
common::{BitSource, CharacterSetECI, DecoderRXingResult, Result, StringUtils},
DecodingHintDictionary, Exceptions,
};
@@ -44,7 +44,7 @@ pub fn decode(
version: VersionRef,
ecLevel: ErrorCorrectionLevel,
hints: &DecodingHintDictionary,
) -> Result<DecoderRXingResult, Exceptions> {
) -> Result<DecoderRXingResult> {
let mut bits = BitSource::new(bytes.to_owned());
let mut result = String::with_capacity(50);
let mut byteSegments = vec![vec![0u8; 0]; 0];
@@ -174,11 +174,7 @@ pub fn decode(
/**
* See specification GBT 18284-2000
*/
fn decodeHanziSegment(
bits: &mut BitSource,
result: &mut String,
count: usize,
) -> Result<(), Exceptions> {
fn decodeHanziSegment(bits: &mut BitSource, result: &mut String, count: usize) -> Result<()> {
// Don't crash trying to read more bits than we have available.
if count * 13 > bits.available() {
return Err(Exceptions::format);
@@ -222,7 +218,7 @@ fn decodeKanjiSegment(
count: usize,
currentCharacterSetECI: Option<CharacterSetECI>,
hints: &DecodingHintDictionary,
) -> Result<(), Exceptions> {
) -> Result<()> {
// Don't crash trying to read more bits than we have available.
if count * 13 > bits.available() {
return Err(Exceptions::format);
@@ -286,7 +282,7 @@ fn decodeByteSegment(
currentCharacterSetECI: Option<CharacterSetECI>,
byteSegments: &mut Vec<Vec<u8>>,
hints: &DecodingHintDictionary,
) -> Result<(), Exceptions> {
) -> Result<()> {
// Don't crash trying to read more bits than we have available.
if 8 * count > bits.available() {
return Err(Exceptions::format);
@@ -350,7 +346,7 @@ fn decodeByteSegment(
Ok(())
}
fn toAlphaNumericChar(value: u32) -> Result<char, Exceptions> {
fn toAlphaNumericChar(value: u32) -> Result<char> {
if value as usize >= ALPHANUMERIC_CHARS.len() {
return Err(Exceptions::format);
}
@@ -366,7 +362,7 @@ fn decodeAlphanumericSegment(
result: &mut String,
count: usize,
fc1InEffect: bool,
) -> Result<(), Exceptions> {
) -> Result<()> {
// Read two characters at a time
let start = result.len();
let mut count = count;
@@ -411,11 +407,7 @@ fn decodeAlphanumericSegment(
Ok(())
}
fn decodeNumericSegment(
bits: &mut BitSource,
result: &mut String,
count: usize,
) -> Result<(), Exceptions> {
fn decodeNumericSegment(bits: &mut BitSource, result: &mut String, count: usize) -> Result<()> {
let mut count = count;
// Read three digits at a time
while count >= 3 {
@@ -458,7 +450,7 @@ fn decodeNumericSegment(
Ok(())
}
fn parseECIValue(bits: &mut BitSource) -> Result<u32, Exceptions> {
fn parseECIValue(bits: &mut BitSource) -> Result<u32> {
let firstByte = bits.readBits(8)?;
if (firstByte & 0x80) == 0 {
// just one byte