mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
move to EncodingRef
This commit is contained in:
@@ -118,7 +118,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
|||||||
// 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: &'static dyn encoding::Encoding = encoding::all::UTF_8;
|
// let mut encdr: &'static dyn encoding::Encoding = encoding::all::UTF_8;
|
||||||
let mut encdr: &'static dyn encoding::Encoding = encoding::all::ISO_8859_1;
|
let mut encdr: encoding::EncodingRef = encoding::all::ISO_8859_1;
|
||||||
|
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ pub fn encode_with_charset(
|
|||||||
data: &str,
|
data: &str,
|
||||||
minECCPercent: u32,
|
minECCPercent: u32,
|
||||||
userSpecifiedLayers: i32,
|
userSpecifiedLayers: i32,
|
||||||
charset: &'static dyn encoding::Encoding,
|
charset: encoding::EncodingRef,
|
||||||
) -> Result<AztecCode, Exceptions> {
|
) -> Result<AztecCode, Exceptions> {
|
||||||
let bytes = charset
|
let bytes = charset
|
||||||
.encode(data, encoding::EncoderTrap::Strict)
|
.encode(data, encoding::EncoderTrap::Strict)
|
||||||
@@ -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: &'static dyn encoding::Encoding,
|
charset: encoding::EncodingRef,
|
||||||
) -> Result<AztecCode, Exceptions> {
|
) -> Result<AztecCode, Exceptions> {
|
||||||
// High-level encode
|
// High-level encode
|
||||||
let bits = HighLevelEncoder::with_charset(data.into(), charset).encode()?;
|
let bits = HighLevelEncoder::with_charset(data.into(), charset).encode()?;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ use super::{State, Token};
|
|||||||
*/
|
*/
|
||||||
pub struct HighLevelEncoder {
|
pub struct HighLevelEncoder {
|
||||||
text: Vec<u8>,
|
text: Vec<u8>,
|
||||||
charset: &'static dyn encoding::Encoding,
|
charset: encoding::EncodingRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HighLevelEncoder {
|
impl HighLevelEncoder {
|
||||||
@@ -235,7 +235,7 @@ impl HighLevelEncoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_charset(text: Vec<u8>, charset: &'static dyn encoding::Encoding) -> Self {
|
pub fn with_charset(text: Vec<u8>, charset: encoding::EncodingRef) -> Self {
|
||||||
Self { text, charset }
|
Self { text, charset }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
// import java.nio.charset.StandardCharsets;
|
// import java.nio.charset.StandardCharsets;
|
||||||
// import java.util.Random;
|
// import java.util.Random;
|
||||||
|
|
||||||
use encoding::Encoding;
|
use encoding::{Encoding, EncodingRef};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ fn test_utf16_le() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_test(bytes: &Vec<u8>, charset: &dyn Encoding, encoding: &str) {
|
fn do_test(bytes: &Vec<u8>, charset: EncodingRef, encoding: &str) {
|
||||||
let guessedCharset = StringUtils::guessCharset(bytes, &HashMap::new());
|
let guessedCharset = StringUtils::guessCharset(bytes, &HashMap::new());
|
||||||
let guessedEncoding = StringUtils::guessEncoding(bytes, &HashMap::new());
|
let guessedEncoding = StringUtils::guessEncoding(bytes, &HashMap::new());
|
||||||
assert_eq!(charset.name(), guessedCharset.name());
|
assert_eq!(charset.name(), guessedCharset.name());
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ 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) -> &'static dyn Encoding {
|
pub fn guessCharset(bytes: &[u8], hints: &DecodingHintDictionary) -> EncodingRef {
|
||||||
match hints.get(&DecodeHintType::CHARACTER_SET) {
|
match hints.get(&DecodeHintType::CHARACTER_SET) {
|
||||||
Some(hint) => {
|
Some(hint) => {
|
||||||
if let DecodeHintValue::CharacterSet(cs_name) = hint {
|
if let DecodeHintValue::CharacterSet(cs_name) = hint {
|
||||||
@@ -2565,7 +2565,7 @@ 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 getCharacterSetECI(charset: &'static dyn Encoding) -> Option<CharacterSetECI> {
|
pub fn getCharacterSetECI(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 {
|
||||||
@@ -2712,7 +2712,7 @@ impl CharacterSetECI {
|
|||||||
pub struct ECIStringBuilder {
|
pub struct ECIStringBuilder {
|
||||||
current_bytes: Vec<u8>,
|
current_bytes: Vec<u8>,
|
||||||
result: String,
|
result: String,
|
||||||
current_charset: &'static dyn Encoding, //= StandardCharsets.ISO_8859_1;
|
current_charset: EncodingRef, //= StandardCharsets.ISO_8859_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ECIStringBuilder {
|
impl ECIStringBuilder {
|
||||||
|
|||||||
Reference in New Issue
Block a user