repurpose CharacterSetECI as encoding abstraction

This commit is contained in:
Henry Schimke
2023-03-02 15:50:56 -06:00
parent c4fec7d2ee
commit a0b8b68869
29 changed files with 304 additions and 337 deletions

View File

@@ -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);
}