fix errant has_eci

This commit is contained in:
Henry Schimke
2023-04-24 18:16:48 -05:00
parent 483539a194
commit 31413b3044
3 changed files with 20 additions and 3 deletions

View File

@@ -51,6 +51,9 @@ where
pub fn with_eci_string_builder(src: ECIStringBuilder) -> Self { pub fn with_eci_string_builder(src: ECIStringBuilder) -> Self {
let mut new_self = Self::default(); let mut new_self = Self::default();
new_self.content = src; new_self.content = src;
new_self new_self
} }

View File

@@ -6,7 +6,7 @@ use super::CharacterSet;
use crate::common::Result; use crate::common::Result;
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Eci { pub enum Eci {
Unknown = -1, Unknown = -1,
Cp437 = 2, // obsolete Cp437 = 2, // obsolete

View File

@@ -22,11 +22,11 @@
// import java.nio.charset.StandardCharsets; // import java.nio.charset.StandardCharsets;
use std::{ use std::{
collections::HashMap, collections::{HashMap, HashSet},
fmt::{self, Display}, fmt::{self, Display},
}; };
use crate::BarcodeFormat; use crate::{pdf417::decoder::ec, BarcodeFormat};
use super::{CharacterSet, Eci, StringUtils}; use super::{CharacterSet, Eci, StringUtils};
@@ -125,6 +125,12 @@ impl ECIStringBuilder {
} }
self.eci_positions.push((eci, self.bytes.len(), 0)); self.eci_positions.push((eci, self.bytes.len(), 0));
let ecis = self.list_ecis();
if ecis.len() <= 1 && (ecis.contains(&Eci::Unknown)) {
self.has_eci = false;
}
} }
} }
@@ -263,6 +269,14 @@ impl ECIStringBuilder {
self self
} }
pub fn list_ecis(&self) -> HashSet<Eci> {
let mut hs = HashSet::new();
self.eci_positions.iter().for_each(|pos| {
hs.insert(pos.0);
});
hs
}
} }
impl fmt::Display for ECIStringBuilder { impl fmt::Display for ECIStringBuilder {