mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
repurpose CharacterSetECI as encoding abstraction
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use crate::{
|
||||
aztec::{
|
||||
aztec_detector_result::AztecDetectorRXingResult,
|
||||
@@ -25,7 +23,7 @@ use crate::{
|
||||
encoder::HighLevelEncoder,
|
||||
shared_test_methods::{stripSpace, toBitArray, toBooleanArray},
|
||||
},
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Point,
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Point, common::CharacterSetECI,
|
||||
};
|
||||
|
||||
use super::{encoder::aztec_encoder, AztecWriter};
|
||||
@@ -34,8 +32,6 @@ use crate::Writer;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
use encoding::Encoding;
|
||||
|
||||
/**
|
||||
* Aztec 2D generator unit tests.
|
||||
*
|
||||
@@ -43,10 +39,10 @@ use encoding::Encoding;
|
||||
* @author Frank Yellin
|
||||
*/
|
||||
|
||||
const ISO_8859_1: EncodingRef = encoding::all::ISO_8859_1; //StandardCharsets.ISO_8859_1;
|
||||
const UTF_8: EncodingRef = encoding::all::UTF_8; //StandardCharsets.UTF_8;
|
||||
const ISO_8859_15: EncodingRef = encoding::all::ISO_8859_15; //Charset.forName("ISO-8859-15");
|
||||
const WINDOWS_1252: EncodingRef = encoding::all::WINDOWS_1252; //Charset.forName("Windows-1252");
|
||||
const ISO_8859_1: CharacterSetECI = CharacterSetECI::ISO8859_1; //StandardCharsets.ISO_8859_1;
|
||||
const UTF_8: CharacterSetECI = CharacterSetECI::UTF8; //StandardCharsets.UTF_8;
|
||||
const ISO_8859_15: CharacterSetECI = CharacterSetECI::ISO8859_15; //Charset.forName("ISO-8859-15");
|
||||
const WINDOWS_1252: CharacterSetECI = CharacterSetECI::Cp1252; //Charset.forName("Windows-1252");
|
||||
|
||||
// const DOTX: &str = "[^.X]";
|
||||
// const SPACES: &str = "\\s+";
|
||||
@@ -140,8 +136,9 @@ X X X X X X X X X X X X X
|
||||
|
||||
#[test]
|
||||
fn testAztecWriter() {
|
||||
let shift_jis: EncodingRef =
|
||||
encoding::label::encoding_from_whatwg_label("Shift_JIS").expect("must exist");
|
||||
let shift_jis: CharacterSetECI =
|
||||
CharacterSetECI::getCharacterSetECIByName("Shift_JIS").expect("must exist");
|
||||
|
||||
testWriter("Espa\u{00F1}ol", None, 25, true, 1); // Without ECI (implicit ISO-8859-1)
|
||||
testWriter("Espa\u{00F1}ol", Some(ISO_8859_1), 25, true, 1); // Explicit ISO-8859-1
|
||||
testWriter("\u{20AC} 1 sample data.", Some(WINDOWS_1252), 25, true, 2); // ISO-8859-1 can't encode Euro; Windows-1252 can
|
||||
@@ -150,7 +147,7 @@ fn testAztecWriter() {
|
||||
testWriter("\u{20AC} 1 sample data.", Some(ISO_8859_15), 0, true, 2);
|
||||
testWriter(
|
||||
"\u{20AC} 1 sample data.",
|
||||
Some(encoding::all::UTF_16BE),
|
||||
Some(CharacterSetECI::UnicodeBigUnmarked),
|
||||
0,
|
||||
true,
|
||||
3,
|
||||
@@ -711,7 +708,7 @@ fn testEncodeDecode(data: &str, compact: bool, layers: u32) {
|
||||
|
||||
fn testWriter(
|
||||
data: &str,
|
||||
charset: Option<EncodingRef>,
|
||||
charset: Option<CharacterSetECI>,
|
||||
ecc_percent: u32,
|
||||
compact: bool,
|
||||
layers: u32,
|
||||
@@ -721,7 +718,7 @@ fn testWriter(
|
||||
if charset.is_some() {
|
||||
hints.insert(
|
||||
EncodeHintType::CHARACTER_SET,
|
||||
EncodeHintValue::CharacterSet(charset.unwrap().name().to_owned()),
|
||||
EncodeHintValue::CharacterSet(charset.unwrap().getCharsetName().to_string()),
|
||||
);
|
||||
}
|
||||
// if (null != charset) {
|
||||
@@ -737,7 +734,7 @@ fn testWriter(
|
||||
|
||||
let cset = match charset {
|
||||
Some(cs) => cs,
|
||||
None => encoding::all::ISO_8859_1,
|
||||
None => CharacterSetECI::ISO8859_1,
|
||||
};
|
||||
let aztec = aztec_encoder::encode_with_charset(
|
||||
data,
|
||||
@@ -820,10 +817,8 @@ fn testStuffBits(wordSize: usize, bits: &str, expected: &str) {
|
||||
|
||||
fn testHighLevelEncodeStringUtf8(s: &str, expectedBits: &str) {
|
||||
let bits = HighLevelEncoder::with_charset(
|
||||
encoding::all::UTF_8
|
||||
.encode(s, encoding::EncoderTrap::Strict)
|
||||
.expect("should encode to bytes"),
|
||||
encoding::all::UTF_8,
|
||||
CharacterSetECI::UTF8.encode(s).expect("should encode to bytes"),
|
||||
CharacterSetECI::UTF8,
|
||||
)
|
||||
.encode()
|
||||
.expect("high level ok");
|
||||
@@ -843,9 +838,7 @@ fn testHighLevelEncodeStringUtf8(s: &str, expectedBits: &str) {
|
||||
|
||||
fn testHighLevelEncodeString(s: &str, expectedBits: &str) {
|
||||
let bits = HighLevelEncoder::new(
|
||||
encoding::all::ISO_8859_1
|
||||
.encode(s, encoding::EncoderTrap::Strict)
|
||||
.expect("should encode to bytes"),
|
||||
CharacterSetECI::ISO8859_1.encode(s).expect("should encode to bytes"),
|
||||
)
|
||||
.encode()
|
||||
.expect("high level ok");
|
||||
@@ -864,9 +857,7 @@ fn testHighLevelEncodeString(s: &str, expectedBits: &str) {
|
||||
|
||||
fn testHighLevelEncodeStringCount(s: &str, expectedReceivedBits: u32) {
|
||||
let bits = HighLevelEncoder::new(
|
||||
encoding::all::ISO_8859_1
|
||||
.encode(s, encoding::EncoderTrap::Strict)
|
||||
.expect("should encode to bytes"),
|
||||
CharacterSetECI::ISO8859_1.encode(s).expect("should encode to bytes"),
|
||||
)
|
||||
.encode()
|
||||
.expect("high level ok");
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use crate::{
|
||||
common::{BitMatrix, Result},
|
||||
common::{BitMatrix, Result, CharacterSetECI},
|
||||
exceptions::Exceptions,
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Writer,
|
||||
};
|
||||
@@ -58,10 +56,7 @@ impl Writer for AztecWriter {
|
||||
hints.get(&EncodeHintType::CHARACTER_SET)
|
||||
{
|
||||
if cset_name.to_lowercase() != "iso-8859-1" {
|
||||
charset = Some(
|
||||
encoding::label::encoding_from_whatwg_label(cset_name)
|
||||
.ok_or(Exceptions::ILLEGAL_ARGUMENT)?,
|
||||
);
|
||||
charset = CharacterSetECI::getCharacterSetECIByName(cset_name);
|
||||
}
|
||||
}
|
||||
if let Some(EncodeHintValue::ErrorCorrection(ecc_level)) =
|
||||
@@ -91,7 +86,7 @@ fn encode(
|
||||
format: BarcodeFormat,
|
||||
width: u32,
|
||||
height: u32,
|
||||
charset: Option<EncodingRef>,
|
||||
charset: Option<CharacterSetECI>,
|
||||
ecc_percent: u32,
|
||||
layers: i32,
|
||||
) -> Result<BitMatrix> {
|
||||
|
||||
@@ -113,8 +113,8 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
|
||||
// Intermediary buffer of decoded bytes, which is decoded into a string and flushed
|
||||
// when character encoding changes (ECI) or input ends.
|
||||
let mut decoded_bytes: Vec<u8> = Vec::new();
|
||||
// let mut encdr: &'static dyn encoding::Encoding = encoding::all::UTF_8;
|
||||
let mut encdr: encoding::EncodingRef = encoding::all::ISO_8859_1;
|
||||
|
||||
let mut encdr: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
||||
|
||||
let mut index = 0;
|
||||
|
||||
@@ -161,8 +161,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
|
||||
// flush bytes, FLG changes state
|
||||
result.push_str(
|
||||
&encdr
|
||||
.decode(&decoded_bytes, encoding::DecoderTrap::Strict)
|
||||
.map_err(Exceptions::illegal_state_with)?,
|
||||
.decode(&decoded_bytes)?,
|
||||
);
|
||||
|
||||
decoded_bytes.clear();
|
||||
@@ -190,7 +189,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
|
||||
if charset_eci.is_err() {
|
||||
return Err(Exceptions::format_with("Charset must exist"));
|
||||
}
|
||||
encdr = CharacterSetECI::getCharset(&charset_eci?);
|
||||
encdr = charset_eci?;
|
||||
}
|
||||
}
|
||||
// Go back to whatever mode we had been in
|
||||
@@ -207,7 +206,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
|
||||
}
|
||||
} else {
|
||||
// Though stored as a table of strings for convenience, codes actually represent 1 or 2 *bytes*.
|
||||
// let b = encoding::all::ASCII.encode(str, encoding::EncoderTrap::Strict).unwrap();
|
||||
|
||||
let b = str.as_bytes();
|
||||
//let b = str.getBytes(StandardCharsets.US_ASCII);
|
||||
//decodedBytes.write(b, 0, b.length);
|
||||
@@ -220,7 +219,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
|
||||
}
|
||||
}
|
||||
//try {
|
||||
if let Ok(str) = encdr.decode(&decoded_bytes, encoding::DecoderTrap::Strict) {
|
||||
if let Ok(str) = encdr.decode(&decoded_bytes) {
|
||||
result.push_str(&str);
|
||||
} else {
|
||||
return Err(Exceptions::illegal_state_with("bad encoding"));
|
||||
|
||||
@@ -14,14 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use encoding::Encoding;
|
||||
|
||||
use crate::{
|
||||
common::{
|
||||
reedsolomon::{
|
||||
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonEncoder,
|
||||
},
|
||||
BitArray, BitMatrix, Result,
|
||||
BitArray, BitMatrix, Result, CharacterSetECI,
|
||||
},
|
||||
exceptions::Exceptions,
|
||||
};
|
||||
@@ -51,10 +49,9 @@ pub const WORD_SIZE: [u32; 33] = [
|
||||
* @return Aztec symbol matrix with metadata
|
||||
*/
|
||||
pub fn encode_simple(data: &str) -> Result<AztecCode> {
|
||||
let Ok(bytes) = encoding::all::ISO_8859_1
|
||||
.encode(data, encoding::EncoderTrap::Replace) else {
|
||||
return Err(Exceptions::illegal_argument_with(format!("'{data}' cannot be encoded as ISO_8859_1")));
|
||||
};
|
||||
let Ok(bytes) =CharacterSetECI::ISO8859_1.encode_replace(data) else {
|
||||
return Err(Exceptions::illegal_argument_with(format!("'{data}' cannot be encoded as ISO_8859_1")));
|
||||
};
|
||||
encode_bytes_simple(&bytes)
|
||||
}
|
||||
|
||||
@@ -68,7 +65,7 @@ pub fn encode_simple(data: &str) -> Result<AztecCode> {
|
||||
* @return Aztec symbol matrix with metadata
|
||||
*/
|
||||
pub fn encode(data: &str, minECCPercent: u32, userSpecifiedLayers: i32) -> Result<AztecCode> {
|
||||
if let Ok(bytes) = encoding::all::ISO_8859_1.encode(data, encoding::EncoderTrap::Strict) {
|
||||
if let Ok(bytes) = CharacterSetECI::ISO8859_1.encode(data) {
|
||||
encode_bytes(&bytes, minECCPercent, userSpecifiedLayers)
|
||||
} else {
|
||||
Err(Exceptions::illegal_argument_with(format!(
|
||||
@@ -93,9 +90,9 @@ pub fn encode_with_charset(
|
||||
data: &str,
|
||||
minECCPercent: u32,
|
||||
userSpecifiedLayers: i32,
|
||||
charset: encoding::EncodingRef,
|
||||
charset: CharacterSetECI,
|
||||
) -> Result<AztecCode> {
|
||||
if let Ok(bytes) = charset.encode(data, encoding::EncoderTrap::Strict) {
|
||||
if let Ok(bytes) = charset.encode(data) {
|
||||
encode_bytes_with_charset(&bytes, minECCPercent, userSpecifiedLayers, charset)
|
||||
} else {
|
||||
Err(Exceptions::illegal_argument_with(format!(
|
||||
@@ -132,7 +129,7 @@ pub fn encode_bytes(
|
||||
data,
|
||||
minECCPercent,
|
||||
userSpecifiedLayers,
|
||||
encoding::all::ISO_8859_1,
|
||||
CharacterSetECI::ISO8859_1,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -151,7 +148,7 @@ pub fn encode_bytes_with_charset(
|
||||
data: &[u8],
|
||||
min_eccpercent: u32,
|
||||
user_specified_layers: i32,
|
||||
charset: encoding::EncodingRef,
|
||||
charset: CharacterSetECI,
|
||||
) -> Result<AztecCode> {
|
||||
// High-level encode
|
||||
let bits = HighLevelEncoder::with_charset(data.into(), charset).encode()?;
|
||||
|
||||
@@ -35,7 +35,7 @@ use super::{State, Token};
|
||||
*/
|
||||
pub struct HighLevelEncoder {
|
||||
text: Vec<u8>,
|
||||
charset: encoding::EncodingRef,
|
||||
charset: CharacterSetECI,
|
||||
}
|
||||
|
||||
impl HighLevelEncoder {
|
||||
@@ -229,11 +229,11 @@ impl HighLevelEncoder {
|
||||
pub fn new(text: Vec<u8>) -> Self {
|
||||
Self {
|
||||
text,
|
||||
charset: encoding::all::ISO_8859_1,
|
||||
charset: CharacterSetECI::ISO8859_1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_charset(text: Vec<u8>, charset: encoding::EncodingRef) -> Self {
|
||||
pub fn with_charset(text: Vec<u8>, charset: CharacterSetECI) -> Self {
|
||||
Self { text, charset }
|
||||
}
|
||||
|
||||
@@ -242,16 +242,16 @@ impl HighLevelEncoder {
|
||||
*/
|
||||
pub fn encode(&self) -> Result<BitArray> {
|
||||
let mut initial_state = State::new(Token::new(), Self::MODE_UPPER as u32, 0, 0);
|
||||
if let Some(eci) = CharacterSetECI::getCharacterSetECI(self.charset) {
|
||||
if eci != CharacterSetECI::ISO8859_1 {
|
||||
//if let Some(eci) = CharacterSetECI::getCharacterSetECI(self.charset) {
|
||||
if self.charset != CharacterSetECI::ISO8859_1 {
|
||||
//} && eci != CharacterSetECI::Cp1252 {
|
||||
initial_state = initial_state.appendFLGn(CharacterSetECI::getValue(&eci))?;
|
||||
initial_state = initial_state.appendFLGn(self.charset.getValue())?;
|
||||
}
|
||||
} else {
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"No ECI code for character set",
|
||||
));
|
||||
}
|
||||
// } else {
|
||||
// return Err(Exceptions::illegal_argument_with(
|
||||
// "No ECI code for character set",
|
||||
// ));
|
||||
// }
|
||||
// if self.charset != null {
|
||||
// CharacterSetECI eci = CharacterSetECI.getCharacterSetECI(charset);
|
||||
// if (null == eci) {
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use encoding::Encoding;
|
||||
|
||||
use crate::{
|
||||
common::{BitArray, Result},
|
||||
common::{BitArray, Result, CharacterSetECI},
|
||||
exceptions::Exceptions,
|
||||
};
|
||||
|
||||
@@ -88,8 +86,8 @@ impl State {
|
||||
));
|
||||
// throw new IllegalArgumentException("ECI code must be between 0 and 999999");
|
||||
} else {
|
||||
let Ok(eci_digits) = encoding::all::ISO_8859_1
|
||||
.encode(&format!("{eci}"), encoding::EncoderTrap::Strict)
|
||||
let Ok(eci_digits) = CharacterSetECI::ISO8859_1
|
||||
.encode(&format!("{eci}"))
|
||||
else {
|
||||
return Err(Exceptions::ILLEGAL_ARGUMENT)
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ use regex::Regex;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::RXingResult;
|
||||
use crate::{RXingResult, common::CharacterSetECI};
|
||||
|
||||
use uriparse::URI;
|
||||
|
||||
@@ -404,9 +404,9 @@ fn maybeAppendFragment(fragmentBuffer: &mut Vec<u8>, charset: &str, result: &mut
|
||||
if charset.is_empty() {
|
||||
fragment = String::from_utf8(fragmentBytes).unwrap_or_else(|_| String::default());
|
||||
// fragment = new String(fragmentBytes, StandardCharsets.UTF_8);
|
||||
} else if let Some(enc) = encoding::label::encoding_from_whatwg_label(charset) {
|
||||
} else if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(charset) {
|
||||
fragment = if let Ok(encoded_result) =
|
||||
enc.decode(&fragmentBytes, encoding::DecoderTrap::Strict)
|
||||
enc.decode(&fragmentBytes)
|
||||
{
|
||||
encoded_result
|
||||
} else {
|
||||
|
||||
@@ -23,12 +23,13 @@
|
||||
// import java.nio.charset.StandardCharsets;
|
||||
// import java.util.Random;
|
||||
|
||||
use encoding::{Encoding, EncodingRef};
|
||||
use rand::Rng;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::common::StringUtils;
|
||||
|
||||
use super::CharacterSetECI;
|
||||
|
||||
#[test]
|
||||
fn test_random() {
|
||||
let mut r = rand::thread_rng();
|
||||
@@ -38,10 +39,9 @@ fn test_random() {
|
||||
// *byte = r.gen();
|
||||
// }
|
||||
assert_eq!(
|
||||
encoding::all::UTF_8.name(),
|
||||
CharacterSetECI::UTF8,
|
||||
StringUtils::guessCharset(&bytes, &HashMap::new())
|
||||
.unwrap()
|
||||
.name()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ fn test_short_shift_jis1() {
|
||||
// 金魚
|
||||
do_test(
|
||||
&[0x8b, 0xe0, 0x8b, 0x9b],
|
||||
encoding::label::encoding_from_whatwg_label("SJIS").unwrap(),
|
||||
CharacterSetECI::SJIS,
|
||||
"SJIS",
|
||||
);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ fn test_short_shift_jis1() {
|
||||
#[test]
|
||||
fn test_short_iso885911() {
|
||||
// båd
|
||||
do_test(&[0x62, 0xe5, 0x64], encoding::all::ISO_8859_1, "ISO8859_1");
|
||||
do_test(&[0x62, 0xe5, 0x64], CharacterSetECI::ISO8859_1, "ISO8859_1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -66,7 +66,7 @@ fn test_short_utf8() {
|
||||
// Español
|
||||
do_test(
|
||||
&[0x45, 0x73, 0x70, 0x61, 0xc3, 0xb1, 0x6f, 0x6c],
|
||||
encoding::all::UTF_8,
|
||||
CharacterSetECI::UTF8,
|
||||
"UTF8",
|
||||
);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ fn test_mixed_shift_jis1() {
|
||||
// Hello 金!
|
||||
do_test(
|
||||
&[0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x8b, 0xe0, 0x21],
|
||||
encoding::label::encoding_from_whatwg_label("SJIS").unwrap(),
|
||||
CharacterSetECI::SJIS,
|
||||
"SJIS",
|
||||
);
|
||||
}
|
||||
@@ -86,8 +86,8 @@ fn test_utf16_be() {
|
||||
// 调压柜
|
||||
do_test(
|
||||
&[0xFE, 0xFF, 0x8c, 0x03, 0x53, 0x8b, 0x67, 0xdc],
|
||||
encoding::all::UTF_16BE,
|
||||
encoding::all::UTF_16BE.name(),
|
||||
CharacterSetECI::UnicodeBigUnmarked,
|
||||
&CharacterSetECI::UnicodeBigUnmarked.getCharsetName(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -96,15 +96,15 @@ fn test_utf16_le() {
|
||||
// 调压柜
|
||||
do_test(
|
||||
&[0xFF, 0xFE, 0x03, 0x8c, 0x8b, 0x53, 0xdc, 0x67],
|
||||
encoding::all::UTF_16LE,
|
||||
encoding::all::UTF_16LE.name(),
|
||||
CharacterSetECI::UTF16LE,
|
||||
&CharacterSetECI::UTF16LE.getCharsetName(),
|
||||
);
|
||||
}
|
||||
|
||||
fn do_test(bytes: &[u8], charset: EncodingRef, encoding: &str) {
|
||||
fn do_test(bytes: &[u8], charset: CharacterSetECI, encoding: &str) {
|
||||
let guessedCharset = StringUtils::guessCharset(bytes, &HashMap::new()).unwrap();
|
||||
let guessedEncoding = StringUtils::guessEncoding(bytes, &HashMap::new()).unwrap();
|
||||
assert_eq!(charset.name(), guessedCharset.name());
|
||||
assert_eq!(charset, guessedCharset);
|
||||
assert_eq!(encoding, guessedEncoding);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,15 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// package com.google.zxing.common;
|
||||
|
||||
// import com.google.zxing.FormatException;
|
||||
|
||||
// import java.nio.charset.Charset;
|
||||
|
||||
// import java.util.HashMap;
|
||||
// import java.util.Map;
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use crate::common::Result;
|
||||
@@ -59,6 +50,7 @@ pub enum CharacterSetECI {
|
||||
Cp1252, //(23, "windows-1252"),
|
||||
Cp1256, //(24, "windows-1256"),
|
||||
UnicodeBigUnmarked, //(25, "UTF-16BE", "UnicodeBig"),
|
||||
UTF16LE,
|
||||
UTF8, //(26, "UTF-8"),
|
||||
ASCII, //(new int[] {27, 170}, "US-ASCII"),
|
||||
Big5, //(28),
|
||||
@@ -101,8 +93,8 @@ impl CharacterSetECI {
|
||||
Self::getValue(self)
|
||||
}
|
||||
|
||||
pub fn getValue(cs_eci: &CharacterSetECI) -> u32 {
|
||||
match cs_eci {
|
||||
pub fn getValue(&self) -> u32 {
|
||||
match self {
|
||||
CharacterSetECI::Cp437 => 0,
|
||||
CharacterSetECI::ISO8859_1 => 1,
|
||||
CharacterSetECI::ISO8859_2 => 4,
|
||||
@@ -125,6 +117,7 @@ impl CharacterSetECI {
|
||||
CharacterSetECI::Cp1252 => 23,
|
||||
CharacterSetECI::Cp1256 => 24,
|
||||
CharacterSetECI::UnicodeBigUnmarked => 25,
|
||||
CharacterSetECI::UTF16LE => 100025,
|
||||
CharacterSetECI::UTF8 => 26,
|
||||
CharacterSetECI::ASCII => 27,
|
||||
CharacterSetECI::Big5 => 28,
|
||||
@@ -136,8 +129,8 @@ impl CharacterSetECI {
|
||||
pub fn getCharset(&self, ) -> EncodingRef {
|
||||
let name = match self {
|
||||
// CharacterSetECI::Cp437 => "CP437",
|
||||
CharacterSetECI::Cp437 => "UTF-8",
|
||||
CharacterSetECI::ISO8859_1 => "ISO-8859-1",
|
||||
CharacterSetECI::Cp437 => "cp437",
|
||||
CharacterSetECI::ISO8859_1 => return encoding::all::ISO_8859_1,
|
||||
CharacterSetECI::ISO8859_2 => "ISO-8859-2",
|
||||
CharacterSetECI::ISO8859_3 => "ISO-8859-3",
|
||||
CharacterSetECI::ISO8859_4 => "ISO-8859-4",
|
||||
@@ -152,12 +145,13 @@ impl CharacterSetECI {
|
||||
// CharacterSetECI::ISO8859_14 => "ISO-8859-14",
|
||||
CharacterSetECI::ISO8859_15 => "ISO-8859-15",
|
||||
CharacterSetECI::ISO8859_16 => "ISO-8859-16",
|
||||
CharacterSetECI::SJIS => "Shift_JIS",
|
||||
CharacterSetECI::SJIS => "shift_jis",
|
||||
CharacterSetECI::Cp1250 => "windows-1250",
|
||||
CharacterSetECI::Cp1251 => "windows-1251",
|
||||
CharacterSetECI::Cp1252 => "windows-1252",
|
||||
CharacterSetECI::Cp1256 => "windows-1256",
|
||||
CharacterSetECI::UnicodeBigUnmarked => "UTF-16BE",
|
||||
CharacterSetECI::UTF16LE => "UTF-16LE",
|
||||
CharacterSetECI::UTF8 => "UTF-8",
|
||||
CharacterSetECI::ASCII => "US-ASCII",
|
||||
CharacterSetECI::Big5 => "Big5",
|
||||
@@ -167,6 +161,41 @@ impl CharacterSetECI {
|
||||
encoding::label::encoding_from_whatwg_label(name).unwrap()
|
||||
}
|
||||
|
||||
pub fn getCharsetName(&self, ) -> &'static str {
|
||||
match self {
|
||||
// CharacterSetECI::Cp437 => "CP437",
|
||||
CharacterSetECI::Cp437 => "cp437",
|
||||
CharacterSetECI::ISO8859_1 => "iso-8859-1",
|
||||
CharacterSetECI::ISO8859_2 => "iso-8859-2",
|
||||
CharacterSetECI::ISO8859_3 => "iso-8859-3",
|
||||
CharacterSetECI::ISO8859_4 => "iso-8859-4",
|
||||
CharacterSetECI::ISO8859_5 => "iso-8859-5",
|
||||
// CharacterSetECI::ISO8859_6 => "ISO-8859-6",
|
||||
CharacterSetECI::ISO8859_7 => "iso-8859-7",
|
||||
// CharacterSetECI::ISO8859_8 => "ISO-8859-8",
|
||||
CharacterSetECI::ISO8859_9 => "iso-8859-9",
|
||||
// CharacterSetECI::ISO8859_10 => "ISO-8859-10",
|
||||
// CharacterSetECI::ISO8859_11 => "ISO-8859-11",
|
||||
CharacterSetECI::ISO8859_13 => "iso-8859-13",
|
||||
// CharacterSetECI::ISO8859_14 => "ISO-8859-14",
|
||||
CharacterSetECI::ISO8859_15 => "iso-8859-15",
|
||||
CharacterSetECI::ISO8859_16 => "iso-8859-16",
|
||||
CharacterSetECI::SJIS => "shift_jis",
|
||||
CharacterSetECI::Cp1250 => "windows-1250",
|
||||
CharacterSetECI::Cp1251 => "windows-1251",
|
||||
CharacterSetECI::Cp1252 => "windows-1252",
|
||||
CharacterSetECI::Cp1256 => "windows-1256",
|
||||
CharacterSetECI::UnicodeBigUnmarked => "utf-16be",
|
||||
CharacterSetECI::UTF16LE => "utf-16le",
|
||||
CharacterSetECI::UTF8 => "utf-8",
|
||||
CharacterSetECI::ASCII => "us-ascii",
|
||||
CharacterSetECI::Big5 => "big5",
|
||||
CharacterSetECI::GB18030 => "gb2312",
|
||||
CharacterSetECI::EUC_KR => "euc-kr",
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param charset Java character set object
|
||||
* @return CharacterSetECI representing ECI for character encoding, or null if it is legal
|
||||
@@ -179,7 +208,7 @@ impl CharacterSetECI {
|
||||
charset.name()
|
||||
};
|
||||
match name {
|
||||
"CP437" => Some(CharacterSetECI::Cp437),
|
||||
"cp437" => Some(CharacterSetECI::Cp437),
|
||||
"iso-8859-1" => Some(CharacterSetECI::ISO8859_1),
|
||||
"iso-8859-2" => Some(CharacterSetECI::ISO8859_2),
|
||||
"iso-8859-3" => Some(CharacterSetECI::ISO8859_3),
|
||||
@@ -201,7 +230,7 @@ impl CharacterSetECI {
|
||||
"windows-1252" => Some(CharacterSetECI::Cp1252),
|
||||
"windows-1256" => Some(CharacterSetECI::Cp1256),
|
||||
"utf-16be" => Some(CharacterSetECI::UnicodeBigUnmarked),
|
||||
"utf-8" => Some(CharacterSetECI::UTF8),
|
||||
"utf-8" | "utf8" => Some(CharacterSetECI::UTF8),
|
||||
"us-ascii" => Some(CharacterSetECI::ASCII),
|
||||
"big5" => Some(CharacterSetECI::Big5),
|
||||
"gb2312" => Some(CharacterSetECI::GB18030),
|
||||
@@ -255,34 +284,34 @@ impl CharacterSetECI {
|
||||
* but unsupported
|
||||
*/
|
||||
pub fn getCharacterSetECIByName(name: &str) -> Option<CharacterSetECI> {
|
||||
match name {
|
||||
"CP437" => Some(CharacterSetECI::Cp437),
|
||||
"ISO-8859-1" => Some(CharacterSetECI::ISO8859_1),
|
||||
"ISO-8859-2" => Some(CharacterSetECI::ISO8859_2),
|
||||
"ISO-8859-3" => Some(CharacterSetECI::ISO8859_3),
|
||||
"ISO-8859-4" => Some(CharacterSetECI::ISO8859_4),
|
||||
"ISO-8859-5" => Some(CharacterSetECI::ISO8859_5),
|
||||
match name.to_lowercase().as_str() {
|
||||
"cp437" => Some(CharacterSetECI::Cp437),
|
||||
"iso-8859-1" => Some(CharacterSetECI::ISO8859_1),
|
||||
"iso-8859-2" => Some(CharacterSetECI::ISO8859_2),
|
||||
"iso-8859-3" => Some(CharacterSetECI::ISO8859_3),
|
||||
"iso-8859-4" => Some(CharacterSetECI::ISO8859_4),
|
||||
"iso-8859-5" => Some(CharacterSetECI::ISO8859_5),
|
||||
// "ISO-8859-6" => Some(CharacterSetECI::ISO8859_6),
|
||||
"ISO-8859-7" => Some(CharacterSetECI::ISO8859_7),
|
||||
"iso-8859-7" => Some(CharacterSetECI::ISO8859_7),
|
||||
// "ISO-8859-8" => Some(CharacterSetECI::ISO8859_8),
|
||||
"ISO-8859-9" => Some(CharacterSetECI::ISO8859_9),
|
||||
"iso-8859-9" => Some(CharacterSetECI::ISO8859_9),
|
||||
// "ISO-8859-10" => Some(CharacterSetECI::ISO8859_10),
|
||||
// "ISO-8859-11" => Some(CharacterSetECI::ISO8859_11),
|
||||
"ISO-8859-13" => Some(CharacterSetECI::ISO8859_13),
|
||||
"iso-8859-13" => Some(CharacterSetECI::ISO8859_13),
|
||||
// "ISO-8859-14" => Some(CharacterSetECI::ISO8859_14),
|
||||
"ISO-8859-15" => Some(CharacterSetECI::ISO8859_15),
|
||||
"ISO-8859-16" => Some(CharacterSetECI::ISO8859_16),
|
||||
"Shift_JIS" => Some(CharacterSetECI::SJIS),
|
||||
"iso-8859-15" => Some(CharacterSetECI::ISO8859_15),
|
||||
"iso-8859-16" => Some(CharacterSetECI::ISO8859_16),
|
||||
"shift_jis" => Some(CharacterSetECI::SJIS),
|
||||
"windows-1250" => Some(CharacterSetECI::Cp1250),
|
||||
"windows-1251" => Some(CharacterSetECI::Cp1251),
|
||||
"windows-1252" => Some(CharacterSetECI::Cp1252),
|
||||
"windows-1256" => Some(CharacterSetECI::Cp1256),
|
||||
"UTF-16BE" => Some(CharacterSetECI::UnicodeBigUnmarked),
|
||||
"UTF-8" => Some(CharacterSetECI::UTF8),
|
||||
"US-ASCII" => Some(CharacterSetECI::ASCII),
|
||||
"Big5" => Some(CharacterSetECI::Big5),
|
||||
"GB2312" => Some(CharacterSetECI::GB18030),
|
||||
"EUC-KR" => Some(CharacterSetECI::EUC_KR),
|
||||
"utf-16be" => Some(CharacterSetECI::UnicodeBigUnmarked),
|
||||
"utf-8" | "utf8" => Some(CharacterSetECI::UTF8),
|
||||
"us-ascii" => Some(CharacterSetECI::ASCII),
|
||||
"big5" => Some(CharacterSetECI::Big5),
|
||||
"gb2312" => Some(CharacterSetECI::GB18030),
|
||||
"euc-kr" => Some(CharacterSetECI::EUC_KR),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -296,7 +325,14 @@ impl CharacterSetECI {
|
||||
}
|
||||
|
||||
pub fn decode(&self, input:&[u8]) -> Result<String> {
|
||||
if self == &CharacterSetECI::Cp437 {
|
||||
use codepage_437::BorrowFromCp437;
|
||||
use codepage_437::CP437_CONTROL;
|
||||
|
||||
Ok(String::borrow_from_cp437(&input, &CP437_CONTROL))
|
||||
}else {
|
||||
self.getCharset().decode(input, encoding::DecoderTrap::Strict).map_err(|e| Exceptions::format_with(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_replace(&self, input:&[u8]) -> Result<String> {
|
||||
|
||||
@@ -14,31 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// package com.google.zxing.common;
|
||||
|
||||
// import java.nio.charset.Charset;
|
||||
// import java.nio.charset.CharsetEncoder;
|
||||
// import java.nio.charset.StandardCharsets;
|
||||
// import java.nio.charset.UnsupportedCharsetException;
|
||||
// import java.util.ArrayList;
|
||||
// import java.util.List;
|
||||
|
||||
use encoding::{Encoding, EncodingRef};
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use super::CharacterSetECI;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
static ENCODERS: Lazy<Vec<EncodingRef>> = Lazy::new(|| {
|
||||
static ENCODERS: Lazy<Vec<CharacterSetECI>> = Lazy::new(|| {
|
||||
let mut enc_vec = Vec::new();
|
||||
for name in NAMES {
|
||||
if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(name) {
|
||||
// try {
|
||||
enc_vec.push(CharacterSetECI::getCharset(&enc));
|
||||
// } catch (UnsupportedCharsetException e) {
|
||||
// continue
|
||||
// }
|
||||
enc_vec.push(enc);
|
||||
}
|
||||
}
|
||||
enc_vec
|
||||
@@ -83,7 +69,7 @@ const NAMES: [&str; 20] = [
|
||||
*/
|
||||
#[derive(Clone)]
|
||||
pub struct ECIEncoderSet {
|
||||
encoders: Vec<EncodingRef>,
|
||||
encoders: Vec<CharacterSetECI>,
|
||||
priorityEncoderIndex: Option<usize>,
|
||||
}
|
||||
|
||||
@@ -98,22 +84,23 @@ impl ECIEncoderSet {
|
||||
*/
|
||||
pub fn new(
|
||||
stringToEncodeMain: &str,
|
||||
priorityCharset: Option<EncodingRef>,
|
||||
priorityCharset: Option<CharacterSetECI>,
|
||||
fnc1: Option<&str>,
|
||||
) -> Self {
|
||||
// List of encoders that potentially encode characters not in ISO-8859-1 in one byte.
|
||||
|
||||
let mut encoders: Vec<EncodingRef>;
|
||||
let mut encoders: Vec<CharacterSetECI>;
|
||||
let mut priorityEncoderIndexValue = None;
|
||||
|
||||
let mut neededEncoders: Vec<EncodingRef> = Vec::new();
|
||||
let mut neededEncoders: Vec<CharacterSetECI> = Vec::new();
|
||||
|
||||
let stringToEncode = stringToEncodeMain.graphemes(true).collect::<Vec<&str>>();
|
||||
|
||||
//we always need the ISO-8859-1 encoder. It is the default encoding
|
||||
neededEncoders.push(encoding::all::ISO_8859_1);
|
||||
neededEncoders.push(CharacterSetECI::ISO8859_1);
|
||||
let mut needUnicodeEncoder = if let Some(pc) = priorityCharset {
|
||||
pc.name().starts_with("UTF") || pc.name().starts_with("utf")
|
||||
//pc.name().starts_with("UTF") || pc.name().starts_with("utf")
|
||||
pc == CharacterSetECI::UTF8 || pc == CharacterSetECI::UnicodeBigUnmarked
|
||||
} else {
|
||||
false
|
||||
};
|
||||
@@ -126,7 +113,7 @@ impl ECIEncoderSet {
|
||||
// for (CharsetEncoder encoder : neededEncoders) {
|
||||
let c = stringToEncode.get(i).unwrap();
|
||||
if (fnc1.is_some() && c == fnc1.as_ref().unwrap())
|
||||
|| encoder.encode(c, encoding::EncoderTrap::Strict).is_ok()
|
||||
|| encoder.encode(c).is_ok()
|
||||
{
|
||||
canEncode = true;
|
||||
break;
|
||||
@@ -140,8 +127,7 @@ impl ECIEncoderSet {
|
||||
// for (CharsetEncoder encoder : ENCODERS) {
|
||||
if encoder
|
||||
.encode(
|
||||
stringToEncode.get(i).unwrap(),
|
||||
encoding::EncoderTrap::Strict,
|
||||
stringToEncode.get(i).unwrap()
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
@@ -163,7 +149,7 @@ impl ECIEncoderSet {
|
||||
|
||||
if neededEncoders.len() == 1 && !needUnicodeEncoder {
|
||||
//the entire input can be encoded by the ISO-8859-1 encoder
|
||||
encoders = vec![encoding::all::ISO_8859_1];
|
||||
encoders = vec![CharacterSetECI::ISO8859_1];
|
||||
} else {
|
||||
// we need more than one single byte encoder or we need a Unicode encoder.
|
||||
// In this case we append a UTF-8 and UTF-16 encoder to the list
|
||||
@@ -177,8 +163,8 @@ impl ECIEncoderSet {
|
||||
encoders.push(encoder);
|
||||
}
|
||||
|
||||
encoders.push(encoding::all::UTF_8);
|
||||
encoders.push(encoding::all::UTF_16BE);
|
||||
encoders.push(CharacterSetECI::UTF8);
|
||||
encoders.push(CharacterSetECI::UnicodeBigUnmarked);
|
||||
}
|
||||
|
||||
//Compute priorityEncoderIndex by looking up priorityCharset in encoders
|
||||
@@ -187,7 +173,8 @@ impl ECIEncoderSet {
|
||||
// for i in 0..encoders.len() {
|
||||
for (i, encoder) in encoders.iter().enumerate() {
|
||||
// for (int i = 0; i < encoders.length; i++) {
|
||||
if priorityCharset.as_ref().unwrap().name() == encoder.name() {
|
||||
// if priorityCharset.as_ref().unwrap().name() == encoder.name() {
|
||||
if priorityCharset.as_ref().unwrap() == encoder {
|
||||
priorityEncoderIndexValue = Some(i);
|
||||
break;
|
||||
}
|
||||
@@ -195,7 +182,7 @@ impl ECIEncoderSet {
|
||||
}
|
||||
// }
|
||||
//invariants
|
||||
assert_eq!(encoders[0].name(), encoding::all::ISO_8859_1.name());
|
||||
assert_eq!(encoders[0], CharacterSetECI::ISO8859_1);
|
||||
Self {
|
||||
encoders,
|
||||
priorityEncoderIndex: priorityEncoderIndexValue,
|
||||
@@ -212,13 +199,13 @@ impl ECIEncoderSet {
|
||||
|
||||
pub fn getCharsetName(&self, index: usize) -> Option<&'static str> {
|
||||
if index < self.len() {
|
||||
Some(self.encoders[index].name())
|
||||
Some(self.encoders[index].getCharsetName())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getCharset(&self, index: usize) -> Option<EncodingRef> {
|
||||
pub fn getCharset(&self, index: usize) -> Option<CharacterSetECI> {
|
||||
if index < self.len() {
|
||||
Some(self.encoders[index])
|
||||
} else {
|
||||
@@ -227,9 +214,10 @@ impl ECIEncoderSet {
|
||||
}
|
||||
|
||||
pub fn getECIValue(&self, encoderIndex: usize) -> u32 {
|
||||
CharacterSetECI::getValue(
|
||||
&CharacterSetECI::getCharacterSetECI(self.encoders[encoderIndex]).unwrap(),
|
||||
)
|
||||
self.encoders[encoderIndex].getValue()
|
||||
// CharacterSetECI::getValue(
|
||||
// &CharacterSetECI::getCharacterSetECI(self.encoders[encoderIndex]).unwrap(),
|
||||
// )
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -242,7 +230,7 @@ impl ECIEncoderSet {
|
||||
pub fn canEncode(&self, c: &str, encoderIndex: usize) -> Option<bool> {
|
||||
if encoderIndex < self.len() {
|
||||
let encoder = self.encoders[encoderIndex];
|
||||
let enc_data = encoder.encode(c, encoding::EncoderTrap::Strict);
|
||||
let enc_data = encoder.encode(c);
|
||||
|
||||
Some(enc_data.is_ok())
|
||||
} else {
|
||||
@@ -253,7 +241,7 @@ impl ECIEncoderSet {
|
||||
pub fn encode_char(&self, c: &str, encoderIndex: usize) -> Option<Vec<u8>> {
|
||||
if encoderIndex < self.len() {
|
||||
let encoder = self.encoders[encoderIndex];
|
||||
let enc_data = encoder.encode(c, encoding::EncoderTrap::Strict);
|
||||
let enc_data = encoder.encode(c);
|
||||
enc_data.ok()
|
||||
// assert!(enc_data.is_ok());
|
||||
// enc_data.unwrap()
|
||||
@@ -265,7 +253,7 @@ impl ECIEncoderSet {
|
||||
pub fn encode_string(&self, s: &str, encoderIndex: usize) -> Option<Vec<u8>> {
|
||||
if encoderIndex < self.len() {
|
||||
let encoder = self.encoders[encoderIndex];
|
||||
encoder.encode(s, encoding::EncoderTrap::Strict).ok()
|
||||
encoder.encode(s).ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use encoding::{Encoding, EncodingRef};
|
||||
|
||||
use crate::common::Result;
|
||||
|
||||
use super::CharacterSetECI;
|
||||
@@ -37,7 +35,7 @@ use super::CharacterSetECI;
|
||||
pub struct ECIStringBuilder {
|
||||
current_bytes: Vec<u8>,
|
||||
result: String,
|
||||
current_charset: Option<EncodingRef>, //= StandardCharsets.ISO_8859_1;
|
||||
current_charset: Option<CharacterSetECI>, //= StandardCharsets.ISO_8859_1;
|
||||
}
|
||||
|
||||
impl ECIStringBuilder {
|
||||
@@ -45,14 +43,14 @@ impl ECIStringBuilder {
|
||||
Self {
|
||||
current_bytes: Vec::new(),
|
||||
result: String::new(),
|
||||
current_charset: Some(encoding::all::ISO_8859_1),
|
||||
current_charset: Some(CharacterSetECI::ISO8859_1),
|
||||
}
|
||||
}
|
||||
pub fn with_capacity(initial_capacity: usize) -> Self {
|
||||
Self {
|
||||
current_bytes: Vec::with_capacity(initial_capacity),
|
||||
result: String::with_capacity(initial_capacity),
|
||||
current_charset: Some(encoding::all::ISO_8859_1),
|
||||
current_charset: Some(CharacterSetECI::ISO8859_1),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,16 +104,18 @@ impl ECIStringBuilder {
|
||||
pub fn appendECI(&mut self, value: u32) -> Result<()> {
|
||||
self.encodeCurrentBytesIfAny();
|
||||
|
||||
if let Ok(character_set_eci) = CharacterSetECI::getCharacterSetECIByValue(value) {
|
||||
// dbg!(
|
||||
// character_set_eci,
|
||||
// CharacterSetECI::getCharset(&character_set_eci).name(),
|
||||
// CharacterSetECI::getCharset(&character_set_eci).whatwg_name()
|
||||
// );
|
||||
self.current_charset = Some(CharacterSetECI::getCharset(&character_set_eci));
|
||||
} else {
|
||||
self.current_charset = None
|
||||
}
|
||||
self.current_charset = CharacterSetECI::getCharacterSetECIByValue(value).ok();
|
||||
|
||||
// if let Ok(character_set_eci) = CharacterSetECI::getCharacterSetECIByValue(value) {
|
||||
// // dbg!(
|
||||
// // character_set_eci,
|
||||
// // CharacterSetECI::getCharset(&character_set_eci).name(),
|
||||
// // CharacterSetECI::getCharset(&character_set_eci).whatwg_name()
|
||||
// // );
|
||||
// self.current_charset = Some(character_set_eci);
|
||||
// } else {
|
||||
// self.current_charset = None
|
||||
// }
|
||||
|
||||
// self.current_charset = CharacterSetECI::getCharset(&character_set_eci);
|
||||
Ok(())
|
||||
@@ -126,7 +126,7 @@ impl ECIStringBuilder {
|
||||
/// This function can panic
|
||||
pub fn encodeCurrentBytesIfAny(&mut self) {
|
||||
if let Some(encoder) = self.current_charset {
|
||||
if encoder.name() == encoding::all::UTF_8.name() {
|
||||
if encoder == CharacterSetECI::UTF8 {
|
||||
if !self.current_bytes.is_empty() {
|
||||
self.result.push_str(
|
||||
&String::from_utf8(std::mem::take(&mut self.current_bytes)).unwrap(),
|
||||
@@ -137,7 +137,7 @@ impl ECIStringBuilder {
|
||||
let bytes = std::mem::take(&mut self.current_bytes);
|
||||
self.current_bytes.clear();
|
||||
let encoded_value = encoder
|
||||
.decode(&bytes, encoding::DecoderTrap::Strict)
|
||||
.decode(&bytes)
|
||||
.unwrap();
|
||||
self.result.push_str(&encoded_value);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
use std::{fmt, rc::Rc};
|
||||
|
||||
use encoding::EncodingRef;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
use super::{ECIEncoderSet, ECIInput};
|
||||
use super::{ECIEncoderSet, ECIInput, CharacterSetECI};
|
||||
|
||||
//* approximated (latch + 2 codewords)
|
||||
pub const COST_PER_ECI: usize = 3;
|
||||
@@ -194,7 +193,7 @@ impl MinimalECIInput {
|
||||
*/
|
||||
pub fn new(
|
||||
stringToEncodeInput: &str,
|
||||
priorityCharset: Option<EncodingRef>,
|
||||
priorityCharset: Option<CharacterSetECI>,
|
||||
fnc1: Option<&str>,
|
||||
) -> Self {
|
||||
let stringToEncode = stringToEncodeInput.graphemes(true).collect::<Vec<&str>>();
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use encoding::{Encoding, EncodingRef};
|
||||
|
||||
use crate::{DecodeHintType, DecodeHintValue, DecodingHintDictionary};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use super::CharacterSetECI;
|
||||
|
||||
/**
|
||||
* Common string-related functions.
|
||||
*
|
||||
@@ -50,8 +50,8 @@ const ASSUME_SHIFT_JIS: bool = false;
|
||||
// static SHIFT_JIS: &'static str = "SJIS";
|
||||
// static GB2312: &'static str = "GB2312";
|
||||
|
||||
pub static SHIFT_JIS_CHARSET: Lazy<EncodingRef> =
|
||||
Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap());
|
||||
pub static SHIFT_JIS_CHARSET: CharacterSetECI =
|
||||
CharacterSetECI::SJIS;
|
||||
|
||||
// private static final boolean ASSUME_SHIFT_JIS =
|
||||
// SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) ||
|
||||
@@ -67,14 +67,14 @@ impl StringUtils {
|
||||
*/
|
||||
pub fn guessEncoding(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<&'static str> {
|
||||
let c = StringUtils::guessCharset(bytes, hints)?;
|
||||
if c.name() == encoding::label::encoding_from_whatwg_label("SJIS")?.name() {
|
||||
if c == CharacterSetECI::SJIS {
|
||||
Some("SJIS")
|
||||
} else if c.name() == encoding::all::UTF_8.name() {
|
||||
} else if c == CharacterSetECI::UTF8 {
|
||||
Some("UTF8")
|
||||
} else if c.name() == encoding::all::ISO_8859_1.name() {
|
||||
} else if c == CharacterSetECI::ISO8859_1 {
|
||||
Some("ISO8859_1")
|
||||
} else {
|
||||
Some(c.name())
|
||||
Some(&c.getCharsetName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,12 +87,12 @@ impl StringUtils {
|
||||
* or the platform default encoding if
|
||||
* none of these can possibly be correct
|
||||
*/
|
||||
pub fn guessCharset(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<EncodingRef> {
|
||||
pub fn guessCharset(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<CharacterSetECI> {
|
||||
if let Some(DecodeHintValue::CharacterSet(cs_name)) =
|
||||
hints.get(&DecodeHintType::CHARACTER_SET)
|
||||
{
|
||||
// if let DecodeHintValue::CharacterSet(cs_name) = hint {
|
||||
return encoding::label::encoding_from_whatwg_label(cs_name);
|
||||
return CharacterSetECI::getCharacterSetECIByName(cs_name)
|
||||
// }
|
||||
}
|
||||
// if hints.contains_key(&DecodeHintType::CHARACTER_SET) {
|
||||
@@ -104,9 +104,9 @@ impl StringUtils {
|
||||
&& ((bytes[0] == 0xFE && bytes[1] == 0xFF) || (bytes[0] == 0xFF && bytes[1] == 0xFE))
|
||||
{
|
||||
if bytes[0] == 0xFE && bytes[1] == 0xFF {
|
||||
return Some(encoding::all::UTF_16BE);
|
||||
return Some(CharacterSetECI::UnicodeBigUnmarked);
|
||||
} else {
|
||||
return Some(encoding::all::UTF_16LE);
|
||||
return Some(CharacterSetECI::UTF16LE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ impl StringUtils {
|
||||
|
||||
// Easy -- if there is BOM or at least 1 valid not-single byte character (and no evidence it can't be UTF-8), done
|
||||
if can_be_utf8 && (utf8bom || utf2_bytes_chars + utf3_bytes_chars + utf4_bytes_chars > 0) {
|
||||
return Some(encoding::all::UTF_8);
|
||||
return Some(CharacterSetECI::UTF8);
|
||||
}
|
||||
// Easy -- if assuming Shift_JIS or >= 3 valid consecutive not-ascii characters (and no evidence it can't be), done
|
||||
if can_be_shift_jis
|
||||
@@ -232,7 +232,7 @@ impl StringUtils {
|
||||
|| sjis_max_katakana_word_length >= 3
|
||||
|| sjis_max_double_bytes_word_length >= 3)
|
||||
{
|
||||
return encoding::label::encoding_from_whatwg_label("SJIS");
|
||||
return Some(CharacterSetECI::SJIS); //encoding::label::encoding_from_whatwg_label("SJIS");
|
||||
}
|
||||
// Distinguishing Shift_JIS and ISO-8859-1 can be a little tough for short words. The crude heuristic is:
|
||||
// - If we saw
|
||||
@@ -243,23 +243,23 @@ impl StringUtils {
|
||||
return if (sjis_max_katakana_word_length == 2 && sjis_katakana_chars == 2)
|
||||
|| iso_high_other * 10 >= length
|
||||
{
|
||||
encoding::label::encoding_from_whatwg_label("SJIS")
|
||||
Some(CharacterSetECI::SJIS)
|
||||
} else {
|
||||
Some(encoding::all::ISO_8859_1)
|
||||
Some(CharacterSetECI::ISO8859_1)
|
||||
};
|
||||
}
|
||||
|
||||
// Otherwise, try in order ISO-8859-1, Shift JIS, UTF-8 and fall back to default platform encoding
|
||||
if can_be_iso88591 {
|
||||
return Some(encoding::all::ISO_8859_1);
|
||||
return Some(CharacterSetECI::ISO8859_1);
|
||||
}
|
||||
if can_be_shift_jis {
|
||||
return Some(encoding::label::encoding_from_whatwg_label("SJIS").unwrap());
|
||||
return Some(CharacterSetECI::SJIS);
|
||||
}
|
||||
if can_be_utf8 {
|
||||
return Some(encoding::all::UTF_8);
|
||||
return Some(CharacterSetECI::UTF8);
|
||||
}
|
||||
// Otherwise, we take a wild guess with platform encoding
|
||||
Some(encoding::all::UTF_8)
|
||||
Some(CharacterSetECI::UTF8)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use crate::{
|
||||
common::{BitMatrix, Result},
|
||||
common::{BitMatrix, Result, CharacterSetECI},
|
||||
qrcode::encoder::ByteMatrix,
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
||||
};
|
||||
@@ -117,14 +115,14 @@ impl Writer for DataMatrixWriter {
|
||||
false
|
||||
};
|
||||
|
||||
let mut charset: Option<EncodingRef> = None;
|
||||
let mut charset: Option<CharacterSetECI> = None;
|
||||
let hasEncodingHint = hints.contains_key(&EncodeHintType::CHARACTER_SET);
|
||||
if hasEncodingHint {
|
||||
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
|
||||
hints.get(&EncodeHintType::CHARACTER_SET) else {
|
||||
return Err(Exceptions::illegal_argument_with("charset does not exist"))
|
||||
};
|
||||
charset = encoding::label::encoding_from_whatwg_label(char_set_name);
|
||||
charset = CharacterSetECI::getCharacterSetECIByName(char_set_name);//encoding::label::encoding_from_whatwg_label(char_set_name);
|
||||
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
|
||||
}
|
||||
encoded = minimal_encoder::encodeHighLevelWithDetails(
|
||||
|
||||
@@ -14,10 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use encoding::Encoding;
|
||||
|
||||
use crate::{
|
||||
common::{BitSource, DecoderRXingResult, ECIStringBuilder, Result},
|
||||
common::{BitSource, DecoderRXingResult, ECIStringBuilder, Result, CharacterSetECI},
|
||||
Exceptions,
|
||||
};
|
||||
|
||||
@@ -730,9 +728,10 @@ fn decodeBase256Segment(
|
||||
codewordPosition += 1;
|
||||
}
|
||||
result.append_string(
|
||||
&encoding::all::ISO_8859_1
|
||||
.decode(&bytes, encoding::DecoderTrap::Strict)
|
||||
.map_err(Exceptions::parse_with)?,
|
||||
|
||||
&CharacterSetECI::ISO8859_1
|
||||
.decode(&bytes)
|
||||
?,
|
||||
);
|
||||
byteSegments.push(bytes);
|
||||
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::common::{Result, CharacterSetECI};
|
||||
use crate::{Dimension, Exceptions};
|
||||
|
||||
use super::{SymbolInfo, SymbolInfoLookup, SymbolShapeHint};
|
||||
use encoding::{self, EncodingRef};
|
||||
|
||||
const ISO_8859_1_ENCODER: EncodingRef = encoding::all::ISO_8859_1;
|
||||
const ISO_8859_1_ENCODER: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
||||
|
||||
pub struct EncoderContext<'a> {
|
||||
symbol_lookup: Rc<SymbolInfoLookup<'a>>,
|
||||
@@ -59,10 +58,10 @@ impl<'a> EncoderContext<'_> {
|
||||
// sb.append(ch);
|
||||
// }
|
||||
let sb = if let Ok(encoded_bytes) =
|
||||
ISO_8859_1_ENCODER.encode(msg, encoding::EncoderTrap::Strict)
|
||||
ISO_8859_1_ENCODER.encode(msg)
|
||||
{
|
||||
ISO_8859_1_ENCODER
|
||||
.decode(&encoded_bytes, encoding::DecoderTrap::Strict)
|
||||
.decode(&encoded_bytes)
|
||||
.map_err(|e| {
|
||||
Exceptions::parse_with(format!("round trip decode should always work: {e}"))
|
||||
})?
|
||||
|
||||
@@ -18,7 +18,7 @@ use std::rc::Rc;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::datamatrix::encoder::{SymbolInfo, SymbolShapeHint};
|
||||
use crate::{datamatrix::encoder::{SymbolInfo, SymbolShapeHint}, common::CharacterSetECI};
|
||||
|
||||
use super::{high_level_encoder, minimal_encoder, symbol_info, SymbolInfoLookup};
|
||||
|
||||
@@ -534,7 +534,7 @@ fn testECIs() {
|
||||
assert_eq!("239 209 151 206 214 92 122 140 35 158 144 162 52 205 55 171 137 23 67 206 218 175 147 113 15 254 116 33 241 25 231 186 14 212 64 253 151 252 159 33 41 241 27 231 83 171 53 209 35 25 134 6 42 33 35 239 184 31 193 234 7 252 205 101 127 241 209 34 24 5 22 23 221 148 179 239 128 140 92 187 106 204 198 59 19 25 114 248 118 36 254 231 106 196 19 239 101 27 107 69 189 112 236 156 252 16 174 125 24 10 125 116 42 129",
|
||||
visualized);
|
||||
|
||||
let visualized = visualize(&minimal_encoder::encodeHighLevelWithDetails("that particularly stands out to me is \u{0625}\u{0650}\u{062C}\u{064E}\u{0651}\u{0627}\u{0635} (\u{02BE}\u{0101}\u{1E63}) \"pear\", suggested to have originated from Hebrew \u{05D0}\u{05B7}\u{05D2}\u{05B8}\u{05BC}\u{05E1} (ag\u{00E1}s)", Some(encoding::all::UTF_8), None , SymbolShapeHint::FORCE_NONE).expect("encode"));
|
||||
let visualized = visualize(&minimal_encoder::encodeHighLevelWithDetails("that particularly stands out to me is \u{0625}\u{0650}\u{062C}\u{064E}\u{0651}\u{0627}\u{0635} (\u{02BE}\u{0101}\u{1E63}) \"pear\", suggested to have originated from Hebrew \u{05D0}\u{05B7}\u{05D2}\u{05B8}\u{05BC}\u{05E1} (ag\u{00E1}s)", Some(CharacterSetECI::UTF8), None , SymbolShapeHint::FORCE_NONE).expect("encode"));
|
||||
assert_eq!("241 27 239 209 151 206 214 92 122 140 35 158 144 162 52 205 55 171 137 23 67 206 218 175 147 113 15 254 116 33 231 202 33 131 77 154 119 225 163 238 206 28 249 93 36 150 151 53 108 246 145 228 217 71 199 42 33 35 239 184 31 193 234 7 252 205 101 127 241 209 34 24 5 22 23 221 148 179 239 128 140 92 187 106 204 198 59 19 25 114 248 118 36 254 231 43 133 212 175 38 220 44 6 125 49 172 93 189 209 111 61 217 203 62 116 42 129 1 151 46 196 91 241 137 32 182 77 227 122 18 168 63 213 108 4 154 49 199 94 244 140 35 185 80",
|
||||
visualized);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use encoding::{self, EncodingRef};
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::common::{Result, CharacterSetECI};
|
||||
use crate::{Dimension, Exceptions};
|
||||
|
||||
use super::{
|
||||
@@ -26,7 +24,7 @@ use super::{
|
||||
SymbolInfoLookup, SymbolShapeHint, TextEncoder, X12Encoder,
|
||||
};
|
||||
#[allow(dead_code)]
|
||||
const DEFAULT_ENCODING: EncodingRef = encoding::all::ISO_8859_1;
|
||||
const DEFAULT_ENCODING: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
||||
|
||||
/**
|
||||
* DataMatrix ECC 200 data encoder following the algorithm described in ISO/IEC 16022:200(E) in
|
||||
|
||||
@@ -16,16 +16,14 @@
|
||||
|
||||
use std::{fmt, rc::Rc};
|
||||
|
||||
use encoding::{self, EncodingRef};
|
||||
|
||||
use crate::{
|
||||
common::{ECIInput, MinimalECIInput, Result},
|
||||
common::{ECIInput, MinimalECIInput, Result, CharacterSetECI},
|
||||
Exceptions,
|
||||
};
|
||||
|
||||
use super::{high_level_encoder, SymbolShapeHint};
|
||||
|
||||
const ISO_8859_1_ENCODER: EncodingRef = encoding::all::ISO_8859_1;
|
||||
const ISO_8859_1_ENCODER: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
||||
|
||||
/**
|
||||
* Encoder that encodes minimally
|
||||
@@ -153,7 +151,7 @@ pub fn encodeHighLevel(msg: &str) -> Result<String> {
|
||||
*/
|
||||
pub fn encodeHighLevelWithDetails(
|
||||
msg: &str,
|
||||
priorityCharset: Option<EncodingRef>,
|
||||
priorityCharset: Option<CharacterSetECI>,
|
||||
fnc1: Option<char>,
|
||||
shape: SymbolShapeHint,
|
||||
) -> Result<String> {
|
||||
@@ -174,8 +172,8 @@ pub fn encodeHighLevelWithDetails(
|
||||
}
|
||||
Ok(ISO_8859_1_ENCODER
|
||||
.decode(
|
||||
&encode(msg, priorityCharset, fnc1, shape, macroId)?,
|
||||
encoding::DecoderTrap::Strict,
|
||||
&encode(msg, priorityCharset, fnc1, shape, macroId)?
|
||||
|
||||
)
|
||||
.expect("should decode"))
|
||||
// return new String(encode(msg, priorityCharset, fnc1, shape, macroId), StandardCharsets.ISO_8859_1);
|
||||
@@ -197,7 +195,7 @@ pub fn encodeHighLevelWithDetails(
|
||||
*/
|
||||
fn encode(
|
||||
input: &str,
|
||||
priorityCharset: Option<EncodingRef>,
|
||||
priorityCharset: Option<CharacterSetECI>,
|
||||
fnc1: Option<char>,
|
||||
shape: SymbolShapeHint,
|
||||
macroId: i32,
|
||||
@@ -1398,7 +1396,7 @@ struct Input {
|
||||
impl Input {
|
||||
pub fn new(
|
||||
stringToEncode: &str,
|
||||
priorityCharset: Option<EncodingRef>,
|
||||
priorityCharset: Option<CharacterSetECI>,
|
||||
fnc1: Option<char>,
|
||||
shape: SymbolShapeHint,
|
||||
macroId: i32,
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use encoding::{Encoding, EncodingRef};
|
||||
use java_rand;
|
||||
|
||||
use crate::common::CharacterSetECI;
|
||||
use crate::pdf417::decoder::decoded_bit_stream_parser;
|
||||
use crate::pdf417::encoder::{pdf_417_high_level_encoder_test_adapter, Compaction};
|
||||
use crate::pdf417::PDF417RXingResultMetadata;
|
||||
@@ -307,8 +307,8 @@ fn testBinaryData() {
|
||||
random.next_bytes(&mut bytes);
|
||||
|
||||
total += encodeDecode(
|
||||
&encoding::all::ISO_8859_1
|
||||
.decode(&bytes, encoding::DecoderTrap::Strict)
|
||||
&CharacterSetECI::ISO8859_1
|
||||
.decode(&bytes)
|
||||
.expect("decode bytes"),
|
||||
);
|
||||
}
|
||||
@@ -437,7 +437,7 @@ fn encodeDecode(input: &str) -> u32 {
|
||||
|
||||
fn encodeDecodeWithAll(
|
||||
input: &str,
|
||||
charset: Option<EncodingRef>,
|
||||
charset: Option<CharacterSetECI>,
|
||||
autoECI: bool,
|
||||
decode: bool,
|
||||
) -> u32 {
|
||||
@@ -523,7 +523,7 @@ fn performECITest(
|
||||
// for (int i = 0; i < 1000; i++) {
|
||||
let s = generateText(&mut random, 100, chars, weights);
|
||||
minLength += encodeDecodeWithAll(&s, None, true, true);
|
||||
utfLength += encodeDecodeWithAll(&s, Some(encoding::all::UTF_8), false, true);
|
||||
utfLength += encodeDecodeWithAll(&s, Some(CharacterSetECI::UTF8), false, true);
|
||||
}
|
||||
assert_eq!(expectedMinLength, minLength);
|
||||
assert_eq!(expectedUTFLength, utfLength);
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
* This file has been modified from its original form in Barcode4J.
|
||||
*/
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::common::{Result, CharacterSetECI};
|
||||
use crate::Exceptions;
|
||||
|
||||
use super::{
|
||||
@@ -34,7 +32,7 @@ pub struct PDF417 {
|
||||
barcodeMatrix: Option<BarcodeMatrix>,
|
||||
compact: bool,
|
||||
compaction: Compaction,
|
||||
encoding: Option<EncodingRef>,
|
||||
encoding: Option<CharacterSetECI>,
|
||||
minCols: u32,
|
||||
maxCols: u32,
|
||||
maxRows: u32,
|
||||
@@ -347,7 +345,7 @@ impl PDF417 {
|
||||
/**
|
||||
* @param encoding sets character encoding to use
|
||||
*/
|
||||
pub fn setEncoding(&mut self, encoding: Option<EncodingRef>) {
|
||||
pub fn setEncoding(&mut self, encoding: Option<CharacterSetECI>) {
|
||||
self.encoding = encoding;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
|
||||
use std::{any::TypeId, fmt::Display, str::FromStr};
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use crate::{
|
||||
common::{CharacterSetECI, ECIInput, MinimalECIInput, Result},
|
||||
Exceptions,
|
||||
@@ -125,7 +123,7 @@ const TEXT_PUNCTUATION_RAW: [u8; 30] = [
|
||||
40, 41, 63, 123, 125, 39, 0,
|
||||
];
|
||||
|
||||
const DEFAULT_ENCODING: EncodingRef = encoding::all::ISO_8859_1; //StandardCharsets.ISO_8859_1;
|
||||
const DEFAULT_ENCODING: CharacterSetECI = CharacterSetECI::ISO8859_1; //StandardCharsets.ISO_8859_1;
|
||||
|
||||
const MIXED: [i8; 128] = {
|
||||
let mut mixed = [-1_i8; 128];
|
||||
@@ -174,7 +172,7 @@ const PUNCTUATION: [i8; 128] = {
|
||||
pub fn encodeHighLevel(
|
||||
msg: &str,
|
||||
compaction: Compaction,
|
||||
encoding: Option<EncodingRef>,
|
||||
encoding: Option<CharacterSetECI>,
|
||||
autoECI: bool,
|
||||
) -> Result<String> {
|
||||
let mut encoding = encoding;
|
||||
@@ -199,14 +197,16 @@ pub fn encodeHighLevel(
|
||||
input = Box::new(NoECIInput::new(msg.to_owned()));
|
||||
if encoding.is_none() {
|
||||
encoding = Some(DEFAULT_ENCODING);
|
||||
} else if DEFAULT_ENCODING.name()
|
||||
!= encoding.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?.name()
|
||||
} else if &DEFAULT_ENCODING
|
||||
!= encoding.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?
|
||||
{
|
||||
if let Some(eci) =
|
||||
CharacterSetECI::getCharacterSetECI(encoding.ok_or(Exceptions::ILLEGAL_STATE)?)
|
||||
{
|
||||
encodingECI(CharacterSetECI::getValue(&eci) as i32, &mut sb)?;
|
||||
}
|
||||
// if let Some(eci) =
|
||||
// CharacterSetECI::getCharacterSetECI(encoding.ok_or(Exceptions::ILLEGAL_STATE)?)
|
||||
// {
|
||||
// encodingECI(CharacterSetECI::getValue(&eci) as i32, &mut sb)?;
|
||||
// }
|
||||
|
||||
encodingECI(CharacterSetECI::getValue(&encoding.ok_or(Exceptions::ILLEGAL_STATE)?) as i32, &mut sb)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ pub fn encodeHighLevel(
|
||||
let msgBytes = encoding
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?
|
||||
.encode(&input.to_string(), encoding::EncoderTrap::Strict)
|
||||
.encode(&input.to_string())
|
||||
.unwrap_or_default(); //input.to_string().getBytes(encoding);
|
||||
encodeBinary(
|
||||
&msgBytes,
|
||||
@@ -286,7 +286,7 @@ pub fn encodeHighLevel(
|
||||
if let Ok(enc_str) = encoding
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?
|
||||
.encode(&str, encoding::EncoderTrap::Strict)
|
||||
.encode(&str)
|
||||
{
|
||||
Some(enc_str)
|
||||
} else {
|
||||
@@ -747,7 +747,7 @@ fn determineConsecutiveTextCount<T: ECIInput + ?Sized>(
|
||||
fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
|
||||
input: &Box<T>,
|
||||
startpos: u32,
|
||||
encoding: Option<EncodingRef>,
|
||||
encoding: Option<CharacterSetECI>,
|
||||
) -> Result<u32> {
|
||||
let len = input.length();
|
||||
let mut idx = startpos as usize;
|
||||
@@ -770,8 +770,8 @@ fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
|
||||
if let Some(encoder) = encoding {
|
||||
let can_encode = encoder
|
||||
.encode(
|
||||
&input.charAt(idx)?.to_string(),
|
||||
encoding::EncoderTrap::Strict,
|
||||
&input.charAt(idx)?.to_string()
|
||||
|
||||
)
|
||||
.is_ok();
|
||||
|
||||
@@ -856,11 +856,11 @@ impl Display for NoECIInput {
|
||||
*/
|
||||
#[cfg(test)]
|
||||
mod PDF417EncoderTestCase {
|
||||
use crate::pdf417::encoder::{pdf_417_high_level_encoder::encodeHighLevel, Compaction};
|
||||
use crate::{pdf417::encoder::{pdf_417_high_level_encoder::encodeHighLevel, Compaction}, common::CharacterSetECI};
|
||||
|
||||
#[test]
|
||||
fn testEncodeAuto() {
|
||||
let encoded = encodeHighLevel("ABCD", Compaction::AUTO, Some(encoding::all::UTF_8), false)
|
||||
let encoded = encodeHighLevel("ABCD", Compaction::AUTO, Some(CharacterSetECI::UTF8), false)
|
||||
.expect("encode");
|
||||
assert_eq!("\u{039f}\u{001A}\u{0385}ABCD", encoded);
|
||||
}
|
||||
@@ -871,7 +871,7 @@ mod PDF417EncoderTestCase {
|
||||
encodeHighLevel(
|
||||
"1%§s ?aG$",
|
||||
Compaction::AUTO,
|
||||
Some(encoding::all::UTF_8),
|
||||
Some(CharacterSetECI::UTF8),
|
||||
false,
|
||||
)
|
||||
.expect("encode");
|
||||
@@ -883,7 +883,7 @@ mod PDF417EncoderTestCase {
|
||||
encodeHighLevel(
|
||||
"asdfg§asd",
|
||||
Compaction::AUTO,
|
||||
Some(encoding::all::ISO_8859_1),
|
||||
Some(CharacterSetECI::ISO8859_1),
|
||||
false,
|
||||
)
|
||||
.expect("encode");
|
||||
@@ -891,7 +891,7 @@ mod PDF417EncoderTestCase {
|
||||
|
||||
#[test]
|
||||
fn testEncodeText() {
|
||||
let encoded = encodeHighLevel("ABCD", Compaction::TEXT, Some(encoding::all::UTF_8), false)
|
||||
let encoded = encodeHighLevel("ABCD", Compaction::TEXT, Some(CharacterSetECI::UTF8), false)
|
||||
.expect("encode");
|
||||
assert_eq!("Ο\u{001A}\u{0001}?", encoded);
|
||||
}
|
||||
@@ -901,7 +901,7 @@ mod PDF417EncoderTestCase {
|
||||
let encoded = encodeHighLevel(
|
||||
"1234",
|
||||
Compaction::NUMERIC,
|
||||
Some(encoding::all::UTF_8),
|
||||
Some(CharacterSetECI::UTF8),
|
||||
false,
|
||||
)
|
||||
.expect("encode");
|
||||
@@ -911,7 +911,7 @@ mod PDF417EncoderTestCase {
|
||||
|
||||
#[test]
|
||||
fn testEncodeByte() {
|
||||
let encoded = encodeHighLevel("abcd", Compaction::BYTE, Some(encoding::all::UTF_8), false)
|
||||
let encoded = encodeHighLevel("abcd", Compaction::BYTE, Some(CharacterSetECI::UTF8), false)
|
||||
.expect("encode");
|
||||
assert_eq!("\u{039f}\u{001A}\u{0385}abcd", encoded);
|
||||
}
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::common::{Result, CharacterSetECI};
|
||||
|
||||
use super::{pdf_417_high_level_encoder, Compaction};
|
||||
|
||||
@@ -27,7 +25,7 @@ use super::{pdf_417_high_level_encoder, Compaction};
|
||||
pub fn encodeHighLevel(
|
||||
msg: &str,
|
||||
compaction: Compaction,
|
||||
encoding: Option<EncodingRef>,
|
||||
encoding: Option<CharacterSetECI>,
|
||||
autoECI: bool,
|
||||
) -> Result<String> {
|
||||
pdf_417_high_level_encoder::encodeHighLevel(msg, compaction, encoding, autoECI)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
common::{BitMatrix, Result},
|
||||
common::{BitMatrix, Result, CharacterSetECI},
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
||||
};
|
||||
|
||||
@@ -108,7 +108,7 @@ impl Writer for PDF417Writer {
|
||||
if let Some(EncodeHintValue::CharacterSet(cs)) =
|
||||
hints.get(&EncodeHintType::CHARACTER_SET)
|
||||
{
|
||||
encoder.setEncoding(encoding::label::encoding_from_whatwg_label(cs));
|
||||
encoder.setEncoding(CharacterSetECI::getCharacterSetECIByName(cs));
|
||||
}
|
||||
if let Some(EncodeHintValue::Pdf417AutoEci(auto_eci_str)) =
|
||||
hints.get(&EncodeHintType::PDF417_AUTO_ECI)
|
||||
|
||||
@@ -204,9 +204,9 @@ fn decodeHanziSegment(bits: &mut BitSource, result: &mut String, count: usize) -
|
||||
}
|
||||
|
||||
let gb_encoder =
|
||||
encoding::label::encoding_from_whatwg_label("GBK").ok_or(Exceptions::ILLEGAL_STATE)?;
|
||||
CharacterSetECI::GB18030;
|
||||
let encode_string = gb_encoder
|
||||
.decode(&buffer, encoding::DecoderTrap::Strict)
|
||||
.decode(&buffer)
|
||||
.map_err(|e| Exceptions::parse_with(format!("unable to decode buffer {buffer:?}: {e}")))?;
|
||||
result.push_str(&encode_string);
|
||||
Ok(())
|
||||
@@ -250,7 +250,7 @@ fn decodeKanjiSegment(
|
||||
let encoder = {
|
||||
let _ = currentCharacterSetECI;
|
||||
let _ = hints;
|
||||
encoding::label::encoding_from_whatwg_label("SJIS").ok_or(Exceptions::FORMAT)?
|
||||
CharacterSetECI::SJIS
|
||||
};
|
||||
|
||||
#[cfg(feature = "allow_forced_iso_ied_18004_compliance")]
|
||||
@@ -258,16 +258,16 @@ fn decodeKanjiSegment(
|
||||
hints.get(&DecodeHintType::QR_ASSUME_SPEC_CONFORM_INPUT)
|
||||
{
|
||||
if let Some(ccse) = ¤tCharacterSetECI {
|
||||
CharacterSetECI::getCharset(ccse)
|
||||
CharacterSetECI::getCharacterSetECIByName(ccse)
|
||||
} else {
|
||||
encoding::all::ISO_8859_1
|
||||
CharacterSetECI::ISO8859_1
|
||||
}
|
||||
} else {
|
||||
encoding::label::encoding_from_whatwg_label("SJIS").ok_or(Exceptions::FORMAT)?
|
||||
CharacterSetECI::SJIS
|
||||
};
|
||||
|
||||
let encode_string = encoder
|
||||
.decode(&buffer, encoding::DecoderTrap::Strict)
|
||||
.decode(&buffer)
|
||||
.map_err(|e| Exceptions::parse_with(format!("unable to decode buffer {buffer:?}: {e}")))?;
|
||||
|
||||
result.push_str(&encode_string);
|
||||
@@ -308,37 +308,26 @@ fn decodeByteSegment(
|
||||
if let Some(DecodeHintValue::QrAssumeSpecConformInput(true)) =
|
||||
hints.get(&DecodeHintType::QR_ASSUME_SPEC_CONFORM_INPUT)
|
||||
{
|
||||
encoding::all::ISO_8859_1
|
||||
CharacterSetECI::ISO8859_1
|
||||
} else {
|
||||
StringUtils::guessCharset(&readBytes, hints)
|
||||
}
|
||||
} else {
|
||||
CharacterSetECI::getCharset(
|
||||
currentCharacterSetECI
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?,
|
||||
)
|
||||
currentCharacterSetECI.ok_or(Exceptions::ILLEGAL_STATE)?
|
||||
// CharacterSetECI::getCharset(
|
||||
// currentCharacterSetECI
|
||||
// .as_ref()
|
||||
// .ok_or(Exceptions::ILLEGAL_STATE)?,
|
||||
// )
|
||||
};
|
||||
|
||||
let encode_string = if currentCharacterSetECI.is_some()
|
||||
&& currentCharacterSetECI
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?
|
||||
== &CharacterSetECI::Cp437
|
||||
{
|
||||
{
|
||||
use codepage_437::BorrowFromCp437;
|
||||
use codepage_437::CP437_CONTROL;
|
||||
|
||||
String::borrow_from_cp437(&readBytes, &CP437_CONTROL)
|
||||
}
|
||||
} else {
|
||||
let encode_string =
|
||||
encoding
|
||||
.decode(&readBytes, encoding::DecoderTrap::Strict)
|
||||
.decode(&readBytes)
|
||||
.map_err(|e| {
|
||||
Exceptions::parse_with(format!("unable to decode buffer {readBytes:?}: {e}"))
|
||||
})?
|
||||
};
|
||||
;
|
||||
|
||||
result.push_str(&encode_string);
|
||||
byteSegments.push(readBytes);
|
||||
|
||||
@@ -17,20 +17,19 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
common::BitArray,
|
||||
common::{BitArray, CharacterSetECI},
|
||||
qrcode::{
|
||||
decoder::{ErrorCorrectionLevel, Mode, Version},
|
||||
encoder::{qrcode_encoder, MinimalEncoder},
|
||||
},
|
||||
EncodeHintType, EncodeHintValue,
|
||||
};
|
||||
use encoding::EncodingRef;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use super::QRCode;
|
||||
|
||||
static SHIFT_JIS_CHARSET: Lazy<EncodingRef> =
|
||||
Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap());
|
||||
static SHIFT_JIS_CHARSET: Lazy<CharacterSetECI> =
|
||||
Lazy::new(|| CharacterSetECI::SJIS);
|
||||
|
||||
/**
|
||||
* @author satorux@google.com (Satoru Takabayashi) - creator
|
||||
@@ -1075,10 +1074,9 @@ fn testMinimalEncoder41() {
|
||||
#[test]
|
||||
fn testMinimalEncoder42() {
|
||||
// test halfwidth Katakana character (they are single byte encoded in Shift_JIS)
|
||||
// NOTE: Changed to windows-31j because that is what is supported in encoding crate
|
||||
verifyMinimalEncoding(
|
||||
"Katakana:\u{FF66}\u{FF66}\u{FF66}\u{FF66}\u{FF66}\u{FF66}",
|
||||
"ECI(windows-31j),BYTE(Katakana:......)",
|
||||
"ECI(shift_jis),BYTE(Katakana:......)",
|
||||
None,
|
||||
false,
|
||||
);
|
||||
@@ -1100,10 +1098,9 @@ fn testMinimalEncoder44() {
|
||||
// The character \u30A2 encodes as double byte in Shift_JIS but KANJI is not more compact in this case because
|
||||
// KANJI is only more compact when it encodes pairs of characters. In the case of mixed text it can however be
|
||||
// that Shift_JIS encoding is more compact as in this example
|
||||
// NOTE: Changed to windows-31j because that is what is supported in encoding crate
|
||||
verifyMinimalEncoding(
|
||||
"Katakana:\u{30A2}a\u{30A2}a\u{30A2}a\u{30A2}a\u{30A2}a\u{30A2}",
|
||||
"ECI(windows-31j),BYTE(Katakana:.a.a.a.a.a.)",
|
||||
"ECI(shift_jis),BYTE(Katakana:.a.a.a.a.a.)",
|
||||
None,
|
||||
false,
|
||||
);
|
||||
@@ -1112,7 +1109,7 @@ fn testMinimalEncoder44() {
|
||||
fn verifyMinimalEncoding(
|
||||
input: &str,
|
||||
expectedRXingResult: &str,
|
||||
priorityCharset: Option<EncodingRef>,
|
||||
priorityCharset: Option<CharacterSetECI>,
|
||||
isGS1: bool,
|
||||
) {
|
||||
let result = MinimalEncoder::encode_with_details(
|
||||
@@ -1198,7 +1195,7 @@ fn verifyNotGS1EncodedData(qrCode: &QRCode) {
|
||||
|
||||
fn shiftJISString(bytes: &[u8]) -> String {
|
||||
SHIFT_JIS_CHARSET
|
||||
.decode(bytes, encoding::DecoderTrap::Strict)
|
||||
.decode(bytes)
|
||||
.expect("decode should be ok")
|
||||
// return new String(bytes, StringUtils.SHIFT_JIS_CHARSET);
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
use std::{fmt, rc::Rc};
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use crate::{
|
||||
common::{BitArray, ECIEncoderSet, Result},
|
||||
common::{BitArray, ECIEncoderSet, Result, CharacterSetECI},
|
||||
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
|
||||
Exceptions,
|
||||
};
|
||||
@@ -107,7 +105,7 @@ impl MinimalEncoder {
|
||||
*/
|
||||
pub fn new(
|
||||
stringToEncode: &str,
|
||||
priorityCharset: Option<EncodingRef>,
|
||||
priorityCharset: Option<CharacterSetECI>,
|
||||
isGS1: bool,
|
||||
ecLevel: ErrorCorrectionLevel,
|
||||
) -> Self {
|
||||
@@ -142,7 +140,7 @@ impl MinimalEncoder {
|
||||
pub fn encode_with_details(
|
||||
stringToEncode: &str,
|
||||
version: Option<VersionRef>,
|
||||
priorityCharset: Option<EncodingRef>,
|
||||
priorityCharset: Option<CharacterSetECI>,
|
||||
isGS1: bool,
|
||||
ecLevel: ErrorCorrectionLevel,
|
||||
) -> Result<RXingResultList> {
|
||||
@@ -1044,10 +1042,10 @@ impl fmt::Display for RXingResultNode {
|
||||
result.push('(');
|
||||
if self.mode == Mode::ECI {
|
||||
result.push_str(
|
||||
self.encoders
|
||||
&self.encoders
|
||||
.getCharset(self.charsetEncoderIndex)
|
||||
.ok_or(fmt::Error)?
|
||||
.name(),
|
||||
.getCharsetName(),
|
||||
);
|
||||
} else {
|
||||
let sub_string: String = self
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
*/
|
||||
use std::collections::HashMap;
|
||||
|
||||
use encoding::EncodingRef;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use crate::{
|
||||
@@ -35,8 +32,8 @@ use crate::{
|
||||
|
||||
use super::{mask_util, matrix_util, BlockPair, ByteMatrix, MinimalEncoder, QRCode};
|
||||
|
||||
static SHIFT_JIS_CHARSET: Lazy<EncodingRef> =
|
||||
Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap());
|
||||
static SHIFT_JIS_CHARSET: CharacterSetECI =
|
||||
CharacterSetECI::SJIS;
|
||||
|
||||
// The original table is defined in the table 5 of JISX0510:2004 (p.19).
|
||||
const ALPHANUMERIC_TABLE: [i8; 96] = [
|
||||
@@ -48,7 +45,7 @@ const ALPHANUMERIC_TABLE: [i8; 96] = [
|
||||
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // 0x50-0x5f
|
||||
];
|
||||
|
||||
pub const DEFAULT_BYTE_MODE_ENCODING: EncodingRef = encoding::all::ISO_8859_1;
|
||||
pub const DEFAULT_BYTE_MODE_ENCODING: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
||||
|
||||
// The mask penalty calculation is complicated. See Table 21 of JISX0510:2004 (p.45) for details.
|
||||
// Basically it applies four rules and summate all penalties.
|
||||
@@ -101,7 +98,7 @@ pub fn encode_with_hints(
|
||||
if has_encoding_hint {
|
||||
if let Some(EncodeHintValue::CharacterSet(v)) = hints.get(&EncodeHintType::CHARACTER_SET) {
|
||||
encoding =
|
||||
Some(encoding::label::encoding_from_whatwg_label(v).ok_or(Exceptions::WRITER)?)
|
||||
Some(CharacterSetECI::getCharacterSetECIByName(v).ok_or(Exceptions::WRITER)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,12 +123,12 @@ pub fn encode_with_hints(
|
||||
let encoding = if let Some(encoding) = encoding {
|
||||
encoding
|
||||
} else if let Ok(_encs) =
|
||||
DEFAULT_BYTE_MODE_ENCODING.encode(content, encoding::EncoderTrap::Strict)
|
||||
DEFAULT_BYTE_MODE_ENCODING.encode(content)
|
||||
{
|
||||
DEFAULT_BYTE_MODE_ENCODING
|
||||
} else {
|
||||
has_encoding_hint = true;
|
||||
encoding::all::UTF_8
|
||||
CharacterSetECI::UTF8
|
||||
};
|
||||
|
||||
// Pick an encoding mode appropriate for the content. Note that this will not attempt to use
|
||||
@@ -144,9 +141,7 @@ pub fn encode_with_hints(
|
||||
|
||||
// Append ECI segment if applicable
|
||||
if mode == Mode::BYTE && has_encoding_hint {
|
||||
if let Some(eci) = CharacterSetECI::getCharacterSetECI(encoding) {
|
||||
appendECI(&eci, &mut header_bits)?;
|
||||
}
|
||||
appendECI(&encoding, &mut header_bits)?;
|
||||
}
|
||||
|
||||
// Append the FNC1 mode header for GS1 formatted data if applicable
|
||||
@@ -304,15 +299,15 @@ pub fn getAlphanumericCode(code: u32) -> i8 {
|
||||
}
|
||||
|
||||
pub fn chooseMode(content: &str) -> Mode {
|
||||
chooseModeWithEncoding(content, encoding::all::ISO_8859_1)
|
||||
chooseModeWithEncoding(content, CharacterSetECI::ISO8859_1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
|
||||
* if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
|
||||
*/
|
||||
fn chooseModeWithEncoding(content: &str, encoding: EncodingRef) -> Mode {
|
||||
if SHIFT_JIS_CHARSET.name() == encoding.name() && isOnlyDoubleByteKanji(content) {
|
||||
fn chooseModeWithEncoding(content: &str, encoding: CharacterSetECI) -> Mode {
|
||||
if SHIFT_JIS_CHARSET == encoding && isOnlyDoubleByteKanji(content) {
|
||||
// Choose Kanji mode if all input are double-byte characters
|
||||
return Mode::KANJI;
|
||||
}
|
||||
@@ -337,7 +332,7 @@ fn chooseModeWithEncoding(content: &str, encoding: EncodingRef) -> Mode {
|
||||
}
|
||||
|
||||
pub fn isOnlyDoubleByteKanji(content: &str) -> bool {
|
||||
let bytes = if let Ok(byt) = SHIFT_JIS_CHARSET.encode(content, encoding::EncoderTrap::Strict) {
|
||||
let bytes = if let Ok(byt) = SHIFT_JIS_CHARSET.encode(content) {
|
||||
byt
|
||||
} else {
|
||||
return false;
|
||||
@@ -638,7 +633,7 @@ pub fn appendBytes(
|
||||
content: &str,
|
||||
mode: Mode,
|
||||
bits: &mut BitArray,
|
||||
encoding: EncodingRef,
|
||||
encoding: CharacterSetECI,
|
||||
) -> Result<()> {
|
||||
match mode {
|
||||
Mode::NUMERIC => appendNumericBytes(content, bits),
|
||||
@@ -725,9 +720,9 @@ pub fn appendAlphanumericBytes(content: &str, bits: &mut BitArray) -> Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn append8BitBytes(content: &str, bits: &mut BitArray, encoding: EncodingRef) -> Result<()> {
|
||||
pub fn append8BitBytes(content: &str, bits: &mut BitArray, encoding: CharacterSetECI) -> Result<()> {
|
||||
let bytes = encoding
|
||||
.encode(content, encoding::EncoderTrap::Strict)
|
||||
.encode(content)
|
||||
.map_err(|e| Exceptions::writer_with(format!("error {e}")))?;
|
||||
for b in bytes {
|
||||
bits.appendBits(b as u32, 8)?;
|
||||
@@ -739,7 +734,7 @@ pub fn appendKanjiBytes(content: &str, bits: &mut BitArray) -> Result<()> {
|
||||
let sjis = &SHIFT_JIS_CHARSET;
|
||||
|
||||
let bytes = sjis
|
||||
.encode(content, encoding::EncoderTrap::Strict)
|
||||
.encode(content)
|
||||
.map_err(|e| Exceptions::writer_with(format!("error {e}")))?;
|
||||
if bytes.len() % 2 != 0 {
|
||||
return Err(Exceptions::writer_with("Kanji byte size not even"));
|
||||
|
||||
@@ -23,9 +23,8 @@ use std::{
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
use encoding::Encoding;
|
||||
use rxing::{
|
||||
common::{HybridBinarizer, Result},
|
||||
common::{HybridBinarizer, Result, CharacterSetECI},
|
||||
multi::MultipleBarcodeReader,
|
||||
pdf417::PDF417RXingResultMetadata,
|
||||
BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType, DecodeHintValue,
|
||||
@@ -646,9 +645,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
|
||||
if ext == "bin" {
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
File::open(&file)?.read_to_end(&mut buffer)?;
|
||||
encoding::all::ISO_8859_1
|
||||
.decode(&buffer, encoding::DecoderTrap::Replace)
|
||||
.expect("decode")
|
||||
CharacterSetECI::ISO8859_1.decode_replace(&buffer).expect("decode")
|
||||
} else {
|
||||
read_to_string(&file).expect("ok")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user