mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-28 05:12:34 +00:00
rename character set and rename methods
This commit is contained in:
@@ -23,7 +23,7 @@ use crate::{
|
|||||||
encoder::HighLevelEncoder,
|
encoder::HighLevelEncoder,
|
||||||
shared_test_methods::{stripSpace, toBitArray, toBooleanArray},
|
shared_test_methods::{stripSpace, toBitArray, toBooleanArray},
|
||||||
},
|
},
|
||||||
common::CharacterSetECI,
|
common::CharacterSet,
|
||||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Point,
|
BarcodeFormat, EncodeHintType, EncodeHintValue, Point,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,10 +40,10 @@ use rand::Rng;
|
|||||||
* @author Frank Yellin
|
* @author Frank Yellin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const ISO_8859_1: CharacterSetECI = CharacterSetECI::ISO8859_1; //StandardCharsets.ISO_8859_1;
|
const ISO_8859_1: CharacterSet = CharacterSet::ISO8859_1; //StandardCharsets.ISO_8859_1;
|
||||||
const UTF_8: CharacterSetECI = CharacterSetECI::UTF8; //StandardCharsets.UTF_8;
|
const UTF_8: CharacterSet = CharacterSet::UTF8; //StandardCharsets.UTF_8;
|
||||||
const ISO_8859_15: CharacterSetECI = CharacterSetECI::ISO8859_15; //Charset.forName("ISO-8859-15");
|
const ISO_8859_15: CharacterSet = CharacterSet::ISO8859_15; //Charset.forName("ISO-8859-15");
|
||||||
const WINDOWS_1252: CharacterSetECI = CharacterSetECI::Cp1252; //Charset.forName("Windows-1252");
|
const WINDOWS_1252: CharacterSet = CharacterSet::Cp1252; //Charset.forName("Windows-1252");
|
||||||
|
|
||||||
// const DOTX: &str = "[^.X]";
|
// const DOTX: &str = "[^.X]";
|
||||||
// const SPACES: &str = "\\s+";
|
// const SPACES: &str = "\\s+";
|
||||||
@@ -137,8 +137,8 @@ X X X X X X X X X X X X X
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testAztecWriter() {
|
fn testAztecWriter() {
|
||||||
let shift_jis: CharacterSetECI =
|
let shift_jis: CharacterSet =
|
||||||
CharacterSetECI::getCharacterSetECIByName("Shift_JIS").expect("must exist");
|
CharacterSet::get_character_set_by_name("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", 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("Espa\u{00F1}ol", Some(ISO_8859_1), 25, true, 1); // Explicit ISO-8859-1
|
||||||
@@ -148,7 +148,7 @@ fn testAztecWriter() {
|
|||||||
testWriter("\u{20AC} 1 sample data.", Some(ISO_8859_15), 0, true, 2);
|
testWriter("\u{20AC} 1 sample data.", Some(ISO_8859_15), 0, true, 2);
|
||||||
testWriter(
|
testWriter(
|
||||||
"\u{20AC} 1 sample data.",
|
"\u{20AC} 1 sample data.",
|
||||||
Some(CharacterSetECI::UnicodeBigUnmarked),
|
Some(CharacterSet::UnicodeBigUnmarked),
|
||||||
0,
|
0,
|
||||||
true,
|
true,
|
||||||
3,
|
3,
|
||||||
@@ -709,7 +709,7 @@ fn testEncodeDecode(data: &str, compact: bool, layers: u32) {
|
|||||||
|
|
||||||
fn testWriter(
|
fn testWriter(
|
||||||
data: &str,
|
data: &str,
|
||||||
charset: Option<CharacterSetECI>,
|
charset: Option<CharacterSet>,
|
||||||
ecc_percent: u32,
|
ecc_percent: u32,
|
||||||
compact: bool,
|
compact: bool,
|
||||||
layers: u32,
|
layers: u32,
|
||||||
@@ -719,7 +719,7 @@ fn testWriter(
|
|||||||
if charset.is_some() {
|
if charset.is_some() {
|
||||||
hints.insert(
|
hints.insert(
|
||||||
EncodeHintType::CHARACTER_SET,
|
EncodeHintType::CHARACTER_SET,
|
||||||
EncodeHintValue::CharacterSet(charset.unwrap().getCharsetName().to_string()),
|
EncodeHintValue::CharacterSet(charset.unwrap().get_charset_name().to_string()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// if (null != charset) {
|
// if (null != charset) {
|
||||||
@@ -735,7 +735,7 @@ fn testWriter(
|
|||||||
|
|
||||||
let cset = match charset {
|
let cset = match charset {
|
||||||
Some(cs) => cs,
|
Some(cs) => cs,
|
||||||
None => CharacterSetECI::ISO8859_1,
|
None => CharacterSet::ISO8859_1,
|
||||||
};
|
};
|
||||||
let aztec = aztec_encoder::encode_with_charset(
|
let aztec = aztec_encoder::encode_with_charset(
|
||||||
data,
|
data,
|
||||||
@@ -818,10 +818,10 @@ fn testStuffBits(wordSize: usize, bits: &str, expected: &str) {
|
|||||||
|
|
||||||
fn testHighLevelEncodeStringUtf8(s: &str, expectedBits: &str) {
|
fn testHighLevelEncodeStringUtf8(s: &str, expectedBits: &str) {
|
||||||
let bits = HighLevelEncoder::with_charset(
|
let bits = HighLevelEncoder::with_charset(
|
||||||
CharacterSetECI::UTF8
|
CharacterSet::UTF8
|
||||||
.encode(s)
|
.encode(s)
|
||||||
.expect("should encode to bytes"),
|
.expect("should encode to bytes"),
|
||||||
CharacterSetECI::UTF8,
|
CharacterSet::UTF8,
|
||||||
)
|
)
|
||||||
.encode()
|
.encode()
|
||||||
.expect("high level ok");
|
.expect("high level ok");
|
||||||
@@ -841,7 +841,7 @@ fn testHighLevelEncodeStringUtf8(s: &str, expectedBits: &str) {
|
|||||||
|
|
||||||
fn testHighLevelEncodeString(s: &str, expectedBits: &str) {
|
fn testHighLevelEncodeString(s: &str, expectedBits: &str) {
|
||||||
let bits = HighLevelEncoder::new(
|
let bits = HighLevelEncoder::new(
|
||||||
CharacterSetECI::ISO8859_1
|
CharacterSet::ISO8859_1
|
||||||
.encode(s)
|
.encode(s)
|
||||||
.expect("should encode to bytes"),
|
.expect("should encode to bytes"),
|
||||||
)
|
)
|
||||||
@@ -862,7 +862,7 @@ fn testHighLevelEncodeString(s: &str, expectedBits: &str) {
|
|||||||
|
|
||||||
fn testHighLevelEncodeStringCount(s: &str, expectedReceivedBits: u32) {
|
fn testHighLevelEncodeStringCount(s: &str, expectedReceivedBits: u32) {
|
||||||
let bits = HighLevelEncoder::new(
|
let bits = HighLevelEncoder::new(
|
||||||
CharacterSetECI::ISO8859_1
|
CharacterSet::ISO8859_1
|
||||||
.encode(s)
|
.encode(s)
|
||||||
.expect("should encode to bytes"),
|
.expect("should encode to bytes"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitMatrix, CharacterSetECI, Result},
|
common::{BitMatrix, CharacterSet, Result},
|
||||||
exceptions::Exceptions,
|
exceptions::Exceptions,
|
||||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Writer,
|
BarcodeFormat, EncodeHintType, EncodeHintValue, Writer,
|
||||||
};
|
};
|
||||||
@@ -56,7 +56,7 @@ impl Writer for AztecWriter {
|
|||||||
hints.get(&EncodeHintType::CHARACTER_SET)
|
hints.get(&EncodeHintType::CHARACTER_SET)
|
||||||
{
|
{
|
||||||
if cset_name.to_lowercase() != "iso-8859-1" {
|
if cset_name.to_lowercase() != "iso-8859-1" {
|
||||||
charset = CharacterSetECI::getCharacterSetECIByName(cset_name);
|
charset = CharacterSet::get_character_set_by_name(cset_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(EncodeHintValue::ErrorCorrection(ecc_level)) =
|
if let Some(EncodeHintValue::ErrorCorrection(ecc_level)) =
|
||||||
@@ -86,7 +86,7 @@ fn encode(
|
|||||||
format: BarcodeFormat,
|
format: BarcodeFormat,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
charset: Option<CharacterSetECI>,
|
charset: Option<CharacterSet>,
|
||||||
ecc_percent: u32,
|
ecc_percent: u32,
|
||||||
layers: i32,
|
layers: i32,
|
||||||
) -> Result<BitMatrix> {
|
) -> Result<BitMatrix> {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use crate::{
|
|||||||
reedsolomon::{
|
reedsolomon::{
|
||||||
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonDecoder,
|
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonDecoder,
|
||||||
},
|
},
|
||||||
BitMatrix, CharacterSetECI, DecoderRXingResult, DetectorRXingResult, Result,
|
BitMatrix, CharacterSet, DecoderRXingResult, DetectorRXingResult, Result,
|
||||||
},
|
},
|
||||||
exceptions::Exceptions,
|
exceptions::Exceptions,
|
||||||
};
|
};
|
||||||
@@ -114,7 +114,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
|
|||||||
// when character encoding changes (ECI) or input ends.
|
// when character encoding changes (ECI) or input ends.
|
||||||
let mut decoded_bytes: Vec<u8> = Vec::new();
|
let mut decoded_bytes: Vec<u8> = Vec::new();
|
||||||
|
|
||||||
let mut encdr: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
let mut encdr: CharacterSet = CharacterSet::ISO8859_1;
|
||||||
|
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String> {
|
|||||||
eci = eci * 10 + (next_digit - 2);
|
eci = eci * 10 + (next_digit - 2);
|
||||||
n -= 1;
|
n -= 1;
|
||||||
}
|
}
|
||||||
let charset_eci = CharacterSetECI::getCharacterSetECIByValue(eci);
|
let charset_eci = CharacterSet::get_character_set_by_eci(eci);
|
||||||
if charset_eci.is_err() {
|
if charset_eci.is_err() {
|
||||||
return Err(Exceptions::format_with("Charset must exist"));
|
return Err(Exceptions::format_with("Charset must exist"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use crate::{
|
|||||||
reedsolomon::{
|
reedsolomon::{
|
||||||
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonEncoder,
|
get_predefined_genericgf, GenericGFRef, PredefinedGenericGF, ReedSolomonEncoder,
|
||||||
},
|
},
|
||||||
BitArray, BitMatrix, CharacterSetECI, Result,
|
BitArray, BitMatrix, CharacterSet, Result,
|
||||||
},
|
},
|
||||||
exceptions::Exceptions,
|
exceptions::Exceptions,
|
||||||
};
|
};
|
||||||
@@ -49,7 +49,7 @@ pub const WORD_SIZE: [u32; 33] = [
|
|||||||
* @return Aztec symbol matrix with metadata
|
* @return Aztec symbol matrix with metadata
|
||||||
*/
|
*/
|
||||||
pub fn encode_simple(data: &str) -> Result<AztecCode> {
|
pub fn encode_simple(data: &str) -> Result<AztecCode> {
|
||||||
let Ok(bytes) =CharacterSetECI::ISO8859_1.encode_replace(data) else {
|
let Ok(bytes) =CharacterSet::ISO8859_1.encode_replace(data) else {
|
||||||
return Err(Exceptions::illegal_argument_with(format!("'{data}' cannot be encoded as ISO_8859_1")));
|
return Err(Exceptions::illegal_argument_with(format!("'{data}' cannot be encoded as ISO_8859_1")));
|
||||||
};
|
};
|
||||||
encode_bytes_simple(&bytes)
|
encode_bytes_simple(&bytes)
|
||||||
@@ -65,7 +65,7 @@ pub fn encode_simple(data: &str) -> Result<AztecCode> {
|
|||||||
* @return Aztec symbol matrix with metadata
|
* @return Aztec symbol matrix with metadata
|
||||||
*/
|
*/
|
||||||
pub fn encode(data: &str, minECCPercent: u32, userSpecifiedLayers: i32) -> Result<AztecCode> {
|
pub fn encode(data: &str, minECCPercent: u32, userSpecifiedLayers: i32) -> Result<AztecCode> {
|
||||||
if let Ok(bytes) = CharacterSetECI::ISO8859_1.encode(data) {
|
if let Ok(bytes) = CharacterSet::ISO8859_1.encode(data) {
|
||||||
encode_bytes(&bytes, minECCPercent, userSpecifiedLayers)
|
encode_bytes(&bytes, minECCPercent, userSpecifiedLayers)
|
||||||
} else {
|
} else {
|
||||||
Err(Exceptions::illegal_argument_with(format!(
|
Err(Exceptions::illegal_argument_with(format!(
|
||||||
@@ -90,7 +90,7 @@ pub fn encode_with_charset(
|
|||||||
data: &str,
|
data: &str,
|
||||||
minECCPercent: u32,
|
minECCPercent: u32,
|
||||||
userSpecifiedLayers: i32,
|
userSpecifiedLayers: i32,
|
||||||
charset: CharacterSetECI,
|
charset: CharacterSet,
|
||||||
) -> Result<AztecCode> {
|
) -> Result<AztecCode> {
|
||||||
if let Ok(bytes) = charset.encode(data) {
|
if let Ok(bytes) = charset.encode(data) {
|
||||||
encode_bytes_with_charset(&bytes, minECCPercent, userSpecifiedLayers, charset)
|
encode_bytes_with_charset(&bytes, minECCPercent, userSpecifiedLayers, charset)
|
||||||
@@ -129,7 +129,7 @@ pub fn encode_bytes(
|
|||||||
data,
|
data,
|
||||||
minECCPercent,
|
minECCPercent,
|
||||||
userSpecifiedLayers,
|
userSpecifiedLayers,
|
||||||
CharacterSetECI::ISO8859_1,
|
CharacterSet::ISO8859_1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ pub fn encode_bytes_with_charset(
|
|||||||
data: &[u8],
|
data: &[u8],
|
||||||
min_eccpercent: u32,
|
min_eccpercent: u32,
|
||||||
user_specified_layers: i32,
|
user_specified_layers: i32,
|
||||||
charset: CharacterSetECI,
|
charset: CharacterSet,
|
||||||
) -> Result<AztecCode> {
|
) -> Result<AztecCode> {
|
||||||
// High-level encode
|
// High-level encode
|
||||||
let bits = HighLevelEncoder::with_charset(data.into(), charset).encode()?;
|
let bits = HighLevelEncoder::with_charset(data.into(), charset).encode()?;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::common::{BitArray, CharacterSetECI, Result};
|
use crate::common::{BitArray, CharacterSet, Result};
|
||||||
|
|
||||||
use super::{State, Token};
|
use super::{State, Token};
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ use super::{State, Token};
|
|||||||
*/
|
*/
|
||||||
pub struct HighLevelEncoder {
|
pub struct HighLevelEncoder {
|
||||||
text: Vec<u8>,
|
text: Vec<u8>,
|
||||||
charset: CharacterSetECI,
|
charset: CharacterSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HighLevelEncoder {
|
impl HighLevelEncoder {
|
||||||
@@ -226,11 +226,11 @@ impl HighLevelEncoder {
|
|||||||
pub fn new(text: Vec<u8>) -> Self {
|
pub fn new(text: Vec<u8>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text,
|
text,
|
||||||
charset: CharacterSetECI::ISO8859_1,
|
charset: CharacterSet::ISO8859_1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_charset(text: Vec<u8>, charset: CharacterSetECI) -> Self {
|
pub fn with_charset(text: Vec<u8>, charset: CharacterSet) -> Self {
|
||||||
Self { text, charset }
|
Self { text, charset }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,9 +240,9 @@ impl HighLevelEncoder {
|
|||||||
pub fn encode(&self) -> Result<BitArray> {
|
pub fn encode(&self) -> Result<BitArray> {
|
||||||
let mut initial_state = State::new(Token::new(), Self::MODE_UPPER as u32, 0, 0);
|
let mut initial_state = State::new(Token::new(), Self::MODE_UPPER as u32, 0, 0);
|
||||||
//if let Some(eci) = CharacterSetECI::getCharacterSetECI(self.charset) {
|
//if let Some(eci) = CharacterSetECI::getCharacterSetECI(self.charset) {
|
||||||
if self.charset != CharacterSetECI::ISO8859_1 {
|
if self.charset != CharacterSet::ISO8859_1 {
|
||||||
//} && eci != CharacterSetECI::Cp1252 {
|
//} && eci != CharacterSetECI::Cp1252 {
|
||||||
initial_state = initial_state.appendFLGn(self.charset.getValue())?;
|
initial_state = initial_state.appendFLGn(self.charset.get_eci_value())?;
|
||||||
}
|
}
|
||||||
// } else {
|
// } else {
|
||||||
// return Err(Exceptions::illegal_argument_with(
|
// return Err(Exceptions::illegal_argument_with(
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitArray, CharacterSetECI, Result},
|
common::{BitArray, CharacterSet, Result},
|
||||||
exceptions::Exceptions,
|
exceptions::Exceptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ impl State {
|
|||||||
));
|
));
|
||||||
// throw new IllegalArgumentException("ECI code must be between 0 and 999999");
|
// throw new IllegalArgumentException("ECI code must be between 0 and 999999");
|
||||||
} else {
|
} else {
|
||||||
let Ok(eci_digits) = CharacterSetECI::ISO8859_1
|
let Ok(eci_digits) = CharacterSet::ISO8859_1
|
||||||
.encode(&format!("{eci}"))
|
.encode(&format!("{eci}"))
|
||||||
else {
|
else {
|
||||||
return Err(Exceptions::ILLEGAL_ARGUMENT)
|
return Err(Exceptions::ILLEGAL_ARGUMENT)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use regex::Regex;
|
|||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::{common::CharacterSetECI, RXingResult};
|
use crate::{common::CharacterSet, RXingResult};
|
||||||
|
|
||||||
use uriparse::URI;
|
use uriparse::URI;
|
||||||
|
|
||||||
@@ -404,7 +404,7 @@ fn maybeAppendFragment(fragmentBuffer: &mut Vec<u8>, charset: &str, result: &mut
|
|||||||
if charset.is_empty() {
|
if charset.is_empty() {
|
||||||
fragment = String::from_utf8(fragmentBytes).unwrap_or_else(|_| String::default());
|
fragment = String::from_utf8(fragmentBytes).unwrap_or_else(|_| String::default());
|
||||||
// fragment = new String(fragmentBytes, StandardCharsets.UTF_8);
|
// fragment = new String(fragmentBytes, StandardCharsets.UTF_8);
|
||||||
} else if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(charset) {
|
} else if let Some(enc) = CharacterSet::get_character_set_by_name(charset) {
|
||||||
fragment = if let Ok(encoded_result) = enc.decode(&fragmentBytes) {
|
fragment = if let Ok(encoded_result) = enc.decode(&fragmentBytes) {
|
||||||
encoded_result
|
encoded_result
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use crate::common::StringUtils;
|
use crate::common::StringUtils;
|
||||||
|
|
||||||
use super::CharacterSetECI;
|
use super::CharacterSet;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_random() {
|
fn test_random() {
|
||||||
@@ -39,7 +39,7 @@ fn test_random() {
|
|||||||
// *byte = r.gen();
|
// *byte = r.gen();
|
||||||
// }
|
// }
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
CharacterSetECI::UTF8,
|
CharacterSet::UTF8,
|
||||||
StringUtils::guessCharset(&bytes, &HashMap::new()).unwrap()
|
StringUtils::guessCharset(&bytes, &HashMap::new()).unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -47,13 +47,13 @@ fn test_random() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_short_shift_jis1() {
|
fn test_short_shift_jis1() {
|
||||||
// 金魚
|
// 金魚
|
||||||
do_test(&[0x8b, 0xe0, 0x8b, 0x9b], CharacterSetECI::SJIS, "SJIS");
|
do_test(&[0x8b, 0xe0, 0x8b, 0x9b], CharacterSet::SJIS, "SJIS");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_short_iso885911() {
|
fn test_short_iso885911() {
|
||||||
// båd
|
// båd
|
||||||
do_test(&[0x62, 0xe5, 0x64], CharacterSetECI::ISO8859_1, "ISO8859_1");
|
do_test(&[0x62, 0xe5, 0x64], CharacterSet::ISO8859_1, "ISO8859_1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -61,7 +61,7 @@ fn test_short_utf8() {
|
|||||||
// Español
|
// Español
|
||||||
do_test(
|
do_test(
|
||||||
&[0x45, 0x73, 0x70, 0x61, 0xc3, 0xb1, 0x6f, 0x6c],
|
&[0x45, 0x73, 0x70, 0x61, 0xc3, 0xb1, 0x6f, 0x6c],
|
||||||
CharacterSetECI::UTF8,
|
CharacterSet::UTF8,
|
||||||
"UTF8",
|
"UTF8",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ fn test_mixed_shift_jis1() {
|
|||||||
// Hello 金!
|
// Hello 金!
|
||||||
do_test(
|
do_test(
|
||||||
&[0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x8b, 0xe0, 0x21],
|
&[0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x8b, 0xe0, 0x21],
|
||||||
CharacterSetECI::SJIS,
|
CharacterSet::SJIS,
|
||||||
"SJIS",
|
"SJIS",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -81,8 +81,8 @@ fn test_utf16_be() {
|
|||||||
// 调压柜
|
// 调压柜
|
||||||
do_test(
|
do_test(
|
||||||
&[0xFE, 0xFF, 0x8c, 0x03, 0x53, 0x8b, 0x67, 0xdc],
|
&[0xFE, 0xFF, 0x8c, 0x03, 0x53, 0x8b, 0x67, 0xdc],
|
||||||
CharacterSetECI::UnicodeBigUnmarked,
|
CharacterSet::UnicodeBigUnmarked,
|
||||||
CharacterSetECI::UnicodeBigUnmarked.getCharsetName(),
|
CharacterSet::UnicodeBigUnmarked.get_charset_name(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,12 +91,12 @@ fn test_utf16_le() {
|
|||||||
// 调压柜
|
// 调压柜
|
||||||
do_test(
|
do_test(
|
||||||
&[0xFF, 0xFE, 0x03, 0x8c, 0x8b, 0x53, 0xdc, 0x67],
|
&[0xFF, 0xFE, 0x03, 0x8c, 0x8b, 0x53, 0xdc, 0x67],
|
||||||
CharacterSetECI::UTF16LE,
|
CharacterSet::UTF16LE,
|
||||||
CharacterSetECI::UTF16LE.getCharsetName(),
|
CharacterSet::UTF16LE.get_charset_name(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_test(bytes: &[u8], charset: CharacterSetECI, encoding: &str) {
|
fn do_test(bytes: &[u8], charset: CharacterSet, encoding: &str) {
|
||||||
let guessedCharset = StringUtils::guessCharset(bytes, &HashMap::new()).unwrap();
|
let guessedCharset = StringUtils::guessCharset(bytes, &HashMap::new()).unwrap();
|
||||||
let guessedEncoding = StringUtils::guessEncoding(bytes, &HashMap::new()).unwrap();
|
let guessedEncoding = StringUtils::guessEncoding(bytes, &HashMap::new()).unwrap();
|
||||||
assert_eq!(charset, guessedCharset);
|
assert_eq!(charset, guessedCharset);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use crate::Exceptions;
|
|||||||
* @author Sean Owen
|
* @author Sean Owen
|
||||||
*/
|
*/
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum CharacterSetECI {
|
pub enum CharacterSet {
|
||||||
// Enum name is a Java encoding valid for java.lang and java.io
|
// Enum name is a Java encoding valid for java.lang and java.io
|
||||||
Cp437, //(new int[]{0,2}),
|
Cp437, //(new int[]{0,2}),
|
||||||
ISO8859_1, //(new int[]{1,3}, "ISO-8859-1"),
|
ISO8859_1, //(new int[]{1,3}, "ISO-8859-1"),
|
||||||
@@ -56,187 +56,152 @@ pub enum CharacterSetECI {
|
|||||||
Big5, //(28),
|
Big5, //(28),
|
||||||
GB18030, //(29, "GB2312", "EUC_CN", "GBK"),
|
GB18030, //(29, "GB2312", "EUC_CN", "GBK"),
|
||||||
EUC_KR, //(30, "EUC-KR");
|
EUC_KR, //(30, "EUC-KR");
|
||||||
|
// Unknown,
|
||||||
|
// Binary,
|
||||||
}
|
}
|
||||||
impl CharacterSetECI {
|
impl CharacterSet {
|
||||||
// private static final Map<Integer,CharacterSetECI> VALUE_TO_ECI = new HashMap<>();
|
pub fn get_eci_value(&self) -> u32 {
|
||||||
// private static final Map<String,CharacterSetECI> NAME_TO_ECI = new HashMap<>();
|
|
||||||
// static {
|
|
||||||
// for (CharacterSetECI eci : values()) {
|
|
||||||
// for (int value : eci.values) {
|
|
||||||
// VALUE_TO_ECI.put(value, eci);
|
|
||||||
// }
|
|
||||||
// NAME_TO_ECI.put(eci.name(), eci);
|
|
||||||
// for (String name : eci.otherEncodingNames) {
|
|
||||||
// NAME_TO_ECI.put(name, eci);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private final int[] values;
|
|
||||||
// private final String[] otherEncodingNames;
|
|
||||||
|
|
||||||
// CharacterSetECI(int value) {
|
|
||||||
// this(new int[] {value});
|
|
||||||
// }
|
|
||||||
|
|
||||||
// CharacterSetECI(int value, String... otherEncodingNames) {
|
|
||||||
// this.values = new int[] {value};
|
|
||||||
// this.otherEncodingNames = otherEncodingNames;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// CharacterSetECI(int[] values, String... otherEncodingNames) {
|
|
||||||
// this.values = values;
|
|
||||||
// this.otherEncodingNames = otherEncodingNames;
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub fn getValueSelf(&self) -> u32 {
|
|
||||||
Self::getValue(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn getValue(&self) -> u32 {
|
|
||||||
match self {
|
match self {
|
||||||
CharacterSetECI::Cp437 => 0,
|
CharacterSet::Cp437 => 0,
|
||||||
CharacterSetECI::ISO8859_1 => 1,
|
CharacterSet::ISO8859_1 => 1,
|
||||||
CharacterSetECI::ISO8859_2 => 4,
|
CharacterSet::ISO8859_2 => 4,
|
||||||
CharacterSetECI::ISO8859_3 => 5,
|
CharacterSet::ISO8859_3 => 5,
|
||||||
CharacterSetECI::ISO8859_4 => 6,
|
CharacterSet::ISO8859_4 => 6,
|
||||||
CharacterSetECI::ISO8859_5 => 7,
|
CharacterSet::ISO8859_5 => 7,
|
||||||
// CharacterSetECI::ISO8859_6 => 8,
|
// CharacterSetECI::ISO8859_6 => 8,
|
||||||
CharacterSetECI::ISO8859_7 => 9,
|
CharacterSet::ISO8859_7 => 9,
|
||||||
// CharacterSetECI::ISO8859_8 => 10,
|
// CharacterSetECI::ISO8859_8 => 10,
|
||||||
CharacterSetECI::ISO8859_9 => 11,
|
CharacterSet::ISO8859_9 => 11,
|
||||||
// CharacterSetECI::ISO8859_10 => 12,
|
// CharacterSetECI::ISO8859_10 => 12,
|
||||||
// CharacterSetECI::ISO8859_11 => 13,
|
// CharacterSetECI::ISO8859_11 => 13,
|
||||||
CharacterSetECI::ISO8859_13 => 15,
|
CharacterSet::ISO8859_13 => 15,
|
||||||
// CharacterSetECI::ISO8859_14 => 16,
|
// CharacterSetECI::ISO8859_14 => 16,
|
||||||
CharacterSetECI::ISO8859_15 => 17,
|
CharacterSet::ISO8859_15 => 17,
|
||||||
CharacterSetECI::ISO8859_16 => 18,
|
CharacterSet::ISO8859_16 => 18,
|
||||||
CharacterSetECI::SJIS => 20,
|
CharacterSet::SJIS => 20,
|
||||||
CharacterSetECI::Cp1250 => 21,
|
CharacterSet::Cp1250 => 21,
|
||||||
CharacterSetECI::Cp1251 => 22,
|
CharacterSet::Cp1251 => 22,
|
||||||
CharacterSetECI::Cp1252 => 23,
|
CharacterSet::Cp1252 => 23,
|
||||||
CharacterSetECI::Cp1256 => 24,
|
CharacterSet::Cp1256 => 24,
|
||||||
CharacterSetECI::UnicodeBigUnmarked => 25,
|
CharacterSet::UnicodeBigUnmarked => 25,
|
||||||
CharacterSetECI::UTF16LE => 100025,
|
CharacterSet::UTF16LE => 100025,
|
||||||
CharacterSetECI::UTF8 => 26,
|
CharacterSet::UTF8 => 26,
|
||||||
CharacterSetECI::ASCII => 27,
|
CharacterSet::ASCII => 27,
|
||||||
CharacterSetECI::Big5 => 28,
|
CharacterSet::Big5 => 28,
|
||||||
CharacterSetECI::GB18030 => 29,
|
CharacterSet::GB18030 => 29,
|
||||||
CharacterSetECI::EUC_KR => 30,
|
CharacterSet::EUC_KR => 30,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getCharset(&self) -> EncodingRef {
|
fn get_base_encoder(&self) -> EncodingRef {
|
||||||
let name = match self {
|
let name = match self {
|
||||||
// CharacterSetECI::Cp437 => "CP437",
|
CharacterSet::Cp437 => "cp437",
|
||||||
CharacterSetECI::Cp437 => "cp437",
|
CharacterSet::ISO8859_1 => return encoding::all::ISO_8859_1,
|
||||||
CharacterSetECI::ISO8859_1 => return encoding::all::ISO_8859_1,
|
CharacterSet::ISO8859_2 => "ISO-8859-2",
|
||||||
CharacterSetECI::ISO8859_2 => "ISO-8859-2",
|
CharacterSet::ISO8859_3 => "ISO-8859-3",
|
||||||
CharacterSetECI::ISO8859_3 => "ISO-8859-3",
|
CharacterSet::ISO8859_4 => "ISO-8859-4",
|
||||||
CharacterSetECI::ISO8859_4 => "ISO-8859-4",
|
CharacterSet::ISO8859_5 => "ISO-8859-5",
|
||||||
CharacterSetECI::ISO8859_5 => "ISO-8859-5",
|
|
||||||
// CharacterSetECI::ISO8859_6 => "ISO-8859-6",
|
// CharacterSetECI::ISO8859_6 => "ISO-8859-6",
|
||||||
CharacterSetECI::ISO8859_7 => "ISO-8859-7",
|
CharacterSet::ISO8859_7 => "ISO-8859-7",
|
||||||
// CharacterSetECI::ISO8859_8 => "ISO-8859-8",
|
// CharacterSetECI::ISO8859_8 => "ISO-8859-8",
|
||||||
CharacterSetECI::ISO8859_9 => "ISO-8859-9",
|
CharacterSet::ISO8859_9 => "ISO-8859-9",
|
||||||
// CharacterSetECI::ISO8859_10 => "ISO-8859-10",
|
// CharacterSetECI::ISO8859_10 => "ISO-8859-10",
|
||||||
// CharacterSetECI::ISO8859_11 => "ISO-8859-11",
|
// CharacterSetECI::ISO8859_11 => "ISO-8859-11",
|
||||||
CharacterSetECI::ISO8859_13 => "ISO-8859-13",
|
CharacterSet::ISO8859_13 => "ISO-8859-13",
|
||||||
// CharacterSetECI::ISO8859_14 => "ISO-8859-14",
|
// CharacterSetECI::ISO8859_14 => "ISO-8859-14",
|
||||||
CharacterSetECI::ISO8859_15 => "ISO-8859-15",
|
CharacterSet::ISO8859_15 => "ISO-8859-15",
|
||||||
CharacterSetECI::ISO8859_16 => "ISO-8859-16",
|
CharacterSet::ISO8859_16 => "ISO-8859-16",
|
||||||
CharacterSetECI::SJIS => "shift_jis",
|
CharacterSet::SJIS => "shift_jis",
|
||||||
CharacterSetECI::Cp1250 => "windows-1250",
|
CharacterSet::Cp1250 => "windows-1250",
|
||||||
CharacterSetECI::Cp1251 => "windows-1251",
|
CharacterSet::Cp1251 => "windows-1251",
|
||||||
CharacterSetECI::Cp1252 => "windows-1252",
|
CharacterSet::Cp1252 => "windows-1252",
|
||||||
CharacterSetECI::Cp1256 => "windows-1256",
|
CharacterSet::Cp1256 => "windows-1256",
|
||||||
CharacterSetECI::UnicodeBigUnmarked => "UTF-16BE",
|
CharacterSet::UnicodeBigUnmarked => "UTF-16BE",
|
||||||
CharacterSetECI::UTF16LE => "UTF-16LE",
|
CharacterSet::UTF16LE => "UTF-16LE",
|
||||||
CharacterSetECI::UTF8 => "UTF-8",
|
CharacterSet::UTF8 => "UTF-8",
|
||||||
CharacterSetECI::ASCII => "US-ASCII",
|
CharacterSet::ASCII => "US-ASCII",
|
||||||
CharacterSetECI::Big5 => "Big5",
|
CharacterSet::Big5 => "Big5",
|
||||||
CharacterSetECI::GB18030 => "GB2312",
|
CharacterSet::GB18030 => "GB2312",
|
||||||
CharacterSetECI::EUC_KR => "EUC-KR",
|
CharacterSet::EUC_KR => "EUC-KR",
|
||||||
};
|
};
|
||||||
encoding::label::encoding_from_whatwg_label(name).unwrap()
|
encoding::label::encoding_from_whatwg_label(name).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getCharsetName(&self) -> &'static str {
|
pub fn get_charset_name(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
// CharacterSetECI::Cp437 => "CP437",
|
CharacterSet::Cp437 => "cp437",
|
||||||
CharacterSetECI::Cp437 => "cp437",
|
CharacterSet::ISO8859_1 => "iso-8859-1",
|
||||||
CharacterSetECI::ISO8859_1 => "iso-8859-1",
|
CharacterSet::ISO8859_2 => "iso-8859-2",
|
||||||
CharacterSetECI::ISO8859_2 => "iso-8859-2",
|
CharacterSet::ISO8859_3 => "iso-8859-3",
|
||||||
CharacterSetECI::ISO8859_3 => "iso-8859-3",
|
CharacterSet::ISO8859_4 => "iso-8859-4",
|
||||||
CharacterSetECI::ISO8859_4 => "iso-8859-4",
|
CharacterSet::ISO8859_5 => "iso-8859-5",
|
||||||
CharacterSetECI::ISO8859_5 => "iso-8859-5",
|
|
||||||
// CharacterSetECI::ISO8859_6 => "ISO-8859-6",
|
// CharacterSetECI::ISO8859_6 => "ISO-8859-6",
|
||||||
CharacterSetECI::ISO8859_7 => "iso-8859-7",
|
CharacterSet::ISO8859_7 => "iso-8859-7",
|
||||||
// CharacterSetECI::ISO8859_8 => "ISO-8859-8",
|
// CharacterSetECI::ISO8859_8 => "ISO-8859-8",
|
||||||
CharacterSetECI::ISO8859_9 => "iso-8859-9",
|
CharacterSet::ISO8859_9 => "iso-8859-9",
|
||||||
// CharacterSetECI::ISO8859_10 => "ISO-8859-10",
|
// CharacterSetECI::ISO8859_10 => "ISO-8859-10",
|
||||||
// CharacterSetECI::ISO8859_11 => "ISO-8859-11",
|
// CharacterSetECI::ISO8859_11 => "ISO-8859-11",
|
||||||
CharacterSetECI::ISO8859_13 => "iso-8859-13",
|
CharacterSet::ISO8859_13 => "iso-8859-13",
|
||||||
// CharacterSetECI::ISO8859_14 => "ISO-8859-14",
|
// CharacterSetECI::ISO8859_14 => "ISO-8859-14",
|
||||||
CharacterSetECI::ISO8859_15 => "iso-8859-15",
|
CharacterSet::ISO8859_15 => "iso-8859-15",
|
||||||
CharacterSetECI::ISO8859_16 => "iso-8859-16",
|
CharacterSet::ISO8859_16 => "iso-8859-16",
|
||||||
CharacterSetECI::SJIS => "shift_jis",
|
CharacterSet::SJIS => "shift_jis",
|
||||||
CharacterSetECI::Cp1250 => "windows-1250",
|
CharacterSet::Cp1250 => "windows-1250",
|
||||||
CharacterSetECI::Cp1251 => "windows-1251",
|
CharacterSet::Cp1251 => "windows-1251",
|
||||||
CharacterSetECI::Cp1252 => "windows-1252",
|
CharacterSet::Cp1252 => "windows-1252",
|
||||||
CharacterSetECI::Cp1256 => "windows-1256",
|
CharacterSet::Cp1256 => "windows-1256",
|
||||||
CharacterSetECI::UnicodeBigUnmarked => "utf-16be",
|
CharacterSet::UnicodeBigUnmarked => "utf-16be",
|
||||||
CharacterSetECI::UTF16LE => "utf-16le",
|
CharacterSet::UTF16LE => "utf-16le",
|
||||||
CharacterSetECI::UTF8 => "utf-8",
|
CharacterSet::UTF8 => "utf-8",
|
||||||
CharacterSetECI::ASCII => "us-ascii",
|
CharacterSet::ASCII => "us-ascii",
|
||||||
CharacterSetECI::Big5 => "big5",
|
CharacterSet::Big5 => "big5",
|
||||||
CharacterSetECI::GB18030 => "gb2312",
|
CharacterSet::GB18030 => "gb2312",
|
||||||
CharacterSetECI::EUC_KR => "euc-kr",
|
CharacterSet::EUC_KR => "euc-kr",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @param charset Java character set object
|
// * @param charset Java character set object
|
||||||
* @return CharacterSetECI representing ECI for character encoding, or null if it is legal
|
// * @return CharacterSetECI representing ECI for character encoding, or null if it is legal
|
||||||
* but unsupported
|
// * but unsupported
|
||||||
*/
|
// */
|
||||||
pub fn getCharacterSetECI(charset: EncodingRef) -> Option<CharacterSetECI> {
|
// fn get_character_set_eci(charset: EncodingRef) -> Option<CharacterSetECI> {
|
||||||
let name = if let Some(nm) = charset.whatwg_name() {
|
// let name = if let Some(nm) = charset.whatwg_name() {
|
||||||
nm
|
// nm
|
||||||
} else {
|
// } else {
|
||||||
charset.name()
|
// charset.name()
|
||||||
};
|
// };
|
||||||
match name {
|
// match name {
|
||||||
"cp437" => Some(CharacterSetECI::Cp437),
|
// "cp437" => Some(CharacterSetECI::Cp437),
|
||||||
"iso-8859-1" => Some(CharacterSetECI::ISO8859_1),
|
// "iso-8859-1" => Some(CharacterSetECI::ISO8859_1),
|
||||||
"iso-8859-2" => Some(CharacterSetECI::ISO8859_2),
|
// "iso-8859-2" => Some(CharacterSetECI::ISO8859_2),
|
||||||
"iso-8859-3" => Some(CharacterSetECI::ISO8859_3),
|
// "iso-8859-3" => Some(CharacterSetECI::ISO8859_3),
|
||||||
"iso-8859-4" => Some(CharacterSetECI::ISO8859_4),
|
// "iso-8859-4" => Some(CharacterSetECI::ISO8859_4),
|
||||||
"iso-8859-5" => Some(CharacterSetECI::ISO8859_5),
|
// "iso-8859-5" => Some(CharacterSetECI::ISO8859_5),
|
||||||
// "iso-8859-6" => Some(CharacterSetECI::ISO8859_6),
|
// // "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-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-10" => Some(CharacterSetECI::ISO8859_10),
|
||||||
// "iso-8859-11" => Some(CharacterSetECI::ISO8859_11),
|
// // "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-14" => Some(CharacterSetECI::ISO8859_14),
|
||||||
"iso-8859-15" => Some(CharacterSetECI::ISO8859_15),
|
// "iso-8859-15" => Some(CharacterSetECI::ISO8859_15),
|
||||||
"iso-8859-16" => Some(CharacterSetECI::ISO8859_16),
|
// "iso-8859-16" => Some(CharacterSetECI::ISO8859_16),
|
||||||
"shift_jis" => Some(CharacterSetECI::SJIS),
|
// "shift_jis" => Some(CharacterSetECI::SJIS),
|
||||||
"windows-1250" => Some(CharacterSetECI::Cp1250),
|
// "windows-1250" => Some(CharacterSetECI::Cp1250),
|
||||||
"windows-1251" => Some(CharacterSetECI::Cp1251),
|
// "windows-1251" => Some(CharacterSetECI::Cp1251),
|
||||||
"windows-1252" => Some(CharacterSetECI::Cp1252),
|
// "windows-1252" => Some(CharacterSetECI::Cp1252),
|
||||||
"windows-1256" => Some(CharacterSetECI::Cp1256),
|
// "windows-1256" => Some(CharacterSetECI::Cp1256),
|
||||||
"utf-16be" => Some(CharacterSetECI::UnicodeBigUnmarked),
|
// "utf-16be" => Some(CharacterSetECI::UnicodeBigUnmarked),
|
||||||
"utf-8" | "utf8" => Some(CharacterSetECI::UTF8),
|
// "utf-8" | "utf8" => Some(CharacterSetECI::UTF8),
|
||||||
"us-ascii" => Some(CharacterSetECI::ASCII),
|
// "us-ascii" => Some(CharacterSetECI::ASCII),
|
||||||
"big5" => Some(CharacterSetECI::Big5),
|
// "big5" => Some(CharacterSetECI::Big5),
|
||||||
"gb2312" => Some(CharacterSetECI::GB18030),
|
// "gb2312" => Some(CharacterSetECI::GB18030),
|
||||||
"euc-kr" => Some(CharacterSetECI::EUC_KR),
|
// "euc-kr" => Some(CharacterSetECI::EUC_KR),
|
||||||
_ => None,
|
// _ => None,
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param value character set ECI value
|
* @param value character set ECI value
|
||||||
@@ -244,35 +209,35 @@ impl CharacterSetECI {
|
|||||||
* unsupported
|
* unsupported
|
||||||
* @throws FormatException if ECI value is invalid
|
* @throws FormatException if ECI value is invalid
|
||||||
*/
|
*/
|
||||||
pub fn getCharacterSetECIByValue(value: u32) -> Result<CharacterSetECI> {
|
pub fn get_character_set_by_eci(value: u32) -> Result<CharacterSet> {
|
||||||
match value {
|
match value {
|
||||||
0 | 2 => Ok(CharacterSetECI::Cp437),
|
0 | 2 => Ok(CharacterSet::Cp437),
|
||||||
1 | 3 => Ok(CharacterSetECI::ISO8859_1),
|
1 | 3 => Ok(CharacterSet::ISO8859_1),
|
||||||
4 => Ok(CharacterSetECI::ISO8859_2),
|
4 => Ok(CharacterSet::ISO8859_2),
|
||||||
5 => Ok(CharacterSetECI::ISO8859_3),
|
5 => Ok(CharacterSet::ISO8859_3),
|
||||||
6 => Ok(CharacterSetECI::ISO8859_4),
|
6 => Ok(CharacterSet::ISO8859_4),
|
||||||
7 => Ok(CharacterSetECI::ISO8859_5),
|
7 => Ok(CharacterSet::ISO8859_5),
|
||||||
// 8 => Ok(CharacterSetECI::ISO8859_6),
|
// 8 => Ok(CharacterSetECI::ISO8859_6),
|
||||||
9 => Ok(CharacterSetECI::ISO8859_7),
|
9 => Ok(CharacterSet::ISO8859_7),
|
||||||
// 10 => Ok(CharacterSetECI::ISO8859_8),
|
// 10 => Ok(CharacterSetECI::ISO8859_8),
|
||||||
11 => Ok(CharacterSetECI::ISO8859_9),
|
11 => Ok(CharacterSet::ISO8859_9),
|
||||||
// 12 => Ok(CharacterSetECI::ISO8859_10),
|
// 12 => Ok(CharacterSetECI::ISO8859_10),
|
||||||
// 13 => Ok(CharacterSetECI::ISO8859_11),
|
// 13 => Ok(CharacterSetECI::ISO8859_11),
|
||||||
15 => Ok(CharacterSetECI::ISO8859_13),
|
15 => Ok(CharacterSet::ISO8859_13),
|
||||||
// 16 => Ok(CharacterSetECI::ISO8859_14),
|
// 16 => Ok(CharacterSetECI::ISO8859_14),
|
||||||
17 => Ok(CharacterSetECI::ISO8859_15),
|
17 => Ok(CharacterSet::ISO8859_15),
|
||||||
18 => Ok(CharacterSetECI::ISO8859_16),
|
18 => Ok(CharacterSet::ISO8859_16),
|
||||||
20 => Ok(CharacterSetECI::SJIS),
|
20 => Ok(CharacterSet::SJIS),
|
||||||
21 => Ok(CharacterSetECI::Cp1250),
|
21 => Ok(CharacterSet::Cp1250),
|
||||||
22 => Ok(CharacterSetECI::Cp1251),
|
22 => Ok(CharacterSet::Cp1251),
|
||||||
23 => Ok(CharacterSetECI::Cp1252),
|
23 => Ok(CharacterSet::Cp1252),
|
||||||
24 => Ok(CharacterSetECI::Cp1256),
|
24 => Ok(CharacterSet::Cp1256),
|
||||||
25 => Ok(CharacterSetECI::UnicodeBigUnmarked),
|
25 => Ok(CharacterSet::UnicodeBigUnmarked),
|
||||||
26 => Ok(CharacterSetECI::UTF8),
|
26 => Ok(CharacterSet::UTF8),
|
||||||
27 | 170 => Ok(CharacterSetECI::ASCII),
|
27 | 170 => Ok(CharacterSet::ASCII),
|
||||||
28 => Ok(CharacterSetECI::Big5),
|
28 => Ok(CharacterSet::Big5),
|
||||||
29 => Ok(CharacterSetECI::GB18030),
|
29 => Ok(CharacterSet::GB18030),
|
||||||
30 => Ok(CharacterSetECI::EUC_KR),
|
30 => Ok(CharacterSet::EUC_KR),
|
||||||
_ => Err(Exceptions::not_found_with("Bad ECI Value")),
|
_ => Err(Exceptions::not_found_with("Bad ECI Value")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -282,66 +247,66 @@ impl CharacterSetECI {
|
|||||||
* @return CharacterSetECI representing ECI for character encoding, or null if it is legal
|
* @return CharacterSetECI representing ECI for character encoding, or null if it is legal
|
||||||
* but unsupported
|
* but unsupported
|
||||||
*/
|
*/
|
||||||
pub fn getCharacterSetECIByName(name: &str) -> Option<CharacterSetECI> {
|
pub fn get_character_set_by_name(name: &str) -> Option<CharacterSet> {
|
||||||
match name.to_lowercase().as_str() {
|
match name.to_lowercase().as_str() {
|
||||||
"cp437" => Some(CharacterSetECI::Cp437),
|
"cp437" => Some(CharacterSet::Cp437),
|
||||||
"iso-8859-1" => Some(CharacterSetECI::ISO8859_1),
|
"iso-8859-1" => Some(CharacterSet::ISO8859_1),
|
||||||
"iso-8859-2" => Some(CharacterSetECI::ISO8859_2),
|
"iso-8859-2" => Some(CharacterSet::ISO8859_2),
|
||||||
"iso-8859-3" => Some(CharacterSetECI::ISO8859_3),
|
"iso-8859-3" => Some(CharacterSet::ISO8859_3),
|
||||||
"iso-8859-4" => Some(CharacterSetECI::ISO8859_4),
|
"iso-8859-4" => Some(CharacterSet::ISO8859_4),
|
||||||
"iso-8859-5" => Some(CharacterSetECI::ISO8859_5),
|
"iso-8859-5" => Some(CharacterSet::ISO8859_5),
|
||||||
// "ISO-8859-6" => Some(CharacterSetECI::ISO8859_6),
|
// "ISO-8859-6" => Some(CharacterSetECI::ISO8859_6),
|
||||||
"iso-8859-7" => Some(CharacterSetECI::ISO8859_7),
|
"iso-8859-7" => Some(CharacterSet::ISO8859_7),
|
||||||
// "ISO-8859-8" => Some(CharacterSetECI::ISO8859_8),
|
// "ISO-8859-8" => Some(CharacterSetECI::ISO8859_8),
|
||||||
"iso-8859-9" => Some(CharacterSetECI::ISO8859_9),
|
"iso-8859-9" => Some(CharacterSet::ISO8859_9),
|
||||||
// "ISO-8859-10" => Some(CharacterSetECI::ISO8859_10),
|
// "ISO-8859-10" => Some(CharacterSetECI::ISO8859_10),
|
||||||
// "ISO-8859-11" => Some(CharacterSetECI::ISO8859_11),
|
// "ISO-8859-11" => Some(CharacterSetECI::ISO8859_11),
|
||||||
"iso-8859-13" => Some(CharacterSetECI::ISO8859_13),
|
"iso-8859-13" => Some(CharacterSet::ISO8859_13),
|
||||||
// "ISO-8859-14" => Some(CharacterSetECI::ISO8859_14),
|
// "ISO-8859-14" => Some(CharacterSetECI::ISO8859_14),
|
||||||
"iso-8859-15" => Some(CharacterSetECI::ISO8859_15),
|
"iso-8859-15" => Some(CharacterSet::ISO8859_15),
|
||||||
"iso-8859-16" => Some(CharacterSetECI::ISO8859_16),
|
"iso-8859-16" => Some(CharacterSet::ISO8859_16),
|
||||||
"shift_jis" => Some(CharacterSetECI::SJIS),
|
"shift_jis" => Some(CharacterSet::SJIS),
|
||||||
"windows-1250" => Some(CharacterSetECI::Cp1250),
|
"windows-1250" => Some(CharacterSet::Cp1250),
|
||||||
"windows-1251" => Some(CharacterSetECI::Cp1251),
|
"windows-1251" => Some(CharacterSet::Cp1251),
|
||||||
"windows-1252" => Some(CharacterSetECI::Cp1252),
|
"windows-1252" => Some(CharacterSet::Cp1252),
|
||||||
"windows-1256" => Some(CharacterSetECI::Cp1256),
|
"windows-1256" => Some(CharacterSet::Cp1256),
|
||||||
"utf-16be" => Some(CharacterSetECI::UnicodeBigUnmarked),
|
"utf-16be" => Some(CharacterSet::UnicodeBigUnmarked),
|
||||||
"utf-8" | "utf8" => Some(CharacterSetECI::UTF8),
|
"utf-8" | "utf8" => Some(CharacterSet::UTF8),
|
||||||
"us-ascii" => Some(CharacterSetECI::ASCII),
|
"us-ascii" => Some(CharacterSet::ASCII),
|
||||||
"big5" => Some(CharacterSetECI::Big5),
|
"big5" => Some(CharacterSet::Big5),
|
||||||
"gb2312" => Some(CharacterSetECI::GB18030),
|
"gb2312" => Some(CharacterSet::GB18030),
|
||||||
"euc-kr" => Some(CharacterSetECI::EUC_KR),
|
"euc-kr" => Some(CharacterSet::EUC_KR),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode(&self, input: &str) -> Result<Vec<u8>> {
|
pub fn encode(&self, input: &str) -> Result<Vec<u8>> {
|
||||||
self.getCharset()
|
self.get_base_encoder()
|
||||||
.encode(input, encoding::EncoderTrap::Strict)
|
.encode(input, encoding::EncoderTrap::Strict)
|
||||||
.map_err(|e| Exceptions::format_with(e.to_string()))
|
.map_err(|e| Exceptions::format_with(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_replace(&self, input: &str) -> Result<Vec<u8>> {
|
pub fn encode_replace(&self, input: &str) -> Result<Vec<u8>> {
|
||||||
self.getCharset()
|
self.get_base_encoder()
|
||||||
.encode(input, encoding::EncoderTrap::Replace)
|
.encode(input, encoding::EncoderTrap::Replace)
|
||||||
.map_err(|e| Exceptions::format_with(e.to_string()))
|
.map_err(|e| Exceptions::format_with(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode(&self, input: &[u8]) -> Result<String> {
|
pub fn decode(&self, input: &[u8]) -> Result<String> {
|
||||||
if self == &CharacterSetECI::Cp437 {
|
if self == &CharacterSet::Cp437 {
|
||||||
use codepage_437::BorrowFromCp437;
|
use codepage_437::BorrowFromCp437;
|
||||||
use codepage_437::CP437_CONTROL;
|
use codepage_437::CP437_CONTROL;
|
||||||
|
|
||||||
Ok(String::borrow_from_cp437(&input, &CP437_CONTROL))
|
Ok(String::borrow_from_cp437(&input, &CP437_CONTROL))
|
||||||
} else {
|
} else {
|
||||||
self.getCharset()
|
self.get_base_encoder()
|
||||||
.decode(input, encoding::DecoderTrap::Strict)
|
.decode(input, encoding::DecoderTrap::Strict)
|
||||||
.map_err(|e| Exceptions::format_with(e.to_string()))
|
.map_err(|e| Exceptions::format_with(e.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode_replace(&self, input: &[u8]) -> Result<String> {
|
pub fn decode_replace(&self, input: &[u8]) -> Result<String> {
|
||||||
self.getCharset()
|
self.get_base_encoder()
|
||||||
.decode(input, encoding::DecoderTrap::Replace)
|
.decode(input, encoding::DecoderTrap::Replace)
|
||||||
.map_err(|e| Exceptions::format_with(e.to_string()))
|
.map_err(|e| Exceptions::format_with(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
use super::CharacterSetECI;
|
use super::CharacterSet;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
static ENCODERS: Lazy<Vec<CharacterSetECI>> = Lazy::new(|| {
|
static ENCODERS: Lazy<Vec<CharacterSet>> = Lazy::new(|| {
|
||||||
let mut enc_vec = Vec::new();
|
let mut enc_vec = Vec::new();
|
||||||
for name in NAMES {
|
for name in NAMES {
|
||||||
if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(name) {
|
if let Some(enc) = CharacterSet::get_character_set_by_name(name) {
|
||||||
enc_vec.push(enc);
|
enc_vec.push(enc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ const NAMES: [&str; 20] = [
|
|||||||
*/
|
*/
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ECIEncoderSet {
|
pub struct ECIEncoderSet {
|
||||||
encoders: Vec<CharacterSetECI>,
|
encoders: Vec<CharacterSet>,
|
||||||
priorityEncoderIndex: Option<usize>,
|
priorityEncoderIndex: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,23 +84,23 @@ impl ECIEncoderSet {
|
|||||||
*/
|
*/
|
||||||
pub fn new(
|
pub fn new(
|
||||||
stringToEncodeMain: &str,
|
stringToEncodeMain: &str,
|
||||||
priorityCharset: Option<CharacterSetECI>,
|
priorityCharset: Option<CharacterSet>,
|
||||||
fnc1: Option<&str>,
|
fnc1: Option<&str>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// List of encoders that potentially encode characters not in ISO-8859-1 in one byte.
|
// List of encoders that potentially encode characters not in ISO-8859-1 in one byte.
|
||||||
|
|
||||||
let mut encoders: Vec<CharacterSetECI>;
|
let mut encoders: Vec<CharacterSet>;
|
||||||
let mut priorityEncoderIndexValue = None;
|
let mut priorityEncoderIndexValue = None;
|
||||||
|
|
||||||
let mut neededEncoders: Vec<CharacterSetECI> = Vec::new();
|
let mut neededEncoders: Vec<CharacterSet> = Vec::new();
|
||||||
|
|
||||||
let stringToEncode = stringToEncodeMain.graphemes(true).collect::<Vec<&str>>();
|
let stringToEncode = stringToEncodeMain.graphemes(true).collect::<Vec<&str>>();
|
||||||
|
|
||||||
//we always need the ISO-8859-1 encoder. It is the default encoding
|
//we always need the ISO-8859-1 encoder. It is the default encoding
|
||||||
neededEncoders.push(CharacterSetECI::ISO8859_1);
|
neededEncoders.push(CharacterSet::ISO8859_1);
|
||||||
let mut needUnicodeEncoder = if let Some(pc) = priorityCharset {
|
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
|
pc == CharacterSet::UTF8 || pc == CharacterSet::UnicodeBigUnmarked
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
@@ -142,7 +142,7 @@ impl ECIEncoderSet {
|
|||||||
|
|
||||||
if neededEncoders.len() == 1 && !needUnicodeEncoder {
|
if neededEncoders.len() == 1 && !needUnicodeEncoder {
|
||||||
//the entire input can be encoded by the ISO-8859-1 encoder
|
//the entire input can be encoded by the ISO-8859-1 encoder
|
||||||
encoders = vec![CharacterSetECI::ISO8859_1];
|
encoders = vec![CharacterSet::ISO8859_1];
|
||||||
} else {
|
} else {
|
||||||
// we need more than one single byte encoder or we need a Unicode encoder.
|
// 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
|
// In this case we append a UTF-8 and UTF-16 encoder to the list
|
||||||
@@ -156,8 +156,8 @@ impl ECIEncoderSet {
|
|||||||
encoders.push(encoder);
|
encoders.push(encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
encoders.push(CharacterSetECI::UTF8);
|
encoders.push(CharacterSet::UTF8);
|
||||||
encoders.push(CharacterSetECI::UnicodeBigUnmarked);
|
encoders.push(CharacterSet::UnicodeBigUnmarked);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Compute priorityEncoderIndex by looking up priorityCharset in encoders
|
//Compute priorityEncoderIndex by looking up priorityCharset in encoders
|
||||||
@@ -175,7 +175,7 @@ impl ECIEncoderSet {
|
|||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
//invariants
|
//invariants
|
||||||
assert_eq!(encoders[0], CharacterSetECI::ISO8859_1);
|
assert_eq!(encoders[0], CharacterSet::ISO8859_1);
|
||||||
Self {
|
Self {
|
||||||
encoders,
|
encoders,
|
||||||
priorityEncoderIndex: priorityEncoderIndexValue,
|
priorityEncoderIndex: priorityEncoderIndexValue,
|
||||||
@@ -192,13 +192,13 @@ impl ECIEncoderSet {
|
|||||||
|
|
||||||
pub fn getCharsetName(&self, index: usize) -> Option<&'static str> {
|
pub fn getCharsetName(&self, index: usize) -> Option<&'static str> {
|
||||||
if index < self.len() {
|
if index < self.len() {
|
||||||
Some(self.encoders[index].getCharsetName())
|
Some(self.encoders[index].get_charset_name())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getCharset(&self, index: usize) -> Option<CharacterSetECI> {
|
pub fn getCharset(&self, index: usize) -> Option<CharacterSet> {
|
||||||
if index < self.len() {
|
if index < self.len() {
|
||||||
Some(self.encoders[index])
|
Some(self.encoders[index])
|
||||||
} else {
|
} else {
|
||||||
@@ -207,7 +207,7 @@ impl ECIEncoderSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getECIValue(&self, encoderIndex: usize) -> u32 {
|
pub fn getECIValue(&self, encoderIndex: usize) -> u32 {
|
||||||
self.encoders[encoderIndex].getValue()
|
self.encoders[encoderIndex].get_eci_value()
|
||||||
// CharacterSetECI::getValue(
|
// CharacterSetECI::getValue(
|
||||||
// &CharacterSetECI::getCharacterSetECI(self.encoders[encoderIndex]).unwrap(),
|
// &CharacterSetECI::getCharacterSetECI(self.encoders[encoderIndex]).unwrap(),
|
||||||
// )
|
// )
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use crate::common::Result;
|
use crate::common::Result;
|
||||||
|
|
||||||
use super::CharacterSetECI;
|
use super::CharacterSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that converts a sequence of ECIs and bytes into a string
|
* Class that converts a sequence of ECIs and bytes into a string
|
||||||
@@ -35,7 +35,7 @@ use super::CharacterSetECI;
|
|||||||
pub struct ECIStringBuilder {
|
pub struct ECIStringBuilder {
|
||||||
current_bytes: Vec<u8>,
|
current_bytes: Vec<u8>,
|
||||||
result: String,
|
result: String,
|
||||||
current_charset: Option<CharacterSetECI>, //= StandardCharsets.ISO_8859_1;
|
current_charset: Option<CharacterSet>, //= StandardCharsets.ISO_8859_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ECIStringBuilder {
|
impl ECIStringBuilder {
|
||||||
@@ -43,14 +43,14 @@ impl ECIStringBuilder {
|
|||||||
Self {
|
Self {
|
||||||
current_bytes: Vec::new(),
|
current_bytes: Vec::new(),
|
||||||
result: String::new(),
|
result: String::new(),
|
||||||
current_charset: Some(CharacterSetECI::ISO8859_1),
|
current_charset: Some(CharacterSet::ISO8859_1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn with_capacity(initial_capacity: usize) -> Self {
|
pub fn with_capacity(initial_capacity: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
current_bytes: Vec::with_capacity(initial_capacity),
|
current_bytes: Vec::with_capacity(initial_capacity),
|
||||||
result: String::with_capacity(initial_capacity),
|
result: String::with_capacity(initial_capacity),
|
||||||
current_charset: Some(CharacterSetECI::ISO8859_1),
|
current_charset: Some(CharacterSet::ISO8859_1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,8 @@ impl ECIStringBuilder {
|
|||||||
pub fn appendECI(&mut self, value: u32) -> Result<()> {
|
pub fn appendECI(&mut self, value: u32) -> Result<()> {
|
||||||
self.encodeCurrentBytesIfAny();
|
self.encodeCurrentBytesIfAny();
|
||||||
|
|
||||||
self.current_charset = CharacterSetECI::getCharacterSetECIByValue(value).ok();
|
self.current_charset = CharacterSet::get_character_set_by_eci(value).ok();
|
||||||
|
|
||||||
|
|
||||||
// if let Ok(character_set_eci) = CharacterSetECI::getCharacterSetECIByValue(value) {
|
// if let Ok(character_set_eci) = CharacterSetECI::getCharacterSetECIByValue(value) {
|
||||||
// // dbg!(
|
// // dbg!(
|
||||||
@@ -126,7 +127,7 @@ impl ECIStringBuilder {
|
|||||||
/// This function can panic
|
/// This function can panic
|
||||||
pub fn encodeCurrentBytesIfAny(&mut self) {
|
pub fn encodeCurrentBytesIfAny(&mut self) {
|
||||||
if let Some(encoder) = self.current_charset {
|
if let Some(encoder) = self.current_charset {
|
||||||
if encoder == CharacterSetECI::UTF8 {
|
if encoder == CharacterSet::UTF8 {
|
||||||
if !self.current_bytes.is_empty() {
|
if !self.current_bytes.is_empty() {
|
||||||
self.result.push_str(
|
self.result.push_str(
|
||||||
&String::from_utf8(std::mem::take(&mut self.current_bytes)).unwrap(),
|
&String::from_utf8(std::mem::take(&mut self.current_bytes)).unwrap(),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
|||||||
use crate::common::Result;
|
use crate::common::Result;
|
||||||
use crate::Exceptions;
|
use crate::Exceptions;
|
||||||
|
|
||||||
use super::{CharacterSetECI, ECIEncoderSet, ECIInput};
|
use super::{CharacterSet, ECIEncoderSet, ECIInput};
|
||||||
|
|
||||||
//* approximated (latch + 2 codewords)
|
//* approximated (latch + 2 codewords)
|
||||||
pub const COST_PER_ECI: usize = 3;
|
pub const COST_PER_ECI: usize = 3;
|
||||||
@@ -193,7 +193,7 @@ impl MinimalECIInput {
|
|||||||
*/
|
*/
|
||||||
pub fn new(
|
pub fn new(
|
||||||
stringToEncodeInput: &str,
|
stringToEncodeInput: &str,
|
||||||
priorityCharset: Option<CharacterSetECI>,
|
priorityCharset: Option<CharacterSet>,
|
||||||
fnc1: Option<&str>,
|
fnc1: Option<&str>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let stringToEncode = stringToEncodeInput.graphemes(true).collect::<Vec<&str>>();
|
let stringToEncode = stringToEncodeInput.graphemes(true).collect::<Vec<&str>>();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
use crate::{DecodeHintType, DecodeHintValue, DecodingHintDictionary};
|
use crate::{DecodeHintType, DecodeHintValue, DecodingHintDictionary};
|
||||||
|
|
||||||
use super::CharacterSetECI;
|
use super::CharacterSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common string-related functions.
|
* Common string-related functions.
|
||||||
@@ -48,7 +48,7 @@ const ASSUME_SHIFT_JIS: bool = false;
|
|||||||
// static SHIFT_JIS: &'static str = "SJIS";
|
// static SHIFT_JIS: &'static str = "SJIS";
|
||||||
// static GB2312: &'static str = "GB2312";
|
// static GB2312: &'static str = "GB2312";
|
||||||
|
|
||||||
pub static SHIFT_JIS_CHARSET: CharacterSetECI = CharacterSetECI::SJIS;
|
pub static SHIFT_JIS_CHARSET: CharacterSet = CharacterSet::SJIS;
|
||||||
|
|
||||||
// private static final boolean ASSUME_SHIFT_JIS =
|
// private static final boolean ASSUME_SHIFT_JIS =
|
||||||
// SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) ||
|
// SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) ||
|
||||||
@@ -64,14 +64,14 @@ impl StringUtils {
|
|||||||
*/
|
*/
|
||||||
pub fn guessEncoding(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<&'static str> {
|
pub fn guessEncoding(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<&'static str> {
|
||||||
let c = StringUtils::guessCharset(bytes, hints)?;
|
let c = StringUtils::guessCharset(bytes, hints)?;
|
||||||
if c == CharacterSetECI::SJIS {
|
if c == CharacterSet::SJIS {
|
||||||
Some("SJIS")
|
Some("SJIS")
|
||||||
} else if c == CharacterSetECI::UTF8 {
|
} else if c == CharacterSet::UTF8 {
|
||||||
Some("UTF8")
|
Some("UTF8")
|
||||||
} else if c == CharacterSetECI::ISO8859_1 {
|
} else if c == CharacterSet::ISO8859_1 {
|
||||||
Some("ISO8859_1")
|
Some("ISO8859_1")
|
||||||
} else {
|
} else {
|
||||||
Some(c.getCharsetName())
|
Some(c.get_charset_name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,12 +84,12 @@ impl StringUtils {
|
|||||||
* or the platform default encoding if
|
* or the platform default encoding if
|
||||||
* none of these can possibly be correct
|
* none of these can possibly be correct
|
||||||
*/
|
*/
|
||||||
pub fn guessCharset(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<CharacterSetECI> {
|
pub fn guessCharset(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<CharacterSet> {
|
||||||
if let Some(DecodeHintValue::CharacterSet(cs_name)) =
|
if let Some(DecodeHintValue::CharacterSet(cs_name)) =
|
||||||
hints.get(&DecodeHintType::CHARACTER_SET)
|
hints.get(&DecodeHintType::CHARACTER_SET)
|
||||||
{
|
{
|
||||||
// if let DecodeHintValue::CharacterSet(cs_name) = hint {
|
// if let DecodeHintValue::CharacterSet(cs_name) = hint {
|
||||||
return CharacterSetECI::getCharacterSetECIByName(cs_name);
|
return CharacterSet::get_character_set_by_name(cs_name);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
// if hints.contains_key(&DecodeHintType::CHARACTER_SET) {
|
// if hints.contains_key(&DecodeHintType::CHARACTER_SET) {
|
||||||
@@ -101,9 +101,9 @@ impl StringUtils {
|
|||||||
&& ((bytes[0] == 0xFE && bytes[1] == 0xFF) || (bytes[0] == 0xFF && bytes[1] == 0xFE))
|
&& ((bytes[0] == 0xFE && bytes[1] == 0xFF) || (bytes[0] == 0xFF && bytes[1] == 0xFE))
|
||||||
{
|
{
|
||||||
if bytes[0] == 0xFE && bytes[1] == 0xFF {
|
if bytes[0] == 0xFE && bytes[1] == 0xFF {
|
||||||
return Some(CharacterSetECI::UnicodeBigUnmarked);
|
return Some(CharacterSet::UnicodeBigUnmarked);
|
||||||
} else {
|
} else {
|
||||||
return Some(CharacterSetECI::UTF16LE);
|
return Some(CharacterSet::UTF16LE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,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
|
// 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) {
|
if can_be_utf8 && (utf8bom || utf2_bytes_chars + utf3_bytes_chars + utf4_bytes_chars > 0) {
|
||||||
return Some(CharacterSetECI::UTF8);
|
return Some(CharacterSet::UTF8);
|
||||||
}
|
}
|
||||||
// Easy -- if assuming Shift_JIS or >= 3 valid consecutive not-ascii characters (and no evidence it can't be), done
|
// 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
|
if can_be_shift_jis
|
||||||
@@ -229,7 +229,7 @@ impl StringUtils {
|
|||||||
|| sjis_max_katakana_word_length >= 3
|
|| sjis_max_katakana_word_length >= 3
|
||||||
|| sjis_max_double_bytes_word_length >= 3)
|
|| sjis_max_double_bytes_word_length >= 3)
|
||||||
{
|
{
|
||||||
return Some(CharacterSetECI::SJIS); //encoding::label::encoding_from_whatwg_label("SJIS");
|
return Some(CharacterSet::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:
|
// Distinguishing Shift_JIS and ISO-8859-1 can be a little tough for short words. The crude heuristic is:
|
||||||
// - If we saw
|
// - If we saw
|
||||||
@@ -240,23 +240,23 @@ impl StringUtils {
|
|||||||
return if (sjis_max_katakana_word_length == 2 && sjis_katakana_chars == 2)
|
return if (sjis_max_katakana_word_length == 2 && sjis_katakana_chars == 2)
|
||||||
|| iso_high_other * 10 >= length
|
|| iso_high_other * 10 >= length
|
||||||
{
|
{
|
||||||
Some(CharacterSetECI::SJIS)
|
Some(CharacterSet::SJIS)
|
||||||
} else {
|
} else {
|
||||||
Some(CharacterSetECI::ISO8859_1)
|
Some(CharacterSet::ISO8859_1)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, try in order ISO-8859-1, Shift JIS, UTF-8 and fall back to default platform encoding
|
// Otherwise, try in order ISO-8859-1, Shift JIS, UTF-8 and fall back to default platform encoding
|
||||||
if can_be_iso88591 {
|
if can_be_iso88591 {
|
||||||
return Some(CharacterSetECI::ISO8859_1);
|
return Some(CharacterSet::ISO8859_1);
|
||||||
}
|
}
|
||||||
if can_be_shift_jis {
|
if can_be_shift_jis {
|
||||||
return Some(CharacterSetECI::SJIS);
|
return Some(CharacterSet::SJIS);
|
||||||
}
|
}
|
||||||
if can_be_utf8 {
|
if can_be_utf8 {
|
||||||
return Some(CharacterSetECI::UTF8);
|
return Some(CharacterSet::UTF8);
|
||||||
}
|
}
|
||||||
// Otherwise, we take a wild guess with platform encoding
|
// Otherwise, we take a wild guess with platform encoding
|
||||||
Some(CharacterSetECI::UTF8)
|
Some(CharacterSet::UTF8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitMatrix, CharacterSetECI, Result},
|
common::{BitMatrix, CharacterSet, Result},
|
||||||
qrcode::encoder::ByteMatrix,
|
qrcode::encoder::ByteMatrix,
|
||||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
||||||
};
|
};
|
||||||
@@ -115,14 +115,14 @@ impl Writer for DataMatrixWriter {
|
|||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut charset: Option<CharacterSetECI> = None;
|
let mut charset: Option<CharacterSet> = None;
|
||||||
let hasEncodingHint = hints.contains_key(&EncodeHintType::CHARACTER_SET);
|
let hasEncodingHint = hints.contains_key(&EncodeHintType::CHARACTER_SET);
|
||||||
if hasEncodingHint {
|
if hasEncodingHint {
|
||||||
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
|
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
|
||||||
hints.get(&EncodeHintType::CHARACTER_SET) else {
|
hints.get(&EncodeHintType::CHARACTER_SET) else {
|
||||||
return Err(Exceptions::illegal_argument_with("charset does not exist"))
|
return Err(Exceptions::illegal_argument_with("charset does not exist"))
|
||||||
};
|
};
|
||||||
charset = CharacterSetECI::getCharacterSetECIByName(char_set_name);
|
charset = CharacterSet::get_character_set_by_name(char_set_name);
|
||||||
//encoding::label::encoding_from_whatwg_label(char_set_name);
|
//encoding::label::encoding_from_whatwg_label(char_set_name);
|
||||||
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
|
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitSource, CharacterSetECI, DecoderRXingResult, ECIStringBuilder, Result},
|
common::{BitSource, CharacterSet, DecoderRXingResult, ECIStringBuilder, Result},
|
||||||
Exceptions,
|
Exceptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -727,7 +727,7 @@ fn decodeBase256Segment(
|
|||||||
*byte = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8;
|
*byte = unrandomize255State(bits.readBits(8)?, codewordPosition) as u8;
|
||||||
codewordPosition += 1;
|
codewordPosition += 1;
|
||||||
}
|
}
|
||||||
result.append_string(&CharacterSetECI::ISO8859_1.decode(&bytes)?);
|
result.append_string(&CharacterSet::ISO8859_1.decode(&bytes)?);
|
||||||
byteSegments.push(bytes);
|
byteSegments.push(bytes);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::common::{CharacterSetECI, Result};
|
use crate::common::{CharacterSet, Result};
|
||||||
use crate::{Dimension, Exceptions};
|
use crate::{Dimension, Exceptions};
|
||||||
|
|
||||||
use super::{SymbolInfo, SymbolInfoLookup, SymbolShapeHint};
|
use super::{SymbolInfo, SymbolInfoLookup, SymbolShapeHint};
|
||||||
|
|
||||||
const ISO_8859_1_ENCODER: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
const ISO_8859_1_ENCODER: CharacterSet = CharacterSet::ISO8859_1;
|
||||||
|
|
||||||
pub struct EncoderContext<'a> {
|
pub struct EncoderContext<'a> {
|
||||||
symbol_lookup: Rc<SymbolInfoLookup<'a>>,
|
symbol_lookup: Rc<SymbolInfoLookup<'a>>,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use std::rc::Rc;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::CharacterSetECI,
|
common::CharacterSet,
|
||||||
datamatrix::encoder::{SymbolInfo, SymbolShapeHint},
|
datamatrix::encoder::{SymbolInfo, SymbolShapeHint},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -537,7 +537,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",
|
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);
|
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(CharacterSetECI::UTF8), 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(CharacterSet::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",
|
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);
|
visualized);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::common::{CharacterSetECI, Result};
|
use crate::common::{CharacterSet, Result};
|
||||||
use crate::{Dimension, Exceptions};
|
use crate::{Dimension, Exceptions};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@@ -24,7 +24,7 @@ use super::{
|
|||||||
SymbolInfoLookup, SymbolShapeHint, TextEncoder, X12Encoder,
|
SymbolInfoLookup, SymbolShapeHint, TextEncoder, X12Encoder,
|
||||||
};
|
};
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
const DEFAULT_ENCODING: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
const DEFAULT_ENCODING: CharacterSet = CharacterSet::ISO8859_1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DataMatrix ECC 200 data encoder following the algorithm described in ISO/IEC 16022:200(E) in
|
* DataMatrix ECC 200 data encoder following the algorithm described in ISO/IEC 16022:200(E) in
|
||||||
|
|||||||
@@ -17,13 +17,13 @@
|
|||||||
use std::{fmt, rc::Rc};
|
use std::{fmt, rc::Rc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{CharacterSetECI, ECIInput, MinimalECIInput, Result},
|
common::{CharacterSet, ECIInput, MinimalECIInput, Result},
|
||||||
Exceptions,
|
Exceptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{high_level_encoder, SymbolShapeHint};
|
use super::{high_level_encoder, SymbolShapeHint};
|
||||||
|
|
||||||
const ISO_8859_1_ENCODER: CharacterSetECI = CharacterSetECI::ISO8859_1;
|
const ISO_8859_1_ENCODER: CharacterSet = CharacterSet::ISO8859_1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encoder that encodes minimally
|
* Encoder that encodes minimally
|
||||||
@@ -151,7 +151,7 @@ pub fn encodeHighLevel(msg: &str) -> Result<String> {
|
|||||||
*/
|
*/
|
||||||
pub fn encodeHighLevelWithDetails(
|
pub fn encodeHighLevelWithDetails(
|
||||||
msg: &str,
|
msg: &str,
|
||||||
priorityCharset: Option<CharacterSetECI>,
|
priorityCharset: Option<CharacterSet>,
|
||||||
fnc1: Option<char>,
|
fnc1: Option<char>,
|
||||||
shape: SymbolShapeHint,
|
shape: SymbolShapeHint,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
@@ -192,7 +192,7 @@ pub fn encodeHighLevelWithDetails(
|
|||||||
*/
|
*/
|
||||||
fn encode(
|
fn encode(
|
||||||
input: &str,
|
input: &str,
|
||||||
priorityCharset: Option<CharacterSetECI>,
|
priorityCharset: Option<CharacterSet>,
|
||||||
fnc1: Option<char>,
|
fnc1: Option<char>,
|
||||||
shape: SymbolShapeHint,
|
shape: SymbolShapeHint,
|
||||||
macroId: i32,
|
macroId: i32,
|
||||||
@@ -1393,7 +1393,7 @@ struct Input {
|
|||||||
impl Input {
|
impl Input {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
stringToEncode: &str,
|
stringToEncode: &str,
|
||||||
priorityCharset: Option<CharacterSetECI>,
|
priorityCharset: Option<CharacterSet>,
|
||||||
fnc1: Option<char>,
|
fnc1: Option<char>,
|
||||||
shape: SymbolShapeHint,
|
shape: SymbolShapeHint,
|
||||||
macroId: i32,
|
macroId: i32,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
use java_rand;
|
use java_rand;
|
||||||
|
|
||||||
use crate::common::CharacterSetECI;
|
use crate::common::CharacterSet;
|
||||||
use crate::pdf417::decoder::decoded_bit_stream_parser;
|
use crate::pdf417::decoder::decoded_bit_stream_parser;
|
||||||
use crate::pdf417::encoder::{pdf_417_high_level_encoder_test_adapter, Compaction};
|
use crate::pdf417::encoder::{pdf_417_high_level_encoder_test_adapter, Compaction};
|
||||||
use crate::pdf417::PDF417RXingResultMetadata;
|
use crate::pdf417::PDF417RXingResultMetadata;
|
||||||
@@ -307,7 +307,7 @@ fn testBinaryData() {
|
|||||||
random.next_bytes(&mut bytes);
|
random.next_bytes(&mut bytes);
|
||||||
|
|
||||||
total += encodeDecode(
|
total += encodeDecode(
|
||||||
&CharacterSetECI::ISO8859_1
|
&CharacterSet::ISO8859_1
|
||||||
.decode(&bytes)
|
.decode(&bytes)
|
||||||
.expect("decode bytes"),
|
.expect("decode bytes"),
|
||||||
);
|
);
|
||||||
@@ -437,7 +437,7 @@ fn encodeDecode(input: &str) -> u32 {
|
|||||||
|
|
||||||
fn encodeDecodeWithAll(
|
fn encodeDecodeWithAll(
|
||||||
input: &str,
|
input: &str,
|
||||||
charset: Option<CharacterSetECI>,
|
charset: Option<CharacterSet>,
|
||||||
autoECI: bool,
|
autoECI: bool,
|
||||||
decode: bool,
|
decode: bool,
|
||||||
) -> u32 {
|
) -> u32 {
|
||||||
@@ -523,7 +523,7 @@ fn performECITest(
|
|||||||
// for (int i = 0; i < 1000; i++) {
|
// for (int i = 0; i < 1000; i++) {
|
||||||
let s = generateText(&mut random, 100, chars, weights);
|
let s = generateText(&mut random, 100, chars, weights);
|
||||||
minLength += encodeDecodeWithAll(&s, None, true, true);
|
minLength += encodeDecodeWithAll(&s, None, true, true);
|
||||||
utfLength += encodeDecodeWithAll(&s, Some(CharacterSetECI::UTF8), false, true);
|
utfLength += encodeDecodeWithAll(&s, Some(CharacterSet::UTF8), false, true);
|
||||||
}
|
}
|
||||||
assert_eq!(expectedMinLength, minLength);
|
assert_eq!(expectedMinLength, minLength);
|
||||||
assert_eq!(expectedUTFLength, utfLength);
|
assert_eq!(expectedUTFLength, utfLength);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
* This file has been modified from its original form in Barcode4J.
|
* This file has been modified from its original form in Barcode4J.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::common::{CharacterSetECI, Result};
|
use crate::common::{CharacterSet, Result};
|
||||||
use crate::Exceptions;
|
use crate::Exceptions;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@@ -32,7 +32,7 @@ pub struct PDF417 {
|
|||||||
barcodeMatrix: Option<BarcodeMatrix>,
|
barcodeMatrix: Option<BarcodeMatrix>,
|
||||||
compact: bool,
|
compact: bool,
|
||||||
compaction: Compaction,
|
compaction: Compaction,
|
||||||
encoding: Option<CharacterSetECI>,
|
encoding: Option<CharacterSet>,
|
||||||
minCols: u32,
|
minCols: u32,
|
||||||
maxCols: u32,
|
maxCols: u32,
|
||||||
maxRows: u32,
|
maxRows: u32,
|
||||||
@@ -345,7 +345,7 @@ impl PDF417 {
|
|||||||
/**
|
/**
|
||||||
* @param encoding sets character encoding to use
|
* @param encoding sets character encoding to use
|
||||||
*/
|
*/
|
||||||
pub fn setEncoding(&mut self, encoding: Option<CharacterSetECI>) {
|
pub fn setEncoding(&mut self, encoding: Option<CharacterSet>) {
|
||||||
self.encoding = encoding;
|
self.encoding = encoding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
use std::{any::TypeId, fmt::Display, str::FromStr};
|
use std::{any::TypeId, fmt::Display, str::FromStr};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{CharacterSetECI, ECIInput, MinimalECIInput, Result},
|
common::{CharacterSet, ECIInput, MinimalECIInput, Result},
|
||||||
Exceptions,
|
Exceptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ const TEXT_PUNCTUATION_RAW: [u8; 30] = [
|
|||||||
40, 41, 63, 123, 125, 39, 0,
|
40, 41, 63, 123, 125, 39, 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
const DEFAULT_ENCODING: CharacterSetECI = CharacterSetECI::ISO8859_1; //StandardCharsets.ISO_8859_1;
|
const DEFAULT_ENCODING: CharacterSet = CharacterSet::ISO8859_1; //StandardCharsets.ISO_8859_1;
|
||||||
|
|
||||||
const MIXED: [i8; 128] = {
|
const MIXED: [i8; 128] = {
|
||||||
let mut mixed = [-1_i8; 128];
|
let mut mixed = [-1_i8; 128];
|
||||||
@@ -172,7 +172,7 @@ const PUNCTUATION: [i8; 128] = {
|
|||||||
pub fn encodeHighLevel(
|
pub fn encodeHighLevel(
|
||||||
msg: &str,
|
msg: &str,
|
||||||
compaction: Compaction,
|
compaction: Compaction,
|
||||||
encoding: Option<CharacterSetECI>,
|
encoding: Option<CharacterSet>,
|
||||||
autoECI: bool,
|
autoECI: bool,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
let mut encoding = encoding;
|
let mut encoding = encoding;
|
||||||
@@ -205,7 +205,7 @@ pub fn encodeHighLevel(
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
encodingECI(
|
encodingECI(
|
||||||
CharacterSetECI::getValue(&encoding.ok_or(Exceptions::ILLEGAL_STATE)?) as i32,
|
CharacterSet::get_eci_value(&encoding.ok_or(Exceptions::ILLEGAL_STATE)?) as i32,
|
||||||
&mut sb,
|
&mut sb,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
@@ -758,7 +758,7 @@ fn determineConsecutiveTextCount<T: ECIInput + ?Sized>(input: &T, startpos: u32)
|
|||||||
fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
|
fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
|
||||||
input: &T,
|
input: &T,
|
||||||
startpos: u32,
|
startpos: u32,
|
||||||
encoding: Option<CharacterSetECI>,
|
encoding: Option<CharacterSet>,
|
||||||
) -> Result<u32> {
|
) -> Result<u32> {
|
||||||
let len = input.length();
|
let len = input.length();
|
||||||
let mut idx = startpos as usize;
|
let mut idx = startpos as usize;
|
||||||
@@ -863,13 +863,13 @@ impl Display for NoECIInput {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod PDF417EncoderTestCase {
|
mod PDF417EncoderTestCase {
|
||||||
use crate::{
|
use crate::{
|
||||||
common::CharacterSetECI,
|
common::CharacterSet,
|
||||||
pdf417::encoder::{pdf_417_high_level_encoder::encodeHighLevel, Compaction},
|
pdf417::encoder::{pdf_417_high_level_encoder::encodeHighLevel, Compaction},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testEncodeAuto() {
|
fn testEncodeAuto() {
|
||||||
let encoded = encodeHighLevel("ABCD", Compaction::AUTO, Some(CharacterSetECI::UTF8), false)
|
let encoded = encodeHighLevel("ABCD", Compaction::AUTO, Some(CharacterSet::UTF8), false)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
assert_eq!("\u{039f}\u{001A}\u{0385}ABCD", encoded);
|
assert_eq!("\u{039f}\u{001A}\u{0385}ABCD", encoded);
|
||||||
}
|
}
|
||||||
@@ -880,7 +880,7 @@ mod PDF417EncoderTestCase {
|
|||||||
encodeHighLevel(
|
encodeHighLevel(
|
||||||
"1%§s ?aG$",
|
"1%§s ?aG$",
|
||||||
Compaction::AUTO,
|
Compaction::AUTO,
|
||||||
Some(CharacterSetECI::UTF8),
|
Some(CharacterSet::UTF8),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
@@ -892,7 +892,7 @@ mod PDF417EncoderTestCase {
|
|||||||
encodeHighLevel(
|
encodeHighLevel(
|
||||||
"asdfg§asd",
|
"asdfg§asd",
|
||||||
Compaction::AUTO,
|
Compaction::AUTO,
|
||||||
Some(CharacterSetECI::ISO8859_1),
|
Some(CharacterSet::ISO8859_1),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
@@ -900,7 +900,7 @@ mod PDF417EncoderTestCase {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testEncodeText() {
|
fn testEncodeText() {
|
||||||
let encoded = encodeHighLevel("ABCD", Compaction::TEXT, Some(CharacterSetECI::UTF8), false)
|
let encoded = encodeHighLevel("ABCD", Compaction::TEXT, Some(CharacterSet::UTF8), false)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
assert_eq!("Ο\u{001A}\u{0001}?", encoded);
|
assert_eq!("Ο\u{001A}\u{0001}?", encoded);
|
||||||
}
|
}
|
||||||
@@ -910,7 +910,7 @@ mod PDF417EncoderTestCase {
|
|||||||
let encoded = encodeHighLevel(
|
let encoded = encodeHighLevel(
|
||||||
"1234",
|
"1234",
|
||||||
Compaction::NUMERIC,
|
Compaction::NUMERIC,
|
||||||
Some(CharacterSetECI::UTF8),
|
Some(CharacterSet::UTF8),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
@@ -920,7 +920,7 @@ mod PDF417EncoderTestCase {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn testEncodeByte() {
|
fn testEncodeByte() {
|
||||||
let encoded = encodeHighLevel("abcd", Compaction::BYTE, Some(CharacterSetECI::UTF8), false)
|
let encoded = encodeHighLevel("abcd", Compaction::BYTE, Some(CharacterSet::UTF8), false)
|
||||||
.expect("encode");
|
.expect("encode");
|
||||||
assert_eq!("\u{039f}\u{001A}\u{0385}abcd", encoded);
|
assert_eq!("\u{039f}\u{001A}\u{0385}abcd", encoded);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::common::{CharacterSetECI, Result};
|
use crate::common::{CharacterSet, Result};
|
||||||
|
|
||||||
use super::{pdf_417_high_level_encoder, Compaction};
|
use super::{pdf_417_high_level_encoder, Compaction};
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ use super::{pdf_417_high_level_encoder, Compaction};
|
|||||||
pub fn encodeHighLevel(
|
pub fn encodeHighLevel(
|
||||||
msg: &str,
|
msg: &str,
|
||||||
compaction: Compaction,
|
compaction: Compaction,
|
||||||
encoding: Option<CharacterSetECI>,
|
encoding: Option<CharacterSet>,
|
||||||
autoECI: bool,
|
autoECI: bool,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
pdf_417_high_level_encoder::encodeHighLevel(msg, compaction, encoding, autoECI)
|
pdf_417_high_level_encoder::encodeHighLevel(msg, compaction, encoding, autoECI)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitMatrix, CharacterSetECI, Result},
|
common::{BitMatrix, CharacterSet, Result},
|
||||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ impl Writer for PDF417Writer {
|
|||||||
if let Some(EncodeHintValue::CharacterSet(cs)) =
|
if let Some(EncodeHintValue::CharacterSet(cs)) =
|
||||||
hints.get(&EncodeHintType::CHARACTER_SET)
|
hints.get(&EncodeHintType::CHARACTER_SET)
|
||||||
{
|
{
|
||||||
encoder.setEncoding(CharacterSetECI::getCharacterSetECIByName(cs));
|
encoder.setEncoding(CharacterSet::get_character_set_by_name(cs));
|
||||||
}
|
}
|
||||||
if let Some(EncodeHintValue::Pdf417AutoEci(auto_eci_str)) =
|
if let Some(EncodeHintValue::Pdf417AutoEci(auto_eci_str)) =
|
||||||
hints.get(&EncodeHintType::PDF417_AUTO_ECI)
|
hints.get(&EncodeHintType::PDF417_AUTO_ECI)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitSource, CharacterSetECI, DecoderRXingResult, Result, StringUtils},
|
common::{BitSource, CharacterSet, DecoderRXingResult, Result, StringUtils},
|
||||||
DecodingHintDictionary, Exceptions,
|
DecodingHintDictionary, Exceptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ pub fn decode(
|
|||||||
Mode::ECI => {
|
Mode::ECI => {
|
||||||
// Count doesn't apply to ECI
|
// Count doesn't apply to ECI
|
||||||
let value = parseECIValue(&mut bits)?;
|
let value = parseECIValue(&mut bits)?;
|
||||||
currentCharacterSetECI = CharacterSetECI::getCharacterSetECIByValue(value).ok();
|
currentCharacterSetECI = CharacterSet::get_character_set_by_eci(value).ok();
|
||||||
if currentCharacterSetECI.is_none() {
|
if currentCharacterSetECI.is_none() {
|
||||||
return Err(Exceptions::format_with(format!(
|
return Err(Exceptions::format_with(format!(
|
||||||
"Value of {value} not valid"
|
"Value of {value} not valid"
|
||||||
@@ -203,7 +203,7 @@ fn decodeHanziSegment(bits: &mut BitSource, result: &mut String, count: usize) -
|
|||||||
count -= 1;
|
count -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let gb_encoder = CharacterSetECI::GB18030;
|
let gb_encoder = CharacterSet::GB18030;
|
||||||
let encode_string = gb_encoder
|
let encode_string = gb_encoder
|
||||||
.decode(&buffer)
|
.decode(&buffer)
|
||||||
.map_err(|e| Exceptions::parse_with(format!("unable to decode buffer {buffer:?}: {e}")))?;
|
.map_err(|e| Exceptions::parse_with(format!("unable to decode buffer {buffer:?}: {e}")))?;
|
||||||
@@ -215,7 +215,7 @@ fn decodeKanjiSegment(
|
|||||||
bits: &mut BitSource,
|
bits: &mut BitSource,
|
||||||
result: &mut String,
|
result: &mut String,
|
||||||
count: usize,
|
count: usize,
|
||||||
currentCharacterSetECI: Option<CharacterSetECI>,
|
currentCharacterSetECI: Option<CharacterSet>,
|
||||||
hints: &DecodingHintDictionary,
|
hints: &DecodingHintDictionary,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Don't crash trying to read more bits than we have available.
|
// Don't crash trying to read more bits than we have available.
|
||||||
@@ -249,7 +249,7 @@ fn decodeKanjiSegment(
|
|||||||
let encoder = {
|
let encoder = {
|
||||||
let _ = currentCharacterSetECI;
|
let _ = currentCharacterSetECI;
|
||||||
let _ = hints;
|
let _ = hints;
|
||||||
CharacterSetECI::SJIS
|
CharacterSet::SJIS
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "allow_forced_iso_ied_18004_compliance")]
|
#[cfg(feature = "allow_forced_iso_ied_18004_compliance")]
|
||||||
@@ -257,12 +257,12 @@ fn decodeKanjiSegment(
|
|||||||
hints.get(&DecodeHintType::QR_ASSUME_SPEC_CONFORM_INPUT)
|
hints.get(&DecodeHintType::QR_ASSUME_SPEC_CONFORM_INPUT)
|
||||||
{
|
{
|
||||||
if let Some(ccse) = ¤tCharacterSetECI {
|
if let Some(ccse) = ¤tCharacterSetECI {
|
||||||
CharacterSetECI::getCharacterSetECIByName(ccse)
|
CharacterSet::getCharacterSetECIByName(ccse)
|
||||||
} else {
|
} else {
|
||||||
CharacterSetECI::ISO8859_1
|
CharacterSet::ISO8859_1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CharacterSetECI::SJIS
|
CharacterSet::SJIS
|
||||||
};
|
};
|
||||||
|
|
||||||
let encode_string = encoder
|
let encode_string = encoder
|
||||||
@@ -278,7 +278,7 @@ fn decodeByteSegment(
|
|||||||
bits: &mut BitSource,
|
bits: &mut BitSource,
|
||||||
result: &mut String,
|
result: &mut String,
|
||||||
count: usize,
|
count: usize,
|
||||||
currentCharacterSetECI: Option<CharacterSetECI>,
|
currentCharacterSetECI: Option<CharacterSet>,
|
||||||
byteSegments: &mut Vec<Vec<u8>>,
|
byteSegments: &mut Vec<Vec<u8>>,
|
||||||
hints: &DecodingHintDictionary,
|
hints: &DecodingHintDictionary,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@@ -307,7 +307,7 @@ fn decodeByteSegment(
|
|||||||
if let Some(DecodeHintValue::QrAssumeSpecConformInput(true)) =
|
if let Some(DecodeHintValue::QrAssumeSpecConformInput(true)) =
|
||||||
hints.get(&DecodeHintType::QR_ASSUME_SPEC_CONFORM_INPUT)
|
hints.get(&DecodeHintType::QR_ASSUME_SPEC_CONFORM_INPUT)
|
||||||
{
|
{
|
||||||
CharacterSetECI::ISO8859_1
|
CharacterSet::ISO8859_1
|
||||||
} else {
|
} else {
|
||||||
StringUtils::guessCharset(&readBytes, hints).ok_or(Exceptions::ILLEGAL_STATE)?
|
StringUtils::guessCharset(&readBytes, hints).ok_or(Exceptions::ILLEGAL_STATE)?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitArray, CharacterSetECI},
|
common::{BitArray, CharacterSet},
|
||||||
qrcode::{
|
qrcode::{
|
||||||
decoder::{ErrorCorrectionLevel, Mode, Version},
|
decoder::{ErrorCorrectionLevel, Mode, Version},
|
||||||
encoder::{qrcode_encoder, MinimalEncoder},
|
encoder::{qrcode_encoder, MinimalEncoder},
|
||||||
@@ -28,7 +28,7 @@ use once_cell::sync::Lazy;
|
|||||||
|
|
||||||
use super::QRCode;
|
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
|
* @author satorux@google.com (Satoru Takabayashi) - creator
|
||||||
@@ -1108,7 +1108,7 @@ fn testMinimalEncoder44() {
|
|||||||
fn verifyMinimalEncoding(
|
fn verifyMinimalEncoding(
|
||||||
input: &str,
|
input: &str,
|
||||||
expectedRXingResult: &str,
|
expectedRXingResult: &str,
|
||||||
priorityCharset: Option<CharacterSetECI>,
|
priorityCharset: Option<CharacterSet>,
|
||||||
isGS1: bool,
|
isGS1: bool,
|
||||||
) {
|
) {
|
||||||
let result = MinimalEncoder::encode_with_details(
|
let result = MinimalEncoder::encode_with_details(
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
use std::{fmt, rc::Rc};
|
use std::{fmt, rc::Rc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{BitArray, CharacterSetECI, ECIEncoderSet, Result},
|
common::{BitArray, CharacterSet, ECIEncoderSet, Result},
|
||||||
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
|
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
|
||||||
Exceptions,
|
Exceptions,
|
||||||
};
|
};
|
||||||
@@ -105,7 +105,7 @@ impl MinimalEncoder {
|
|||||||
*/
|
*/
|
||||||
pub fn new(
|
pub fn new(
|
||||||
stringToEncode: &str,
|
stringToEncode: &str,
|
||||||
priorityCharset: Option<CharacterSetECI>,
|
priorityCharset: Option<CharacterSet>,
|
||||||
isGS1: bool,
|
isGS1: bool,
|
||||||
ecLevel: ErrorCorrectionLevel,
|
ecLevel: ErrorCorrectionLevel,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -140,7 +140,7 @@ impl MinimalEncoder {
|
|||||||
pub fn encode_with_details(
|
pub fn encode_with_details(
|
||||||
stringToEncode: &str,
|
stringToEncode: &str,
|
||||||
version: Option<VersionRef>,
|
version: Option<VersionRef>,
|
||||||
priorityCharset: Option<CharacterSetECI>,
|
priorityCharset: Option<CharacterSet>,
|
||||||
isGS1: bool,
|
isGS1: bool,
|
||||||
ecLevel: ErrorCorrectionLevel,
|
ecLevel: ErrorCorrectionLevel,
|
||||||
) -> Result<RXingResultList> {
|
) -> Result<RXingResultList> {
|
||||||
@@ -1045,7 +1045,7 @@ impl fmt::Display for RXingResultNode {
|
|||||||
self.encoders
|
self.encoders
|
||||||
.getCharset(self.charsetEncoderIndex)
|
.getCharset(self.charsetEncoderIndex)
|
||||||
.ok_or(fmt::Error)?
|
.ok_or(fmt::Error)?
|
||||||
.getCharsetName(),
|
.get_charset_name(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let sub_string: String = self
|
let sub_string: String = self
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
|||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
reedsolomon::{get_predefined_genericgf, PredefinedGenericGF, ReedSolomonEncoder},
|
reedsolomon::{get_predefined_genericgf, PredefinedGenericGF, ReedSolomonEncoder},
|
||||||
BitArray, CharacterSetECI, Result,
|
BitArray, CharacterSet, Result,
|
||||||
},
|
},
|
||||||
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
|
qrcode::decoder::{ErrorCorrectionLevel, Mode, Version, VersionRef},
|
||||||
EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions,
|
EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions,
|
||||||
@@ -32,7 +32,7 @@ use crate::{
|
|||||||
|
|
||||||
use super::{mask_util, matrix_util, BlockPair, ByteMatrix, MinimalEncoder, QRCode};
|
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).
|
// The original table is defined in the table 5 of JISX0510:2004 (p.19).
|
||||||
const ALPHANUMERIC_TABLE: [i8; 96] = [
|
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
|
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.
|
// 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.
|
// 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);
|
let mut has_encoding_hint = hints.contains_key(&EncodeHintType::CHARACTER_SET);
|
||||||
if has_encoding_hint {
|
if has_encoding_hint {
|
||||||
if let Some(EncodeHintValue::CharacterSet(v)) = hints.get(&EncodeHintType::CHARACTER_SET) {
|
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
|
DEFAULT_BYTE_MODE_ENCODING
|
||||||
} else {
|
} else {
|
||||||
has_encoding_hint = true;
|
has_encoding_hint = true;
|
||||||
CharacterSetECI::UTF8
|
CharacterSet::UTF8
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pick an encoding mode appropriate for the content. Note that this will not attempt to use
|
// 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 {
|
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;
|
* 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}.
|
* 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) {
|
if SHIFT_JIS_CHARSET == encoding && isOnlyDoubleByteKanji(content) {
|
||||||
// Choose Kanji mode if all input are double-byte characters
|
// Choose Kanji mode if all input are double-byte characters
|
||||||
return Mode::KANJI;
|
return Mode::KANJI;
|
||||||
@@ -629,7 +629,7 @@ pub fn appendBytes(
|
|||||||
content: &str,
|
content: &str,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
bits: &mut BitArray,
|
bits: &mut BitArray,
|
||||||
encoding: CharacterSetECI,
|
encoding: CharacterSet,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
match mode {
|
match mode {
|
||||||
Mode::NUMERIC => appendNumericBytes(content, bits),
|
Mode::NUMERIC => appendNumericBytes(content, bits),
|
||||||
@@ -719,7 +719,7 @@ pub fn appendAlphanumericBytes(content: &str, bits: &mut BitArray) -> Result<()>
|
|||||||
pub fn append8BitBytes(
|
pub fn append8BitBytes(
|
||||||
content: &str,
|
content: &str,
|
||||||
bits: &mut BitArray,
|
bits: &mut BitArray,
|
||||||
encoding: CharacterSetECI,
|
encoding: CharacterSet,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let bytes = encoding
|
let bytes = encoding
|
||||||
.encode(content)
|
.encode(content)
|
||||||
@@ -762,8 +762,8 @@ pub fn appendKanjiBytes(content: &str, bits: &mut BitArray) -> Result<()> {
|
|||||||
Ok(())
|
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)?;
|
bits.appendBits(Mode::ECI.getBits() as u32, 4)?;
|
||||||
// This is correct for values up to 127, which is all we need now.
|
// 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use rxing::{
|
use rxing::{
|
||||||
common::{CharacterSetECI, HybridBinarizer, Result},
|
common::{CharacterSet, HybridBinarizer, Result},
|
||||||
multi::MultipleBarcodeReader,
|
multi::MultipleBarcodeReader,
|
||||||
pdf417::PDF417RXingResultMetadata,
|
pdf417::PDF417RXingResultMetadata,
|
||||||
BarcodeFormat, Binarizer, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType,
|
BarcodeFormat, Binarizer, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType,
|
||||||
@@ -644,7 +644,7 @@ impl<T: MultipleBarcodeReader + Reader> PDF417MultiImageSpanAbstractBlackBoxTest
|
|||||||
if ext == "bin" {
|
if ext == "bin" {
|
||||||
let mut buffer: Vec<u8> = Vec::new();
|
let mut buffer: Vec<u8> = Vec::new();
|
||||||
File::open(&file)?.read_to_end(&mut buffer)?;
|
File::open(&file)?.read_to_end(&mut buffer)?;
|
||||||
CharacterSetECI::ISO8859_1
|
CharacterSet::ISO8859_1
|
||||||
.decode_replace(&buffer)
|
.decode_replace(&buffer)
|
||||||
.expect("decode")
|
.expect("decode")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user