continued porting of test cases

This commit is contained in:
Henry Schimke
2023-04-09 18:25:59 -05:00
parent 8a1d0b3969
commit 1900e1ca57
10 changed files with 364 additions and 214 deletions

View File

@@ -2,7 +2,7 @@ use crate::common::Result;
use crate::qrcode::decoder::ErrorCorrectionLevel;
impl ErrorCorrectionLevel {
pub fn ECLevelFromBits(bits: u8, isMicro: bool) -> Self {
pub fn ECLevelFromBitsSigned(bits: i8, isMicro: bool) -> Self {
if (isMicro) {
let LEVEL_FOR_BITS: [ErrorCorrectionLevel; 8] = [
ErrorCorrectionLevel::L,
@@ -24,4 +24,8 @@ impl ErrorCorrectionLevel {
];
return LEVEL_FOR_BITS[bits as usize & 0x3];
}
pub fn ECLevelFromBits(bits: u8, isMicro: bool) -> Self {
Self::ECLevelFromBitsSigned(bits as i8, isMicro)
}
}

View File

@@ -125,4 +125,9 @@ impl FormatInformation {
pub fn isValid(&self) -> bool {
self.hammingDistance <= 3
}
pub fn cpp_eq(&self, other: &Self) -> bool {
self.data_mask == other.data_mask
&& self.error_correction_level == other.error_correction_level
}
}

View File

@@ -200,3 +200,32 @@ where
// }
}
impl<T> DecoderResult<T>
where
T: Copy + Clone + Default + Eq + PartialEq,
{
pub fn text(&self) -> String {
self.content.to_string()
}
pub fn symbologyIdentifier(&self) -> String {
let s = self.content.symbology;
if s.code > 0 {
format!(
"]{}{}",
vec!['1'; s.code as usize].into_iter().collect::<String>(),
char::from(
s.modifier
+ if self.content.is_eci {
s.eciModifierOffset
} else {
0
}
)
)
} else {
String::default()
}
}
}

View File

@@ -32,7 +32,7 @@ use super::{CharacterSet, Eci};
*/
#[derive(Default, PartialEq, Eq, Debug, Clone)]
pub struct ECIStringBuilder {
is_eci: bool,
pub is_eci: bool,
eci_result: Option<String>,
bytes: Vec<u8>,
eci_positions: Vec<(Eci, usize, usize)>, // (Eci, start, end)