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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user