rename character set and rename methods

This commit is contained in:
Henry Schimke
2023-03-04 11:47:39 -06:00
parent c81c6578d0
commit 15859b9f10
29 changed files with 329 additions and 363 deletions

View File

@@ -15,7 +15,7 @@
*/
use crate::{
common::{BitSource, CharacterSetECI, DecoderRXingResult, Result, StringUtils},
common::{BitSource, CharacterSet, DecoderRXingResult, Result, StringUtils},
DecodingHintDictionary, Exceptions,
};
@@ -91,7 +91,7 @@ pub fn decode(
Mode::ECI => {
// Count doesn't apply to ECI
let value = parseECIValue(&mut bits)?;
currentCharacterSetECI = CharacterSetECI::getCharacterSetECIByValue(value).ok();
currentCharacterSetECI = CharacterSet::get_character_set_by_eci(value).ok();
if currentCharacterSetECI.is_none() {
return Err(Exceptions::format_with(format!(
"Value of {value} not valid"
@@ -203,7 +203,7 @@ fn decodeHanziSegment(bits: &mut BitSource, result: &mut String, count: usize) -
count -= 1;
}
let gb_encoder = CharacterSetECI::GB18030;
let gb_encoder = CharacterSet::GB18030;
let encode_string = gb_encoder
.decode(&buffer)
.map_err(|e| Exceptions::parse_with(format!("unable to decode buffer {buffer:?}: {e}")))?;
@@ -215,7 +215,7 @@ fn decodeKanjiSegment(
bits: &mut BitSource,
result: &mut String,
count: usize,
currentCharacterSetECI: Option<CharacterSetECI>,
currentCharacterSetECI: Option<CharacterSet>,
hints: &DecodingHintDictionary,
) -> Result<()> {
// Don't crash trying to read more bits than we have available.
@@ -249,7 +249,7 @@ fn decodeKanjiSegment(
let encoder = {
let _ = currentCharacterSetECI;
let _ = hints;
CharacterSetECI::SJIS
CharacterSet::SJIS
};
#[cfg(feature = "allow_forced_iso_ied_18004_compliance")]
@@ -257,12 +257,12 @@ fn decodeKanjiSegment(
hints.get(&DecodeHintType::QR_ASSUME_SPEC_CONFORM_INPUT)
{
if let Some(ccse) = &currentCharacterSetECI {
CharacterSetECI::getCharacterSetECIByName(ccse)
CharacterSet::getCharacterSetECIByName(ccse)
} else {
CharacterSetECI::ISO8859_1
CharacterSet::ISO8859_1
}
} else {
CharacterSetECI::SJIS
CharacterSet::SJIS
};
let encode_string = encoder
@@ -278,7 +278,7 @@ fn decodeByteSegment(
bits: &mut BitSource,
result: &mut String,
count: usize,
currentCharacterSetECI: Option<CharacterSetECI>,
currentCharacterSetECI: Option<CharacterSet>,
byteSegments: &mut Vec<Vec<u8>>,
hints: &DecodingHintDictionary,
) -> Result<()> {
@@ -307,7 +307,7 @@ fn decodeByteSegment(
if let Some(DecodeHintValue::QrAssumeSpecConformInput(true)) =
hints.get(&DecodeHintType::QR_ASSUME_SPEC_CONFORM_INPUT)
{
CharacterSetECI::ISO8859_1
CharacterSet::ISO8859_1
} else {
StringUtils::guessCharset(&readBytes, hints).ok_or(Exceptions::ILLEGAL_STATE)?
}

View File

@@ -17,7 +17,7 @@
use std::collections::HashMap;
use crate::{
common::{BitArray, CharacterSetECI},
common::{BitArray, CharacterSet},
qrcode::{
decoder::{ErrorCorrectionLevel, Mode, Version},
encoder::{qrcode_encoder, MinimalEncoder},
@@ -28,7 +28,7 @@ use once_cell::sync::Lazy;
use super::QRCode;
static SHIFT_JIS_CHARSET: Lazy<CharacterSetECI> = Lazy::new(|| CharacterSetECI::SJIS);
static SHIFT_JIS_CHARSET: Lazy<CharacterSet> = Lazy::new(|| CharacterSet::SJIS);
/**
* @author satorux@google.com (Satoru Takabayashi) - creator
@@ -1108,7 +1108,7 @@ fn testMinimalEncoder44() {
fn verifyMinimalEncoding(
input: &str,
expectedRXingResult: &str,
priorityCharset: Option<CharacterSetECI>,
priorityCharset: Option<CharacterSet>,
isGS1: bool,
) {
let result = MinimalEncoder::encode_with_details(

View File

@@ -17,7 +17,7 @@
use std::{fmt, rc::Rc};
use crate::{
common::{BitArray, CharacterSetECI, ECIEncoderSet, Result},
common::{BitArray, CharacterSet, ECIEncoderSet, Result},
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
Exceptions,
};
@@ -105,7 +105,7 @@ impl MinimalEncoder {
*/
pub fn new(
stringToEncode: &str,
priorityCharset: Option<CharacterSetECI>,
priorityCharset: Option<CharacterSet>,
isGS1: bool,
ecLevel: ErrorCorrectionLevel,
) -> Self {
@@ -140,7 +140,7 @@ impl MinimalEncoder {
pub fn encode_with_details(
stringToEncode: &str,
version: Option<VersionRef>,
priorityCharset: Option<CharacterSetECI>,
priorityCharset: Option<CharacterSet>,
isGS1: bool,
ecLevel: ErrorCorrectionLevel,
) -> Result<RXingResultList> {
@@ -1045,7 +1045,7 @@ impl fmt::Display for RXingResultNode {
self.encoders
.getCharset(self.charsetEncoderIndex)
.ok_or(fmt::Error)?
.getCharsetName(),
.get_charset_name(),
);
} else {
let sub_string: String = self

View File

@@ -24,7 +24,7 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::{
common::{
reedsolomon::{get_predefined_genericgf, PredefinedGenericGF, ReedSolomonEncoder},
BitArray, CharacterSetECI, Result,
BitArray, CharacterSet, Result,
},
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions,
@@ -32,7 +32,7 @@ use crate::{
use super::{mask_util, matrix_util, BlockPair, ByteMatrix, MinimalEncoder, QRCode};
static SHIFT_JIS_CHARSET: CharacterSetECI = CharacterSetECI::SJIS;
static SHIFT_JIS_CHARSET: CharacterSet = CharacterSet::SJIS;
// The original table is defined in the table 5 of JISX0510:2004 (p.19).
const ALPHANUMERIC_TABLE: [i8; 96] = [
@@ -44,7 +44,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: CharacterSetECI = CharacterSetECI::ISO8859_1;
pub const DEFAULT_BYTE_MODE_ENCODING: CharacterSet = CharacterSet::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.
@@ -96,7 +96,7 @@ pub fn encode_with_hints(
let mut has_encoding_hint = hints.contains_key(&EncodeHintType::CHARACTER_SET);
if has_encoding_hint {
if let Some(EncodeHintValue::CharacterSet(v)) = hints.get(&EncodeHintType::CHARACTER_SET) {
encoding = Some(CharacterSetECI::getCharacterSetECIByName(v).ok_or(Exceptions::WRITER)?)
encoding = Some(CharacterSet::get_character_set_by_name(v).ok_or(Exceptions::WRITER)?)
}
}
@@ -124,7 +124,7 @@ pub fn encode_with_hints(
DEFAULT_BYTE_MODE_ENCODING
} else {
has_encoding_hint = true;
CharacterSetECI::UTF8
CharacterSet::UTF8
};
// Pick an encoding mode appropriate for the content. Note that this will not attempt to use
@@ -295,14 +295,14 @@ pub fn getAlphanumericCode(code: u32) -> i8 {
}
pub fn chooseMode(content: &str) -> Mode {
chooseModeWithEncoding(content, CharacterSetECI::ISO8859_1)
chooseModeWithEncoding(content, CharacterSet::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: CharacterSetECI) -> Mode {
fn chooseModeWithEncoding(content: &str, encoding: CharacterSet) -> Mode {
if SHIFT_JIS_CHARSET == encoding && isOnlyDoubleByteKanji(content) {
// Choose Kanji mode if all input are double-byte characters
return Mode::KANJI;
@@ -629,7 +629,7 @@ pub fn appendBytes(
content: &str,
mode: Mode,
bits: &mut BitArray,
encoding: CharacterSetECI,
encoding: CharacterSet,
) -> Result<()> {
match mode {
Mode::NUMERIC => appendNumericBytes(content, bits),
@@ -719,7 +719,7 @@ pub fn appendAlphanumericBytes(content: &str, bits: &mut BitArray) -> Result<()>
pub fn append8BitBytes(
content: &str,
bits: &mut BitArray,
encoding: CharacterSetECI,
encoding: CharacterSet,
) -> Result<()> {
let bytes = encoding
.encode(content)
@@ -762,8 +762,8 @@ pub fn appendKanjiBytes(content: &str, bits: &mut BitArray) -> Result<()> {
Ok(())
}
fn appendECI(eci: &CharacterSetECI, bits: &mut BitArray) -> Result<()> {
fn appendECI(eci: &CharacterSet, bits: &mut BitArray) -> Result<()> {
bits.appendBits(Mode::ECI.getBits() as u32, 4)?;
// This is correct for values up to 127, which is all we need now.
bits.appendBits(eci.getValueSelf(), 8)
bits.appendBits(eci.get_eci_value(), 8)
}