diff --git a/Cargo.toml b/Cargo.toml index 3deec45..c68596f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ exclude = [ [dependencies] regex = "1.7.0" fancy-regex = "0.10" -lazy_static = "1.4.0" +once_cell = "1.17.0" encoding = "0.2" rand = "0.8.5" urlencoding = "2.1.2" diff --git a/src/aztec/shared_test_methods.rs b/src/aztec/shared_test_methods.rs index 9ca8602..51e9779 100644 --- a/src/aztec/shared_test_methods.rs +++ b/src/aztec/shared_test_methods.rs @@ -2,12 +2,10 @@ use regex::Regex; use crate::common::BitArray; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref SPACES: Regex = Regex::new("\\s+").unwrap(); - static ref DOTX: Regex = Regex::new("[^.X]").unwrap(); -} +static SPACES: Lazy = Lazy::new(|| Regex::new("\\s+").unwrap()); +static DOTX: Lazy = Lazy::new(|| Regex::new("[^.X]").unwrap()); #[allow(dead_code)] pub fn toBitArray(bits: &str) -> BitArray { diff --git a/src/client/result/CalendarParsedResult.rs b/src/client/result/CalendarParsedResult.rs index 17be512..1c63410 100644 --- a/src/client/result/CalendarParsedResult.rs +++ b/src/client/result/CalendarParsedResult.rs @@ -29,7 +29,7 @@ use chrono::{DateTime, NaiveDateTime, TimeZone, Utc}; use chrono_tz::Tz; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use regex::Regex; use crate::exceptions::Exceptions; @@ -46,11 +46,11 @@ const RFC2445_DURATION_FIELD_UNITS: [i64; 5] = [ 1000i64, // 1 second ]; -lazy_static! { - static ref DATE_TIME: Regex = Regex::new("[0-9]{8}(T[0-9]{6}Z?)?").unwrap(); - static ref RFC2445_DURATION: Regex = - Regex::new("P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?").unwrap(); -} +static DATE_TIME: Lazy = Lazy::new(|| Regex::new("[0-9]{8}(T[0-9]{6}Z?)?").unwrap()); +static RFC2445_DURATION: Lazy = Lazy::new(|| { + Regex::new("P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?").unwrap() +}); + // const DATE_TIME: &'static str = "[0-9]{8}(T[0-9]{6}Z?)?"; /** diff --git a/src/client/result/EmailAddressResultParser.rs b/src/client/result/EmailAddressResultParser.rs index 255b087..0570b8b 100644 --- a/src/client/result/EmailAddressResultParser.rs +++ b/src/client/result/EmailAddressResultParser.rs @@ -24,13 +24,11 @@ use regex::Regex; use crate::RXingResult; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref COMMA: Regex = Regex::new(",").unwrap(); - static ref ATEXT_ALPHANUMERIC: Regex = - Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap(); -} +static COMMA: Lazy = Lazy::new(|| Regex::new(",").unwrap()); +static ATEXT_ALPHANUMERIC: Lazy = + Lazy::new(|| Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap()); use super::{ EmailAddressParsedRXingResult, EmailDoCoMoResultParser, ParsedClientResult, ResultParser, diff --git a/src/client/result/EmailDoCoMoResultParser.rs b/src/client/result/EmailDoCoMoResultParser.rs index 6a05b82..a7e4e62 100644 --- a/src/client/result/EmailDoCoMoResultParser.rs +++ b/src/client/result/EmailDoCoMoResultParser.rs @@ -26,12 +26,10 @@ use crate::RXingResult; use super::{EmailAddressParsedRXingResult, ParsedClientResult, ResultParser}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref ATEXT_ALPHANUMERIC: Regex = - Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap(); -} +static ATEXT_ALPHANUMERIC: Lazy = + Lazy::new(|| Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap()); /** * Implements the "MATMSG" email message entry format. diff --git a/src/client/result/GeoResultParser.rs b/src/client/result/GeoResultParser.rs index 2eaa550..1cee854 100644 --- a/src/client/result/GeoResultParser.rs +++ b/src/client/result/GeoResultParser.rs @@ -23,11 +23,9 @@ use super::{GeoParsedRXingResult, ParsedClientResult, ResultParser}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref GEO_URL: regex::Regex = regex::Regex::new(GEO_URL_PATTERN).unwrap(); -} +static GEO_URL: Lazy = Lazy::new(|| regex::Regex::new(GEO_URL_PATTERN).unwrap()); const GEO_URL_PATTERN: &str = "geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?"; diff --git a/src/client/result/ResultParser.rs b/src/client/result/ResultParser.rs index 106406a..8b7daed 100644 --- a/src/client/result/ResultParser.rs +++ b/src/client/result/ResultParser.rs @@ -31,7 +31,7 @@ use std::collections::HashMap; use regex::Regex; use urlencoding::decode; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::{exceptions::Exceptions, RXingResult}; @@ -92,9 +92,7 @@ use super::{ pub type ParserFunction = dyn Fn(&RXingResult) -> Option; -lazy_static! { - static ref DIGITS: Regex = Regex::new("\\d+").unwrap(); -} +static DIGITS: Lazy = Lazy::new(|| Regex::new("\\d+").unwrap()); // const DIGITS: &'static str = "\\d+"; //= Pattern.compile("\\d+"); const AMPERSAND: &str = "&"; // private static final Pattern AMPERSAND = Pattern.compile("&"); diff --git a/src/client/result/URIResultParser.rs b/src/client/result/URIResultParser.rs index 9593474..d85d37c 100644 --- a/src/client/result/URIResultParser.rs +++ b/src/client/result/URIResultParser.rs @@ -21,7 +21,7 @@ // import java.util.regex.Matcher; // import java.util.regex.Pattern; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; /** * Tries to parse results that are a URI of some kind. * @@ -34,15 +34,15 @@ use crate::RXingResult; use super::{ParsedClientResult, ResultParser, URIParsedRXingResult}; -lazy_static! { - static ref ALLOWED_URI_CHARS: Regex = - Regex::new(ALLOWED_URI_CHARS_PATTERN).expect("Regex patterns should always copile"); - static ref USER_IN_HOST: Regex = - Regex::new(":/*([^/@]+)@[^/]+").expect("Regex patterns should always copile"); - static ref URL_WITH_PROTOCOL_PATTERN: Regex = Regex::new("[a-zA-Z][a-zA-Z0-9+-.]+:").unwrap(); - static ref URL_WITHOUT_PROTOCOL_PATTERN: Regex = - Regex::new("([a-zA-Z0-9\\-]+\\.){1,6}[a-zA-Z]{2,}(:\\d{1,5})?(/|\\?|$)").unwrap(); -} +static ALLOWED_URI_CHARS: Lazy = Lazy::new(|| { + Regex::new(ALLOWED_URI_CHARS_PATTERN).expect("Regex patterns should always copile") +}); +static USER_IN_HOST: Lazy = + Lazy::new(|| Regex::new(":/*([^/@]+)@[^/]+").expect("Regex patterns should always copile")); +static URL_WITH_PROTOCOL_PATTERN: Lazy = + Lazy::new(|| Regex::new("[a-zA-Z][a-zA-Z0-9+-.]+:").unwrap()); +static URL_WITHOUT_PROTOCOL_PATTERN: Lazy = + Lazy::new(|| Regex::new("([a-zA-Z0-9\\-]+\\.){1,6}[a-zA-Z]{2,}(:\\d{1,5})?(/|\\?|$)").unwrap()); const ALLOWED_URI_CHARS_PATTERN: &str = "[-._~:/?#\\[\\]@!$&'()*+,;=%A-Za-z0-9]+"; // const USER_IN_HOST: &'static str = ":/*([^/@]+)@[^/]+"; diff --git a/src/client/result/VCardResultParser.rs b/src/client/result/VCardResultParser.rs index 6b4e298..5c80555 100644 --- a/src/client/result/VCardResultParser.rs +++ b/src/client/result/VCardResultParser.rs @@ -32,7 +32,7 @@ use std::convert::TryFrom; use regex::Regex; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::RXingResult; @@ -40,17 +40,15 @@ use uriparse::URI; use super::{AddressBookParsedRXingResult, ParsedClientResult, ResultParser}; -lazy_static! { - static ref BEGIN_VCARD: Regex = Regex::new("(?i:BEGIN:VCARD)").unwrap(); - static ref VCARD_LIKE_DATE: Regex = Regex::new("\\d{4}-?\\d{2}-?\\d{2}").unwrap(); - static ref CR_LF_SPACE_TAB: Regex = Regex::new("\r\n[ \t]").unwrap(); - static ref NEWLINE_ESCAPE: Regex = Regex::new("\\\\[nN]").unwrap(); - static ref VCARD_ESCAPE: Regex = Regex::new("\\\\([,;\\\\])").unwrap(); - static ref EQUALS: Regex = Regex::new("=").unwrap(); - static ref UNESCAPED_SEMICOLONS: fancy_regex::Regex = - fancy_regex::Regex::new("(? = Lazy::new(|| Regex::new("(?i:BEGIN:VCARD)").unwrap()); +static VCARD_LIKE_DATE: Lazy = Lazy::new(|| Regex::new("\\d{4}-?\\d{2}-?\\d{2}").unwrap()); +static CR_LF_SPACE_TAB: Lazy = Lazy::new(|| Regex::new("\r\n[ \t]").unwrap()); +static NEWLINE_ESCAPE: Lazy = Lazy::new(|| Regex::new("\\\\[nN]").unwrap()); +static VCARD_ESCAPE: Lazy = Lazy::new(|| Regex::new("\\\\([,;\\\\])").unwrap()); +static EQUALS: Lazy = Lazy::new(|| Regex::new("=").unwrap()); +static UNESCAPED_SEMICOLONS: Lazy = + Lazy::new(|| fancy_regex::Regex::new("(? = Lazy::new(|| Regex::new("[;,]").unwrap()); // const BEGIN_VCARD: &'static str = "(?i:BEGIN:VCARD)"; //, Pattern.CASE_INSENSITIVE); // const VCARD_LIKE_DATE: &'static str = "\\d{4}-?\\d{2}-?\\d{2}"; diff --git a/src/client/result/VINResultParser.rs b/src/client/result/VINResultParser.rs index d82e704..60d0735 100644 --- a/src/client/result/VINResultParser.rs +++ b/src/client/result/VINResultParser.rs @@ -29,12 +29,10 @@ use crate::{ use super::ParsedClientResult; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref IOQ_MATCHER: Regex = Regex::new(IOQ).unwrap(); - static ref AZ09_MATCHER: Regex = Regex::new(AZ09).unwrap(); -} +static IOQ_MATCHER: Lazy = Lazy::new(|| Regex::new(IOQ).unwrap()); +static AZ09_MATCHER: Lazy = Lazy::new(|| Regex::new(AZ09).unwrap()); /** * Detects a result that is likely a vehicle identification number. diff --git a/src/common/StringUtilsTestCase.rs b/src/common/StringUtilsTestCase.rs index e8cf00e..b8b70cf 100644 --- a/src/common/StringUtilsTestCase.rs +++ b/src/common/StringUtilsTestCase.rs @@ -56,11 +56,7 @@ fn test_short_shift_jis1() { #[test] fn test_short_iso885911() { // båd - do_test( - &[0x62, 0xe5, 0x64], - encoding::all::ISO_8859_1, - "ISO8859_1", - ); + do_test(&[0x62, 0xe5, 0x64], encoding::all::ISO_8859_1, "ISO8859_1"); } #[test] diff --git a/src/common/eci_encoder_set.rs b/src/common/eci_encoder_set.rs index b27494c..25a4e8a 100644 --- a/src/common/eci_encoder_set.rs +++ b/src/common/eci_encoder_set.rs @@ -28,23 +28,22 @@ use unicode_segmentation::UnicodeSegmentation; use super::CharacterSetECI; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref ENCODERS : Vec = { - let mut enc_vec = Vec::new(); - for name in NAMES { - if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(name) { - // try { - enc_vec.push(CharacterSetECI::getCharset(&enc)); - // } catch (UnsupportedCharsetException e) { - // continue - // } - } +static ENCODERS: Lazy> = Lazy::new(|| { + let mut enc_vec = Vec::new(); + for name in NAMES { + if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(name) { + // try { + enc_vec.push(CharacterSetECI::getCharset(&enc)); + // } catch (UnsupportedCharsetException e) { + // continue + // } } - enc_vec - }; -} + } + enc_vec +}); + const NAMES: [&str; 20] = [ "IBM437", "ISO-8859-2", diff --git a/src/common/reedsolomon/mod.rs b/src/common/reedsolomon/mod.rs index 224b59f..c675bf8 100644 --- a/src/common/reedsolomon/mod.rs +++ b/src/common/reedsolomon/mod.rs @@ -22,18 +22,14 @@ pub(crate) mod ReedSolomonTestCase; //package com.google.zxing.common.reedsolomon; pub type GenericGFRef = &'static GenericGF; +use once_cell::sync::Lazy; -use lazy_static::lazy_static; - -lazy_static! { - static ref AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1 - static ref AZTEC_DATA_10: GenericGF = GenericGF::new(0x409, 1024, 1); // x^10 + x^3 + 1 - static ref AZTEC_DATA_6: GenericGF = GenericGF::new(0x43, 64, 1); // x^6 + x + 1 - static ref AZTEC_PARAM: GenericGF = GenericGF::new(0x13, 16, 1); // x^4 + x + 1 - static ref QR_CODE_FIELD_256: GenericGF = GenericGF::new(0x011D, 256, 0); // x^8 + x^4 + x^3 + x^2 + 1 - static ref DATA_MATRIX_FIELD_256: GenericGF = GenericGF::new(0x012D, 256, 1); // x^8 + x^5 + x^3 + x^2 + 1 - // static ref PDF_417_FIELD: GenericGF = GenericGF::new(3,crate::pdf417::pdf_417_common::NUMBER_OF_CODEWORDS as usize,1); -} +static AZTEC_DATA_12: Lazy = Lazy::new(|| GenericGF::new(0x1069, 4096, 1)); // x^12 + x^6 + x^5 + x^3 + 1 +static AZTEC_DATA_10: Lazy = Lazy::new(|| GenericGF::new(0x409, 1024, 1)); // x^10 + x^3 + 1 +static AZTEC_DATA_6: Lazy = Lazy::new(|| GenericGF::new(0x43, 64, 1)); // x^6 + x + 1 +static AZTEC_PARAM: Lazy = Lazy::new(|| GenericGF::new(0x13, 16, 1)); // x^4 + x + 1 +static QR_CODE_FIELD_256: Lazy = Lazy::new(|| GenericGF::new(0x011D, 256, 0)); // x^8 + x^4 + x^3 + x^2 + 1 +static DATA_MATRIX_FIELD_256: Lazy = Lazy::new(|| GenericGF::new(0x012D, 256, 1)); // x^8 + x^5 + x^3 + x^2 + 1 // pub const AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1 // pub const AZTEC_DATA_10: GenericGF = GenericGF::new(0x409, 1024, 1); // x^10 + x^3 + 1 diff --git a/src/common/string_utils.rs b/src/common/string_utils.rs index ee1eb8a..29893b1 100644 --- a/src/common/string_utils.rs +++ b/src/common/string_utils.rs @@ -24,7 +24,7 @@ use encoding::{Encoding, EncodingRef}; use crate::{DecodeHintType, DecodeHintValue, DecodingHintDictionary}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; /** * Common string-related functions. @@ -55,10 +55,9 @@ pub struct StringUtils { const ASSUME_SHIFT_JIS: bool = false; // static SHIFT_JIS: &'static str = "SJIS"; // static GB2312: &'static str = "GB2312"; -lazy_static! { - pub static ref SHIFT_JIS_CHARSET: EncodingRef = - encoding::label::encoding_from_whatwg_label("SJIS").unwrap(); -} + +pub static SHIFT_JIS_CHARSET: Lazy = + Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap()); // private static final boolean ASSUME_SHIFT_JIS = // SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) || diff --git a/src/datamatrix/data_matrix_reader.rs b/src/datamatrix/data_matrix_reader.rs index d970336..d5857b8 100644 --- a/src/datamatrix/data_matrix_reader.rs +++ b/src/datamatrix/data_matrix_reader.rs @@ -24,11 +24,9 @@ use crate::{ use super::{decoder::Decoder, detector::Detector}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref DECODER: Decoder = Decoder::new(); -} +static DECODER: Lazy = Lazy::new(|| Decoder::new()); /** * This implementation can detect and decode Data Matrix codes in an image. diff --git a/src/datamatrix/decoder/version.rs b/src/datamatrix/decoder/version.rs index 255cc43..7f31981 100644 --- a/src/datamatrix/decoder/version.rs +++ b/src/datamatrix/decoder/version.rs @@ -15,13 +15,11 @@ */ use core::fmt; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::Exceptions; -lazy_static! { - static ref VERSIONS: Vec = Version::buildVersions(); -} +static VERSIONS: Lazy> = Lazy::new(|| Version::buildVersions()); pub type VersionRef = &'static Version; diff --git a/src/datamatrix/encoder/error_correction.rs b/src/datamatrix/encoder/error_correction.rs index c0c05d6..79edb90 100644 --- a/src/datamatrix/encoder/error_correction.rs +++ b/src/datamatrix/encoder/error_correction.rs @@ -18,7 +18,7 @@ use crate::Exceptions; use super::SymbolInfo; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; /** * Error Correction Code for ECC200. @@ -30,66 +30,68 @@ use lazy_static::lazy_static; */ const FACTOR_SETS: [u32; 16] = [5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 62, 68]; -lazy_static! { /** * Precomputed polynomial factors for ECC 200. */ -static ref FACTORS: [Vec; 16] = [ - Vec::from([228, 48, 15, 111, 62]), - Vec::from([23, 68, 144, 134, 240, 92, 254]), - Vec::from([28, 24, 185, 166, 223, 248, 116, 255, 110, 61]), - Vec::from([175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120]), - Vec::from([41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242]), - Vec::from([ - 156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185, - ]), - Vec::from([ - 83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90, 188, - ]), - Vec::from([ - 15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186, 172, - ]), - Vec::from([ - 52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172, 254, 124, 12, 181, - 184, 96, 50, 193, - ]), - Vec::from([ - 211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121, 17, 138, 110, 213, - 141, 136, 120, 151, 233, 168, 93, 255, - ]), - Vec::from([ - 245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80, 182, 229, 18, 2, - 4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25, 225, 98, 81, 112, - ]), - Vec::from([ - 77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8, 175, 95, 100, 9, - 167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101, 248, 202, 69, 50, 150, 177, 226, 5, - 9, 5, - ]), - Vec::from([ - 245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87, 191, 106, 16, - 147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138, 186, 240, 82, 44, 176, 87, 187, - 147, 160, 175, 69, 213, 92, 253, 225, 19, - ]), - Vec::from([ - 175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235, 150, 159, 36, - 223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232, 144, 238, 22, 150, 201, 117, - 62, 207, 164, 13, 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53, 143, 46, - ]), - Vec::from([ - 242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37, 185, 112, 134, - 230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114, 71, 161, 44, 147, 6, 27, 218, 51, - 63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47, - 11, 204, - ]), - Vec::from([ - 220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127, 213, 136, 248, - 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236, 66, 139, 153, 185, 202, 167, - 179, 25, 220, 232, 96, 210, 231, 136, 223, 239, 181, 241, 59, 52, 172, 25, 49, 232, 211, - 189, 64, 54, 108, 153, 132, 63, 96, 103, 82, 186, - ]), -]; - } +static FACTORS: Lazy<[Vec; 16]> = Lazy::new(|| { + [ + Vec::from([228, 48, 15, 111, 62]), + Vec::from([23, 68, 144, 134, 240, 92, 254]), + Vec::from([28, 24, 185, 166, 223, 248, 116, 255, 110, 61]), + Vec::from([175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120]), + Vec::from([41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242]), + Vec::from([ + 156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185, + ]), + Vec::from([ + 83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90, 188, + ]), + Vec::from([ + 15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186, + 172, + ]), + Vec::from([ + 52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172, 254, 124, 12, + 181, 184, 96, 50, 193, + ]), + Vec::from([ + 211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121, 17, 138, 110, + 213, 141, 136, 120, 151, 233, 168, 93, 255, + ]), + Vec::from([ + 245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80, 182, 229, 18, + 2, 4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25, 225, 98, 81, 112, + ]), + Vec::from([ + 77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8, 175, 95, 100, 9, + 167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101, 248, 202, 69, 50, 150, 177, 226, + 5, 9, 5, + ]), + Vec::from([ + 245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87, 191, 106, + 16, 147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138, 186, 240, 82, 44, 176, + 87, 187, 147, 160, 175, 69, 213, 92, 253, 225, 19, + ]), + Vec::from([ + 175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235, 150, 159, + 36, 223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232, 144, 238, 22, 150, + 201, 117, 62, 207, 164, 13, 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53, + 143, 46, + ]), + Vec::from([ + 242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37, 185, 112, + 134, 230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114, 71, 161, 44, 147, 6, 27, + 218, 51, 63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, 232, 7, 94, 166, 224, + 124, 86, 47, 11, 204, + ]), + Vec::from([ + 220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127, 213, 136, + 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236, 66, 139, 153, 185, + 202, 167, 179, 25, 220, 232, 96, 210, 231, 136, 223, 239, 181, 241, 59, 52, 172, 25, + 49, 232, 211, 189, 64, 54, 108, 153, 132, 63, 96, 103, 82, 186, + ]), + ] +}); const MODULO_VALUE: usize = 0x12D; diff --git a/src/datamatrix/encoder/high_level_encode_test_case.rs b/src/datamatrix/encoder/high_level_encode_test_case.rs index e90cad0..f875b7c 100644 --- a/src/datamatrix/encoder/high_level_encode_test_case.rs +++ b/src/datamatrix/encoder/high_level_encode_test_case.rs @@ -16,27 +16,26 @@ use std::rc::Rc; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::datamatrix::encoder::{SymbolInfo, SymbolShapeHint}; use super::{high_level_encoder, minimal_encoder, symbol_info, SymbolInfoLookup}; -lazy_static! { - /** +/** * Tests for {@link HighLevelEncoder} and {@link MinimalEncoder} */ - static ref TEST_SYMBOLS :Vec= vec![ - SymbolInfo::new(false, 3, 5, 8, 8, 1), - SymbolInfo::new(false, 5, 7, 10, 10, 1), - /*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1), - SymbolInfo::new(false, 8, 10, 12, 12, 1), - /*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2), - SymbolInfo::new(false, 13, 0, 0, 0, 1), - SymbolInfo::new(false, 77, 0, 0, 0, 1) - //The last entries are fake entries to test special conditions with C40 encoding - ]; -} +static TEST_SYMBOLS: Lazy> = Lazy::new(|| { + vec![ + SymbolInfo::new(false, 3, 5, 8, 8, 1), + SymbolInfo::new(false, 5, 7, 10, 10, 1), + /*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1), + SymbolInfo::new(false, 8, 10, 12, 12, 1), + /*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2), + SymbolInfo::new(false, 13, 0, 0, 0, 1), + SymbolInfo::new(false, 77, 0, 0, 0, 1), //The last entries are fake entries to test special conditions with C40 encoding + ] +}); // const SIL: SymbolInfoLookup = SymbolInfoLookup::new(); diff --git a/src/datamatrix/encoder/symbol_info.rs b/src/datamatrix/encoder/symbol_info.rs index ac97d09..45d5a1f 100644 --- a/src/datamatrix/encoder/symbol_info.rs +++ b/src/datamatrix/encoder/symbol_info.rs @@ -19,42 +19,42 @@ use std::fmt; use crate::{Dimension, Exceptions}; use super::SymbolShapeHint; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { -pub(super) static ref PROD_SYMBOLS: Vec = vec![ - SymbolInfo::new(false, 3, 5, 8, 8, 1), - SymbolInfo::new(false, 5, 7, 10, 10, 1), - /*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1), - SymbolInfo::new(false, 8, 10, 12, 12, 1), - /*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2), - SymbolInfo::new(false, 12, 12, 14, 14, 1), - /*rect*/ SymbolInfo::new(true, 16, 14, 24, 10, 1), - SymbolInfo::new(false, 18, 14, 16, 16, 1), - SymbolInfo::new(false, 22, 18, 18, 18, 1), - /*rect*/ SymbolInfo::new(true, 22, 18, 16, 10, 2), - SymbolInfo::new(false, 30, 20, 20, 20, 1), - /*rect*/ SymbolInfo::new(true, 32, 24, 16, 14, 2), - SymbolInfo::new(false, 36, 24, 22, 22, 1), - SymbolInfo::new(false, 44, 28, 24, 24, 1), - /*rect*/ SymbolInfo::new(true, 49, 28, 22, 14, 2), - SymbolInfo::new(false, 62, 36, 14, 14, 4), - SymbolInfo::new(false, 86, 42, 16, 16, 4), - SymbolInfo::new(false, 114, 48, 18, 18, 4), - SymbolInfo::new(false, 144, 56, 20, 20, 4), - SymbolInfo::new(false, 174, 68, 22, 22, 4), - SymbolInfo::with_details(false, 204, 84, 24, 24, 4, 102, 42), - SymbolInfo::with_details(false, 280, 112, 14, 14, 16, 140, 56), - SymbolInfo::with_details(false, 368, 144, 16, 16, 16, 92, 36), - SymbolInfo::with_details(false, 456, 192, 18, 18, 16, 114, 48), - SymbolInfo::with_details(false, 576, 224, 20, 20, 16, 144, 56), - SymbolInfo::with_details(false, 696, 272, 22, 22, 16, 174, 68), - SymbolInfo::with_details(false, 816, 336, 24, 24, 16, 136, 56), - SymbolInfo::with_details(false, 1050, 408, 18, 18, 36, 175, 68), - SymbolInfo::with_details(false, 1304, 496, 20, 20, 36, 163, 62), - SymbolInfo::new_symbol_info_144(), -]; -} +pub(super) static PROD_SYMBOLS: Lazy> = Lazy::new(|| { + vec![ + SymbolInfo::new(false, 3, 5, 8, 8, 1), + SymbolInfo::new(false, 5, 7, 10, 10, 1), + /*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1), + SymbolInfo::new(false, 8, 10, 12, 12, 1), + /*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2), + SymbolInfo::new(false, 12, 12, 14, 14, 1), + /*rect*/ SymbolInfo::new(true, 16, 14, 24, 10, 1), + SymbolInfo::new(false, 18, 14, 16, 16, 1), + SymbolInfo::new(false, 22, 18, 18, 18, 1), + /*rect*/ SymbolInfo::new(true, 22, 18, 16, 10, 2), + SymbolInfo::new(false, 30, 20, 20, 20, 1), + /*rect*/ SymbolInfo::new(true, 32, 24, 16, 14, 2), + SymbolInfo::new(false, 36, 24, 22, 22, 1), + SymbolInfo::new(false, 44, 28, 24, 24, 1), + /*rect*/ SymbolInfo::new(true, 49, 28, 22, 14, 2), + SymbolInfo::new(false, 62, 36, 14, 14, 4), + SymbolInfo::new(false, 86, 42, 16, 16, 4), + SymbolInfo::new(false, 114, 48, 18, 18, 4), + SymbolInfo::new(false, 144, 56, 20, 20, 4), + SymbolInfo::new(false, 174, 68, 22, 22, 4), + SymbolInfo::with_details(false, 204, 84, 24, 24, 4, 102, 42), + SymbolInfo::with_details(false, 280, 112, 14, 14, 16, 140, 56), + SymbolInfo::with_details(false, 368, 144, 16, 16, 16, 92, 36), + SymbolInfo::with_details(false, 456, 192, 18, 18, 16, 114, 48), + SymbolInfo::with_details(false, 576, 224, 20, 20, 16, 144, 56), + SymbolInfo::with_details(false, 696, 272, 22, 22, 16, 174, 68), + SymbolInfo::with_details(false, 816, 336, 24, 24, 16, 136, 56), + SymbolInfo::with_details(false, 1050, 408, 18, 18, 36, 175, 68), + SymbolInfo::with_details(false, 1304, 496, 20, 20, 36, 163, 62), + SymbolInfo::new_symbol_info_144(), + ] +}); /** * Symbol info table for DataMatrix. diff --git a/src/helpers.rs b/src/helpers.rs index 2c78b33..3c6767f 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -36,7 +36,9 @@ pub fn detect_in_file_with_hints( ); } - hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); + hints + .entry(DecodeHintType::TRY_HARDER) + .or_insert(DecodeHintValue::TryHarder(true)); multi_format_reader.decode_with_hints( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( @@ -60,7 +62,9 @@ pub fn detect_multiple_in_file_with_hints( let multi_format_reader = MultiFormatReader::default(); let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader); - hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); + hints + .entry(DecodeHintType::TRY_HARDER) + .or_insert(DecodeHintValue::TryHarder(true)); scanner.decode_multiple_with_hints( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( @@ -95,7 +99,9 @@ pub fn detect_in_luma_with_hints( ); } - hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); + hints + .entry(DecodeHintType::TRY_HARDER) + .or_insert(DecodeHintValue::TryHarder(true)); multi_format_reader.decode_with_hints( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( @@ -122,7 +128,9 @@ pub fn detect_multiple_in_luma_with_hints( let multi_format_reader = MultiFormatReader::default(); let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader); - hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); + hints + .entry(DecodeHintType::TRY_HARDER) + .or_insert(DecodeHintValue::TryHarder(true)); scanner.decode_multiple_with_hints( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( diff --git a/src/lib.rs b/src/lib.rs index 7db688f..36ece51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,4 +98,4 @@ pub use multi_format_reader::*; pub mod helpers; mod luma_luma_source; -pub use luma_luma_source::*; \ No newline at end of file +pub use luma_luma_source::*; diff --git a/src/maxicode/decoder/decoded_bit_stream_parser.rs b/src/maxicode/decoder/decoded_bit_stream_parser.rs index 738a9c9..429d799 100644 --- a/src/maxicode/decoder/decoded_bit_stream_parser.rs +++ b/src/maxicode/decoder/decoded_bit_stream_parser.rs @@ -17,7 +17,7 @@ use unicode_segmentation::UnicodeSegmentation; use crate::{common::DecoderRXingResult, Exceptions}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; /** *

MaxiCodes can encode text or structured information as bits in one of several modes, @@ -59,8 +59,8 @@ const POSTCODE_3_BYTES: [[u8; 6]; 6] = [ [9, 10, 11, 12, 1, 2], ]; -lazy_static! { -static ref SETS : [String;5]= [ +static SETS: Lazy<[String; 5]> = Lazy::new(|| { + [ format!("\rABCDEFGHIJKLMNOPQRSTUVWXYZ{}{}{}{}{} {}\"#$%&'()*+,-./0123456789:{}{}{}{}{}" , ECI , FS , GS , RS , NS , PAD , SHIFTB , SHIFTC , SHIFTD , SHIFTE , LATCHB), format!("`abcdefghijklmnopqrstuvwxyz{}{}{}{}{}{{{}}}~\u{007F};<=>?[\\]^_ ,./:@!|{}{}{}{}{}{}{}{}{}" , ECI , FS , GS , RS , NS ,PAD , @@ -78,8 +78,8 @@ static ref SETS : [String;5]= [ ECI , PAD , PAD , '\u{001B}' , NS , FS , GS , RS , "\u{001F}\u{009F}\u{00A0}\u{00A2}\u{00A3}\u{00A4}\u{00A5}\u{00A6}\u{00A7}\u{00A9}\u{00AD}\u{00AE}\u{00B6}\u{0095}\u{0096}\u{0097}\u{0098}\u{0099}\u{009A}\u{009B}\u{009C}\u{009D}\u{009E}" , LATCHA , ' ' , SHIFTC , SHIFTD , LOCK , LATCHB), - ]; -} + ] +}); pub fn decode(bytes: &[u8], mode: u8) -> Result { let mut result = String::with_capacity(144); diff --git a/src/maxicode/decoder/decoder.rs b/src/maxicode/decoder/decoder.rs index 94528e0..ed210f6 100644 --- a/src/maxicode/decoder/decoder.rs +++ b/src/maxicode/decoder/decoder.rs @@ -16,7 +16,7 @@ use std::collections::HashMap; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::{ common::{ @@ -39,11 +39,11 @@ const ALL: u32 = 0; const EVEN: u32 = 1; const ODD: u32 = 2; -lazy_static! { - static ref RS_DECODER: ReedSolomonDecoder = ReedSolomonDecoder::new(get_predefined_genericgf( - PredefinedGenericGF::MaxicodeField64 - )); -} +static RS_DECODER: Lazy = Lazy::new(|| { + ReedSolomonDecoder::new(get_predefined_genericgf( + PredefinedGenericGF::MaxicodeField64, + )) +}); pub fn decode(bits: BitMatrix) -> Result { decode_with_hints(bits, &HashMap::new()) diff --git a/src/oned/code_128_reader.rs b/src/oned/code_128_reader.rs index bdd3c25..6355e64 100644 --- a/src/oned/code_128_reader.rs +++ b/src/oned/code_128_reader.rs @@ -450,120 +450,119 @@ impl Code128Reader { } } -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - -pub static ref CODE_PATTERNS: [Vec; 107] = [ - vec![2, 1, 2, 2, 2, 2], // 0 - vec![2, 2, 2, 1, 2, 2], - vec![2, 2, 2, 2, 2, 1], - vec![1, 2, 1, 2, 2, 3], - vec![1, 2, 1, 3, 2, 2], - vec![1, 3, 1, 2, 2, 2], // 5 - vec![1, 2, 2, 2, 1, 3], - vec![1, 2, 2, 3, 1, 2], - vec![1, 3, 2, 2, 1, 2], - vec![2, 2, 1, 2, 1, 3], - vec![2, 2, 1, 3, 1, 2], // 10 - vec![2, 3, 1, 2, 1, 2], - vec![1, 1, 2, 2, 3, 2], - vec![1, 2, 2, 1, 3, 2], - vec![1, 2, 2, 2, 3, 1], - vec![1, 1, 3, 2, 2, 2], // 15 - vec![1, 2, 3, 1, 2, 2], - vec![1, 2, 3, 2, 2, 1], - vec![2, 2, 3, 2, 1, 1], - vec![2, 2, 1, 1, 3, 2], - vec![2, 2, 1, 2, 3, 1], // 20 - vec![2, 1, 3, 2, 1, 2], - vec![2, 2, 3, 1, 1, 2], - vec![3, 1, 2, 1, 3, 1], - vec![3, 1, 1, 2, 2, 2], - vec![3, 2, 1, 1, 2, 2], // 25 - vec![3, 2, 1, 2, 2, 1], - vec![3, 1, 2, 2, 1, 2], - vec![3, 2, 2, 1, 1, 2], - vec![3, 2, 2, 2, 1, 1], - vec![2, 1, 2, 1, 2, 3], // 30 - vec![2, 1, 2, 3, 2, 1], - vec![2, 3, 2, 1, 2, 1], - vec![1, 1, 1, 3, 2, 3], - vec![1, 3, 1, 1, 2, 3], - vec![1, 3, 1, 3, 2, 1], // 35 - vec![1, 1, 2, 3, 1, 3], - vec![1, 3, 2, 1, 1, 3], - vec![1, 3, 2, 3, 1, 1], - vec![2, 1, 1, 3, 1, 3], - vec![2, 3, 1, 1, 1, 3], // 40 - vec![2, 3, 1, 3, 1, 1], - vec![1, 1, 2, 1, 3, 3], - vec![1, 1, 2, 3, 3, 1], - vec![1, 3, 2, 1, 3, 1], - vec![1, 1, 3, 1, 2, 3], // 45 - vec![1, 1, 3, 3, 2, 1], - vec![1, 3, 3, 1, 2, 1], - vec![3, 1, 3, 1, 2, 1], - vec![2, 1, 1, 3, 3, 1], - vec![2, 3, 1, 1, 3, 1], // 50 - vec![2, 1, 3, 1, 1, 3], - vec![2, 1, 3, 3, 1, 1], - vec![2, 1, 3, 1, 3, 1], - vec![3, 1, 1, 1, 2, 3], - vec![3, 1, 1, 3, 2, 1], // 55 - vec![3, 3, 1, 1, 2, 1], - vec![3, 1, 2, 1, 1, 3], - vec![3, 1, 2, 3, 1, 1], - vec![3, 3, 2, 1, 1, 1], - vec![3, 1, 4, 1, 1, 1], // 60 - vec![2, 2, 1, 4, 1, 1], - vec![4, 3, 1, 1, 1, 1], - vec![1, 1, 1, 2, 2, 4], - vec![1, 1, 1, 4, 2, 2], - vec![1, 2, 1, 1, 2, 4], // 65 - vec![1, 2, 1, 4, 2, 1], - vec![1, 4, 1, 1, 2, 2], - vec![1, 4, 1, 2, 2, 1], - vec![1, 1, 2, 2, 1, 4], - vec![1, 1, 2, 4, 1, 2], // 70 - vec![1, 2, 2, 1, 1, 4], - vec![1, 2, 2, 4, 1, 1], - vec![1, 4, 2, 1, 1, 2], - vec![1, 4, 2, 2, 1, 1], - vec![2, 4, 1, 2, 1, 1], // 75 - vec![2, 2, 1, 1, 1, 4], - vec![4, 1, 3, 1, 1, 1], - vec![2, 4, 1, 1, 1, 2], - vec![1, 3, 4, 1, 1, 1], - vec![1, 1, 1, 2, 4, 2], // 80 - vec![1, 2, 1, 1, 4, 2], - vec![1, 2, 1, 2, 4, 1], - vec![1, 1, 4, 2, 1, 2], - vec![1, 2, 4, 1, 1, 2], - vec![1, 2, 4, 2, 1, 1], // 85 - vec![4, 1, 1, 2, 1, 2], - vec![4, 2, 1, 1, 1, 2], - vec![4, 2, 1, 2, 1, 1], - vec![2, 1, 2, 1, 4, 1], - vec![2, 1, 4, 1, 2, 1], // 90 - vec![4, 1, 2, 1, 2, 1], - vec![1, 1, 1, 1, 4, 3], - vec![1, 1, 1, 3, 4, 1], - vec![1, 3, 1, 1, 4, 1], - vec![1, 1, 4, 1, 1, 3], // 95 - vec![1, 1, 4, 3, 1, 1], - vec![4, 1, 1, 1, 1, 3], - vec![4, 1, 1, 3, 1, 1], - vec![1, 1, 3, 1, 4, 1], - vec![1, 1, 4, 1, 3, 1], // 100 - vec![3, 1, 1, 1, 4, 1], - vec![4, 1, 1, 1, 3, 1], - vec![2, 1, 1, 4, 1, 2], - vec![2, 1, 1, 2, 1, 4], - vec![2, 1, 1, 2, 3, 2], // 105 - vec![2, 3, 3, 1, 1, 1, 2], -]; -} +pub static CODE_PATTERNS: Lazy<[Vec; 107]> = Lazy::new(|| { + [ + vec![2, 1, 2, 2, 2, 2], // 0 + vec![2, 2, 2, 1, 2, 2], + vec![2, 2, 2, 2, 2, 1], + vec![1, 2, 1, 2, 2, 3], + vec![1, 2, 1, 3, 2, 2], + vec![1, 3, 1, 2, 2, 2], // 5 + vec![1, 2, 2, 2, 1, 3], + vec![1, 2, 2, 3, 1, 2], + vec![1, 3, 2, 2, 1, 2], + vec![2, 2, 1, 2, 1, 3], + vec![2, 2, 1, 3, 1, 2], // 10 + vec![2, 3, 1, 2, 1, 2], + vec![1, 1, 2, 2, 3, 2], + vec![1, 2, 2, 1, 3, 2], + vec![1, 2, 2, 2, 3, 1], + vec![1, 1, 3, 2, 2, 2], // 15 + vec![1, 2, 3, 1, 2, 2], + vec![1, 2, 3, 2, 2, 1], + vec![2, 2, 3, 2, 1, 1], + vec![2, 2, 1, 1, 3, 2], + vec![2, 2, 1, 2, 3, 1], // 20 + vec![2, 1, 3, 2, 1, 2], + vec![2, 2, 3, 1, 1, 2], + vec![3, 1, 2, 1, 3, 1], + vec![3, 1, 1, 2, 2, 2], + vec![3, 2, 1, 1, 2, 2], // 25 + vec![3, 2, 1, 2, 2, 1], + vec![3, 1, 2, 2, 1, 2], + vec![3, 2, 2, 1, 1, 2], + vec![3, 2, 2, 2, 1, 1], + vec![2, 1, 2, 1, 2, 3], // 30 + vec![2, 1, 2, 3, 2, 1], + vec![2, 3, 2, 1, 2, 1], + vec![1, 1, 1, 3, 2, 3], + vec![1, 3, 1, 1, 2, 3], + vec![1, 3, 1, 3, 2, 1], // 35 + vec![1, 1, 2, 3, 1, 3], + vec![1, 3, 2, 1, 1, 3], + vec![1, 3, 2, 3, 1, 1], + vec![2, 1, 1, 3, 1, 3], + vec![2, 3, 1, 1, 1, 3], // 40 + vec![2, 3, 1, 3, 1, 1], + vec![1, 1, 2, 1, 3, 3], + vec![1, 1, 2, 3, 3, 1], + vec![1, 3, 2, 1, 3, 1], + vec![1, 1, 3, 1, 2, 3], // 45 + vec![1, 1, 3, 3, 2, 1], + vec![1, 3, 3, 1, 2, 1], + vec![3, 1, 3, 1, 2, 1], + vec![2, 1, 1, 3, 3, 1], + vec![2, 3, 1, 1, 3, 1], // 50 + vec![2, 1, 3, 1, 1, 3], + vec![2, 1, 3, 3, 1, 1], + vec![2, 1, 3, 1, 3, 1], + vec![3, 1, 1, 1, 2, 3], + vec![3, 1, 1, 3, 2, 1], // 55 + vec![3, 3, 1, 1, 2, 1], + vec![3, 1, 2, 1, 1, 3], + vec![3, 1, 2, 3, 1, 1], + vec![3, 3, 2, 1, 1, 1], + vec![3, 1, 4, 1, 1, 1], // 60 + vec![2, 2, 1, 4, 1, 1], + vec![4, 3, 1, 1, 1, 1], + vec![1, 1, 1, 2, 2, 4], + vec![1, 1, 1, 4, 2, 2], + vec![1, 2, 1, 1, 2, 4], // 65 + vec![1, 2, 1, 4, 2, 1], + vec![1, 4, 1, 1, 2, 2], + vec![1, 4, 1, 2, 2, 1], + vec![1, 1, 2, 2, 1, 4], + vec![1, 1, 2, 4, 1, 2], // 70 + vec![1, 2, 2, 1, 1, 4], + vec![1, 2, 2, 4, 1, 1], + vec![1, 4, 2, 1, 1, 2], + vec![1, 4, 2, 2, 1, 1], + vec![2, 4, 1, 2, 1, 1], // 75 + vec![2, 2, 1, 1, 1, 4], + vec![4, 1, 3, 1, 1, 1], + vec![2, 4, 1, 1, 1, 2], + vec![1, 3, 4, 1, 1, 1], + vec![1, 1, 1, 2, 4, 2], // 80 + vec![1, 2, 1, 1, 4, 2], + vec![1, 2, 1, 2, 4, 1], + vec![1, 1, 4, 2, 1, 2], + vec![1, 2, 4, 1, 1, 2], + vec![1, 2, 4, 2, 1, 1], // 85 + vec![4, 1, 1, 2, 1, 2], + vec![4, 2, 1, 1, 1, 2], + vec![4, 2, 1, 2, 1, 1], + vec![2, 1, 2, 1, 4, 1], + vec![2, 1, 4, 1, 2, 1], // 90 + vec![4, 1, 2, 1, 2, 1], + vec![1, 1, 1, 1, 4, 3], + vec![1, 1, 1, 3, 4, 1], + vec![1, 3, 1, 1, 4, 1], + vec![1, 1, 4, 1, 1, 3], // 95 + vec![1, 1, 4, 3, 1, 1], + vec![4, 1, 1, 1, 1, 3], + vec![4, 1, 1, 3, 1, 1], + vec![1, 1, 3, 1, 4, 1], + vec![1, 1, 4, 1, 3, 1], // 100 + vec![3, 1, 1, 1, 4, 1], + vec![4, 1, 1, 1, 3, 1], + vec![2, 1, 1, 4, 1, 2], + vec![2, 1, 1, 2, 1, 4], + vec![2, 1, 1, 2, 3, 2], // 105 + vec![2, 3, 3, 1, 1, 1, 2], + ] +}); const MAX_AVG_VARIANCE: f32 = 0.25; const MAX_INDIVIDUAL_VARIANCE: f32 = 0.7; diff --git a/src/oned/code_128_writer_test_tase.rs b/src/oned/code_128_writer_test_tase.rs index 6fc671a..19b19f8 100644 --- a/src/oned/code_128_writer_test_tase.rs +++ b/src/oned/code_128_writer_test_tase.rs @@ -34,7 +34,7 @@ const LF: &str = "10000110010"; use std::collections::HashMap; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::{ common::{BitMatrix, BitMatrixTestCase}, @@ -43,9 +43,8 @@ use crate::{ }; use super::Code128Writer; -lazy_static! { - static ref WRITER: Code128Writer = Code128Writer::default(); -} + +static WRITER: Lazy = Lazy::new(|| Code128Writer::default()); #[test] fn testEncodeWithFunc3() { diff --git a/src/oned/one_d_code_writer.rs b/src/oned/one_d_code_writer.rs index 9cf9fcc..48c7097 100644 --- a/src/oned/one_d_code_writer.rs +++ b/src/oned/one_d_code_writer.rs @@ -20,12 +20,10 @@ use crate::{ common::BitMatrix, BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer, }; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use regex::Regex; -lazy_static! { - pub static ref NUMERIC: Regex = Regex::new("[0-9]+").unwrap(); -} +pub static NUMERIC: Lazy = Lazy::new(|| Regex::new("[0-9]+").unwrap()); /** *

Encapsulates functionality and implementation that is common to one-dimensional barcodes.

diff --git a/src/oned/rss/expanded/binary_util.rs b/src/oned/rss/expanded/binary_util.rs index 6cb93a8..f163cda 100644 --- a/src/oned/rss/expanded/binary_util.rs +++ b/src/oned/rss/expanded/binary_util.rs @@ -27,16 +27,14 @@ /** * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) */ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use regex::Regex; use crate::{common::BitArray, Exceptions}; -lazy_static! { - static ref ONE: Regex = Regex::new("1").unwrap(); - static ref ZERO: Regex = Regex::new("0").unwrap(); - static ref SPACE: Regex = Regex::new(" ").unwrap(); -} +static ONE: Lazy = Lazy::new(|| Regex::new("1").unwrap()); +static ZERO: Lazy = Lazy::new(|| Regex::new("0").unwrap()); +static SPACE: Lazy = Lazy::new(|| Regex::new(" ").unwrap()); /* * Constructs a BitArray from a String like the one returned from BitArray.toString() diff --git a/src/oned/rss/expanded/decoders/field_parser.rs b/src/oned/rss/expanded/decoders/field_parser.rs index 8e49f71..70c85a9 100644 --- a/src/oned/rss/expanded/decoders/field_parser.rs +++ b/src/oned/rss/expanded/decoders/field_parser.rs @@ -31,115 +31,111 @@ use std::collections::HashMap; use crate::Exceptions; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { +static TWO_DIGIT_DATA_LENGTH: Lazy> = Lazy::new(|| { + let mut hm = HashMap::new(); + hm.insert("00".to_owned(), DataLength::fixed(18)); + hm.insert("01".to_owned(), DataLength::fixed(14)); + hm.insert("02".to_owned(), DataLength::fixed(14)); + hm.insert("10".to_owned(), DataLength::variable(20)); + hm.insert("11".to_owned(), DataLength::fixed(6)); + hm.insert("12".to_owned(), DataLength::fixed(6)); + hm.insert("13".to_owned(), DataLength::fixed(6)); + hm.insert("15".to_owned(), DataLength::fixed(6)); + hm.insert("17".to_owned(), DataLength::fixed(6)); + hm.insert("20".to_owned(), DataLength::fixed(2)); + hm.insert("21".to_owned(), DataLength::variable(20)); + hm.insert("22".to_owned(), DataLength::variable(29)); + hm.insert("30".to_owned(), DataLength::variable(8)); + hm.insert("37".to_owned(), DataLength::variable(8)); + //internal company codes + for i in 90..=99 { + // for (int i = 90; i <= 99; i++) { + hm.insert(i.to_string(), DataLength::variable(30)); + } + hm +}); - static ref TWO_DIGIT_DATA_LENGTH : HashMap = { - let mut hm = HashMap::new(); - hm.insert("00".to_owned(), DataLength::fixed(18)); - hm.insert("01".to_owned(), DataLength::fixed(14)); - hm.insert("02".to_owned(), DataLength::fixed(14)); - hm.insert("10".to_owned(), DataLength::variable(20)); - hm.insert("11".to_owned(), DataLength::fixed(6)); - hm.insert("12".to_owned(), DataLength::fixed(6)); - hm.insert("13".to_owned(), DataLength::fixed(6)); - hm.insert("15".to_owned(), DataLength::fixed(6)); - hm.insert("17".to_owned(), DataLength::fixed(6)); - hm.insert("20".to_owned(), DataLength::fixed(2)); - hm.insert("21".to_owned(), DataLength::variable(20)); - hm.insert("22".to_owned(), DataLength::variable(29)); - hm.insert("30".to_owned(), DataLength::variable(8)); - hm.insert("37".to_owned(), DataLength::variable(8)); - //internal company codes - for i in 90..=99 { - // for (int i = 90; i <= 99; i++) { - hm.insert(i.to_string(), DataLength::variable(30)); - } - hm - }; +static THREE_DIGIT_DATA_LENGTH: Lazy> = Lazy::new(|| { + let mut hm = HashMap::new(); + hm.insert("240".to_owned(), DataLength::variable(30)); + hm.insert("241".to_owned(), DataLength::variable(30)); + hm.insert("242".to_owned(), DataLength::variable(6)); + hm.insert("250".to_owned(), DataLength::variable(30)); + hm.insert("251".to_owned(), DataLength::variable(30)); + hm.insert("253".to_owned(), DataLength::variable(17)); + hm.insert("254".to_owned(), DataLength::variable(20)); + hm.insert("400".to_owned(), DataLength::variable(30)); + hm.insert("401".to_owned(), DataLength::variable(30)); + hm.insert("402".to_owned(), DataLength::fixed(17)); + hm.insert("403".to_owned(), DataLength::variable(30)); + hm.insert("410".to_owned(), DataLength::fixed(13)); + hm.insert("411".to_owned(), DataLength::fixed(13)); + hm.insert("412".to_owned(), DataLength::fixed(13)); + hm.insert("413".to_owned(), DataLength::fixed(13)); + hm.insert("414".to_owned(), DataLength::fixed(13)); + hm.insert("420".to_owned(), DataLength::variable(20)); + hm.insert("421".to_owned(), DataLength::variable(15)); + hm.insert("422".to_owned(), DataLength::fixed(3)); + hm.insert("423".to_owned(), DataLength::variable(15)); + hm.insert("424".to_owned(), DataLength::fixed(3)); + hm.insert("425".to_owned(), DataLength::fixed(3)); + hm.insert("426".to_owned(), DataLength::fixed(3)); - static ref THREE_DIGIT_DATA_LENGTH : HashMap= - { - let mut hm = HashMap::new(); - hm.insert("240".to_owned(), DataLength::variable(30)); - hm.insert("241".to_owned(), DataLength::variable(30)); - hm.insert("242".to_owned(), DataLength::variable(6)); - hm.insert("250".to_owned(), DataLength::variable(30)); - hm.insert("251".to_owned(), DataLength::variable(30)); - hm.insert("253".to_owned(), DataLength::variable(17)); - hm.insert("254".to_owned(), DataLength::variable(20)); - hm.insert("400".to_owned(), DataLength::variable(30)); - hm.insert("401".to_owned(), DataLength::variable(30)); - hm.insert("402".to_owned(), DataLength::fixed(17)); - hm.insert("403".to_owned(), DataLength::variable(30)); - hm.insert("410".to_owned(), DataLength::fixed(13)); - hm.insert("411".to_owned(), DataLength::fixed(13)); - hm.insert("412".to_owned(), DataLength::fixed(13)); - hm.insert("413".to_owned(), DataLength::fixed(13)); - hm.insert("414".to_owned(), DataLength::fixed(13)); - hm.insert("420".to_owned(), DataLength::variable(20)); - hm.insert("421".to_owned(), DataLength::variable(15)); - hm.insert("422".to_owned(), DataLength::fixed(3)); - hm.insert("423".to_owned(), DataLength::variable(15)); - hm.insert("424".to_owned(), DataLength::fixed(3)); - hm.insert("425".to_owned(), DataLength::fixed(3)); - hm.insert("426".to_owned(), DataLength::fixed(3)); + hm +}); - hm - }; +static THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH: Lazy> = Lazy::new(|| { + let mut hm = HashMap::new(); + for i in 310..=316 { + // for (int i = 310; i <= 316; i++) { + hm.insert(i.to_string(), DataLength::fixed(6)); + } + for i in 320..=336 { + // for (int i = 320; i <= 336; i++) { + hm.insert(i.to_string(), DataLength::fixed(6)); + } + for i in 340..=357 { + // for (int i = 340; i <= 357; i++) { + hm.insert(i.to_string(), DataLength::fixed(6)); + } + for i in 360..=369 { + // for (int i = 360; i <= 369; i++) { + hm.insert(i.to_string(), DataLength::fixed(6)); + } + hm.insert("390".to_owned(), DataLength::variable(15)); + hm.insert("391".to_owned(), DataLength::variable(18)); + hm.insert("392".to_owned(), DataLength::variable(15)); + hm.insert("393".to_owned(), DataLength::variable(18)); + hm.insert("703".to_owned(), DataLength::variable(30)); - static ref THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH:HashMap = { - let mut hm = HashMap::new(); - for i in 310..=316 { - // for (int i = 310; i <= 316; i++) { - hm.insert(i.to_string(), DataLength::fixed(6)); - } - for i in 320..=336 { - // for (int i = 320; i <= 336; i++) { - hm.insert(i.to_string(), DataLength::fixed(6)); - } - for i in 340..=357 { - // for (int i = 340; i <= 357; i++) { - hm.insert(i.to_string(), DataLength::fixed(6)); - } - for i in 360..=369 { - // for (int i = 360; i <= 369; i++) { - hm.insert(i.to_string(), DataLength::fixed(6)); - } - hm.insert("390".to_owned(), DataLength::variable(15)); - hm.insert("391".to_owned(), DataLength::variable(18)); - hm.insert("392".to_owned(), DataLength::variable(15)); - hm.insert("393".to_owned(), DataLength::variable(18)); - hm.insert("703".to_owned(), DataLength::variable(30)); + hm +}); - hm - }; +static FOUR_DIGIT_DATA_LENGTH: Lazy> = Lazy::new(|| { + let mut hm = HashMap::new(); + hm.insert("7001".to_owned(), DataLength::fixed(13)); + hm.insert("7002".to_owned(), DataLength::variable(30)); + hm.insert("7003".to_owned(), DataLength::fixed(10)); + hm.insert("8001".to_owned(), DataLength::fixed(14)); + hm.insert("8002".to_owned(), DataLength::variable(20)); + hm.insert("8003".to_owned(), DataLength::variable(30)); + hm.insert("8004".to_owned(), DataLength::variable(30)); + hm.insert("8005".to_owned(), DataLength::fixed(6)); + hm.insert("8006".to_owned(), DataLength::fixed(18)); + hm.insert("8007".to_owned(), DataLength::variable(30)); + hm.insert("8008".to_owned(), DataLength::variable(12)); + hm.insert("8018".to_owned(), DataLength::fixed(18)); + hm.insert("8020".to_owned(), DataLength::variable(25)); + hm.insert("8100".to_owned(), DataLength::fixed(6)); + hm.insert("8101".to_owned(), DataLength::fixed(10)); + hm.insert("8102".to_owned(), DataLength::fixed(2)); + hm.insert("8110".to_owned(), DataLength::variable(70)); + hm.insert("8200".to_owned(), DataLength::variable(70)); - static ref FOUR_DIGIT_DATA_LENGTH : HashMap={ - let mut hm = HashMap::new(); - hm.insert("7001".to_owned(), DataLength::fixed(13)); - hm.insert("7002".to_owned(), DataLength::variable(30)); - hm.insert("7003".to_owned(), DataLength::fixed(10)); - hm.insert("8001".to_owned(), DataLength::fixed(14)); - hm.insert("8002".to_owned(), DataLength::variable(20)); - hm.insert("8003".to_owned(), DataLength::variable(30)); - hm.insert("8004".to_owned(), DataLength::variable(30)); - hm.insert("8005".to_owned(), DataLength::fixed(6)); - hm.insert("8006".to_owned(), DataLength::fixed(18)); - hm.insert("8007".to_owned(), DataLength::variable(30)); - hm.insert("8008".to_owned(), DataLength::variable(12)); - hm.insert("8018".to_owned(), DataLength::fixed(18)); - hm.insert("8020".to_owned(), DataLength::variable(25)); - hm.insert("8100".to_owned(), DataLength::fixed(6)); - hm.insert("8101".to_owned(), DataLength::fixed(10)); - hm.insert("8102".to_owned(), DataLength::fixed(2)); - hm.insert("8110".to_owned(), DataLength::variable(70)); - hm.insert("8200".to_owned(), DataLength::variable(70)); - - hm - }; -} + hm +}); pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result { if rawInformation.is_empty() { diff --git a/src/oned/rss/expanded/rss_expanded_reader.rs b/src/oned/rss/expanded/rss_expanded_reader.rs index 306753f..c731938 100644 --- a/src/oned/rss/expanded/rss_expanded_reader.rs +++ b/src/oned/rss/expanded/rss_expanded_reader.rs @@ -40,6 +40,8 @@ use crate::{ RXingResultMetadataType, RXingResultMetadataValue, Reader, }; +use once_cell::sync::Lazy; + use super::{bit_array_builder, decoders::abstract_expanded_decoder, ExpandedPair, ExpandedRow}; const FINDER_PAT_A: u32 = 0; @@ -49,9 +51,8 @@ const FINDER_PAT_D: u32 = 3; const FINDER_PAT_E: u32 = 4; const FINDER_PAT_F: u32 = 5; -use lazy_static::lazy_static; -lazy_static! { - static ref FINDER_PATTERN_SEQUENCES: Vec> = vec![ +static FINDER_PATTERN_SEQUENCES: Lazy>> = Lazy::new(|| { + vec![ vec![FINDER_PAT_A, FINDER_PAT_A], vec![FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B], vec![FINDER_PAT_A, FINDER_PAT_C, FINDER_PAT_B, FINDER_PAT_D], @@ -60,7 +61,7 @@ lazy_static! { FINDER_PAT_E, FINDER_PAT_B, FINDER_PAT_D, - FINDER_PAT_C + FINDER_PAT_C, ], vec![ FINDER_PAT_A, @@ -68,7 +69,7 @@ lazy_static! { FINDER_PAT_B, FINDER_PAT_D, FINDER_PAT_D, - FINDER_PAT_F + FINDER_PAT_F, ], vec![ FINDER_PAT_A, @@ -77,7 +78,7 @@ lazy_static! { FINDER_PAT_D, FINDER_PAT_E, FINDER_PAT_F, - FINDER_PAT_F + FINDER_PAT_F, ], vec![ FINDER_PAT_A, @@ -87,7 +88,7 @@ lazy_static! { FINDER_PAT_C, FINDER_PAT_C, FINDER_PAT_D, - FINDER_PAT_D + FINDER_PAT_D, ], vec![ FINDER_PAT_A, @@ -98,7 +99,7 @@ lazy_static! { FINDER_PAT_C, FINDER_PAT_D, FINDER_PAT_E, - FINDER_PAT_E + FINDER_PAT_E, ], vec![ FINDER_PAT_A, @@ -110,7 +111,7 @@ lazy_static! { FINDER_PAT_D, FINDER_PAT_E, FINDER_PAT_F, - FINDER_PAT_F + FINDER_PAT_F, ], vec![ FINDER_PAT_A, @@ -123,10 +124,10 @@ lazy_static! { FINDER_PAT_E, FINDER_PAT_E, FINDER_PAT_F, - FINDER_PAT_F + FINDER_PAT_F, ], - ]; -} + ] +}); /** * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) diff --git a/src/oned/upc_ean_reader.rs b/src/oned/upc_ean_reader.rs index 478f5ab..4c7ee13 100644 --- a/src/oned/upc_ean_reader.rs +++ b/src/oned/upc_ean_reader.rs @@ -21,14 +21,12 @@ use crate::{ use super::{one_d_reader, EANManufacturerOrgSupport, OneDReader, UPCEANExtensionSupport}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - pub static ref EAN_MANUFACTURER_SUPPORT: EANManufacturerOrgSupport = - EANManufacturerOrgSupport::default(); - pub static ref UPC_EAN_EXTENSION_SUPPORT: UPCEANExtensionSupport = - UPCEANExtensionSupport::default(); -} +pub static EAN_MANUFACTURER_SUPPORT: Lazy = + Lazy::new(|| EANManufacturerOrgSupport::default()); +pub static UPC_EAN_EXTENSION_SUPPORT: Lazy = + Lazy::new(|| UPCEANExtensionSupport::default()); // These two values are critical for determining how permissive the decoding will be. // We've arrived at these values through a lot of trial and error. Setting them any higher diff --git a/src/pdf417/decoder/decoded_bit_stream_parser.rs b/src/pdf417/decoder/decoded_bit_stream_parser.rs index b64518d..e14dac2 100644 --- a/src/pdf417/decoder/decoded_bit_stream_parser.rs +++ b/src/pdf417/decoder/decoded_bit_stream_parser.rs @@ -80,30 +80,28 @@ const MIXED_CHARS: [char; 25] = [ '$', '/', '+', '%', '*', '=', '^', ]; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - /** - * Table containing values for the exponent of 900. - * This is used in the numeric compaction decode algorithm. - */ - static ref EXP900 : Vec = { - const EXP_LEN :usize= 16; +/** + * Table containing values for the exponent of 900. + * This is used in the numeric compaction decode algorithm. + */ +static EXP900: Lazy> = Lazy::new(|| { + const EXP_LEN: usize = 16; let mut exp900 = Vec::with_capacity(EXP_LEN); //[0;16]; exp900.push(ToBigUint::to_biguint(&1).unwrap()); let nineHundred = ToBigUint::to_biguint(&900).unwrap(); exp900.push(nineHundred); let mut i = 2; while i < EXP_LEN { - // for (int i = 2; i < EXP900.length; i++) { - exp900.push( &exp900[i - 1] * 900_u32); + // for (int i = 2; i < EXP900.length; i++) { + exp900.push(&exp900[i - 1] * 900_u32); - i+=1; + i += 1; } exp900 - }; -} +}); // /** // * Table containing values for the exponent of 900. diff --git a/src/pdf417/decoder/ec/error_correction.rs b/src/pdf417/decoder/ec/error_correction.rs index 0e67071..791fe22 100644 --- a/src/pdf417/decoder/ec/error_correction.rs +++ b/src/pdf417/decoder/ec/error_correction.rs @@ -23,12 +23,10 @@ use crate::{ use super::ModulusPoly; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - // static ref PDF417_GF : Rc<&ModulusGF> = Rc::new(&ModulusGF::new(NUMBER_OF_CODEWORDS, 3)); - static ref FLD_INTERIOR : ModulusGF = ModulusGF::new(NUMBER_OF_CODEWORDS, 3); -} +// static ref PDF417_GF : Rc<&ModulusGF> = Rc::new(&ModulusGF::new(NUMBER_OF_CODEWORDS, 3)); +static FLD_INTERIOR: Lazy = Lazy::new(|| ModulusGF::new(NUMBER_OF_CODEWORDS, 3)); /** *

PDF417 error correction implementation.

diff --git a/src/pdf417/encoder/pdf_417_error_correction.rs b/src/pdf417/encoder/pdf_417_error_correction.rs index 813ba4f..2d80a1b 100644 --- a/src/pdf417/encoder/pdf_417_error_correction.rs +++ b/src/pdf417/encoder/pdf_417_error_correction.rs @@ -22,107 +22,93 @@ * PDF417 error correction code following the algorithm described in ISO/IEC 15438:2001(E) in * chapter 4.10. */ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::Exceptions; -lazy_static! { - /** - * Tables of coefficients for calculating error correction words - * (see annex F, ISO/IEC 15438:2001(E)) - */ - static ref EC_COEFFICIENTS : [Vec;9] = [ - vec![27, 917], - vec![522, 568, 723, 809], - vec![237, 308, 436, 284, 646, 653, 428, 379], - vec![274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, - 42, 176, 65], - vec![361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, - 284, 193, 517, 273, 494, 263, 147, 593, 800, 571, 320, 803, - 133, 231, 390, 685, 330, 63, 410], - vec![539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, - 877, 381, 612, 723, 476, 462, 172, 430, 609, 858, 822, 543, - 376, 511, 400, 672, 762, 283, 184, 440, 35, 519, 31, 460, - 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, 648, - 733, 717, 83, 404, 97, 280, 771, 840, 629, 4, 381, 843, - 623, 264, 543], - vec![521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, - 925, 749, 415, 822, 93, 217, 208, 928, 244, 583, 620, 246, - 148, 447, 631, 292, 908, 490, 704, 516, 258, 457, 907, 594, - 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, 193, - 219, 129, 186, 236, 287, 192, 775, 278, 173, 40, 379, 712, - 463, 646, 776, 171, 491, 297, 763, 156, 732, 95, 270, 447, - 90, 507, 48, 228, 821, 808, 898, 784, 663, 627, 378, 382, - 262, 380, 602, 754, 336, 89, 614, 87, 432, 670, 616, 157, - 374, 242, 726, 600, 269, 375, 898, 845, 454, 354, 130, 814, - 587, 804, 34, 211, 330, 539, 297, 827, 865, 37, 517, 834, - 315, 550, 86, 801, 4, 108, 539], - vec![524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, - 786, 138, 720, 858, 194, 311, 913, 275, 190, 375, 850, 438, - 733, 194, 280, 201, 280, 828, 757, 710, 814, 919, 89, 68, - 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, 439, - 418, 592, 668, 353, 859, 370, 694, 325, 240, 216, 257, 284, - 549, 209, 884, 315, 70, 329, 793, 490, 274, 877, 162, 749, - 812, 684, 461, 334, 376, 849, 521, 307, 291, 803, 712, 19, - 358, 399, 908, 103, 511, 51, 8, 517, 225, 289, 470, 637, - 731, 66, 255, 917, 269, 463, 830, 730, 433, 848, 585, 136, - 538, 906, 90, 2, 290, 743, 199, 655, 903, 329, 49, 802, - 580, 355, 588, 188, 462, 10, 134, 628, 320, 479, 130, 739, - 71, 263, 318, 374, 601, 192, 605, 142, 673, 687, 234, 722, - 384, 177, 752, 607, 640, 455, 193, 689, 707, 805, 641, 48, - 60, 732, 621, 895, 544, 261, 852, 655, 309, 697, 755, 756, - 60, 231, 773, 434, 421, 726, 528, 503, 118, 49, 795, 32, - 144, 500, 238, 836, 394, 280, 566, 319, 9, 647, 550, 73, - 914, 342, 126, 32, 681, 331, 792, 620, 60, 609, 441, 180, - 791, 893, 754, 605, 383, 228, 749, 760, 213, 54, 297, 134, - 54, 834, 299, 922, 191, 910, 532, 609, 829, 189, 20, 167, - 29, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, 404, - 251, 688, 95, 497, 555, 642, 543, 307, 159, 924, 558, 648, - 55, 497, 10], - vec![352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, - 380, 350, 492, 197, 265, 920, 155, 914, 299, 229, 643, 294, - 871, 306, 88, 87, 193, 352, 781, 846, 75, 327, 520, 435, - 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, 539, - 781, 408, 390, 644, 102, 476, 499, 290, 632, 545, 37, 858, - 916, 552, 41, 542, 289, 122, 272, 383, 800, 485, 98, 752, - 472, 761, 107, 784, 860, 658, 741, 290, 204, 681, 407, 855, - 85, 99, 62, 482, 180, 20, 297, 451, 593, 913, 142, 808, - 684, 287, 536, 561, 76, 653, 899, 729, 567, 744, 390, 513, - 192, 516, 258, 240, 518, 794, 395, 768, 848, 51, 610, 384, - 168, 190, 826, 328, 596, 786, 303, 570, 381, 415, 641, 156, - 237, 151, 429, 531, 207, 676, 710, 89, 168, 304, 402, 40, - 708, 575, 162, 864, 229, 65, 861, 841, 512, 164, 477, 221, - 92, 358, 785, 288, 357, 850, 836, 827, 736, 707, 94, 8, - 494, 114, 521, 2, 499, 851, 543, 152, 729, 771, 95, 248, - 361, 578, 323, 856, 797, 289, 51, 684, 466, 533, 820, 669, - 45, 902, 452, 167, 342, 244, 173, 35, 463, 651, 51, 699, - 591, 452, 578, 37, 124, 298, 332, 552, 43, 427, 119, 662, - 777, 475, 850, 764, 364, 578, 911, 283, 711, 472, 420, 245, - 288, 594, 394, 511, 327, 589, 777, 699, 688, 43, 408, 842, - 383, 721, 521, 560, 644, 714, 559, 62, 145, 873, 663, 713, - 159, 672, 729, 624, 59, 193, 417, 158, 209, 563, 564, 343, - 693, 109, 608, 563, 365, 181, 772, 677, 310, 248, 353, 708, - 410, 579, 870, 617, 841, 632, 860, 289, 536, 35, 777, 618, - 586, 424, 833, 77, 597, 346, 269, 757, 632, 695, 751, 331, - 247, 184, 45, 787, 680, 18, 66, 407, 369, 54, 492, 228, - 613, 830, 922, 437, 519, 644, 905, 789, 420, 305, 441, 207, - 300, 892, 827, 141, 537, 381, 662, 513, 56, 252, 341, 242, - 797, 838, 837, 720, 224, 307, 631, 61, 87, 560, 310, 756, - 665, 397, 808, 851, 309, 473, 795, 378, 31, 647, 915, 459, - 806, 590, 731, 425, 216, 548, 249, 321, 881, 699, 535, 673, - 782, 210, 815, 905, 303, 843, 922, 281, 73, 469, 791, 660, - 162, 498, 308, 155, 422, 907, 817, 187, 62, 16, 425, 535, - 336, 286, 437, 375, 273, 610, 296, 183, 923, 116, 667, 751, - 353, 62, 366, 691, 379, 687, 842, 37, 357, 720, 742, 330, - 5, 39, 923, 311, 424, 242, 749, 321, 54, 669, 316, 342, - 299, 534, 105, 667, 488, 640, 672, 576, 540, 316, 486, 721, - 610, 46, 656, 447, 171, 616, 464, 190, 531, 297, 321, 762, - 752, 533, 175, 134, 14, 381, 433, 717, 45, 111, 20, 596, - 284, 736, 138, 646, 411, 877, 669, 141, 919, 45, 780, 407, - 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, 768, - 223, 849, 647, 63, 310, 863, 251, 366, 304, 282, 738, 675, - 410, 389, 244, 31, 121, 303, 263]]; -} +/** + * Tables of coefficients for calculating error correction words + * (see annex F, ISO/IEC 15438:2001(E)) + */ +static EC_COEFFICIENTS: Lazy<[Vec; 9]> = Lazy::new(|| { + [ + vec![27, 917], + vec![522, 568, 723, 809], + vec![237, 308, 436, 284, 646, 653, 428, 379], + vec![ + 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65, + ], + vec![ + 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, 273, + 494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410, + ], + vec![ + 539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, 877, 381, 612, 723, 476, + 462, 172, 430, 609, 858, 822, 543, 376, 511, 400, 672, 762, 283, 184, 440, 35, 519, 31, + 460, 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, 648, 733, 717, 83, 404, 97, + 280, 771, 840, 629, 4, 381, 843, 623, 264, 543, + ], + vec![ + 521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 925, 749, 415, 822, 93, + 217, 208, 928, 244, 583, 620, 246, 148, 447, 631, 292, 908, 490, 704, 516, 258, 457, + 907, 594, 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, 193, 219, 129, 186, + 236, 287, 192, 775, 278, 173, 40, 379, 712, 463, 646, 776, 171, 491, 297, 763, 156, + 732, 95, 270, 447, 90, 507, 48, 228, 821, 808, 898, 784, 663, 627, 378, 382, 262, 380, + 602, 754, 336, 89, 614, 87, 432, 670, 616, 157, 374, 242, 726, 600, 269, 375, 898, 845, + 454, 354, 130, 814, 587, 804, 34, 211, 330, 539, 297, 827, 865, 37, 517, 834, 315, 550, + 86, 801, 4, 108, 539, + ], + vec![ + 524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, 786, 138, 720, 858, 194, + 311, 913, 275, 190, 375, 850, 438, 733, 194, 280, 201, 280, 828, 757, 710, 814, 919, + 89, 68, 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, 439, 418, 592, 668, 353, + 859, 370, 694, 325, 240, 216, 257, 284, 549, 209, 884, 315, 70, 329, 793, 490, 274, + 877, 162, 749, 812, 684, 461, 334, 376, 849, 521, 307, 291, 803, 712, 19, 358, 399, + 908, 103, 511, 51, 8, 517, 225, 289, 470, 637, 731, 66, 255, 917, 269, 463, 830, 730, + 433, 848, 585, 136, 538, 906, 90, 2, 290, 743, 199, 655, 903, 329, 49, 802, 580, 355, + 588, 188, 462, 10, 134, 628, 320, 479, 130, 739, 71, 263, 318, 374, 601, 192, 605, 142, + 673, 687, 234, 722, 384, 177, 752, 607, 640, 455, 193, 689, 707, 805, 641, 48, 60, 732, + 621, 895, 544, 261, 852, 655, 309, 697, 755, 756, 60, 231, 773, 434, 421, 726, 528, + 503, 118, 49, 795, 32, 144, 500, 238, 836, 394, 280, 566, 319, 9, 647, 550, 73, 914, + 342, 126, 32, 681, 331, 792, 620, 60, 609, 441, 180, 791, 893, 754, 605, 383, 228, 749, + 760, 213, 54, 297, 134, 54, 834, 299, 922, 191, 910, 532, 609, 829, 189, 20, 167, 29, + 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, 404, 251, 688, 95, 497, 555, 642, 543, + 307, 159, 924, 558, 648, 55, 497, 10, + ], + vec![ + 352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 380, 350, 492, 197, 265, + 920, 155, 914, 299, 229, 643, 294, 871, 306, 88, 87, 193, 352, 781, 846, 75, 327, 520, + 435, 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, 539, 781, 408, 390, 644, + 102, 476, 499, 290, 632, 545, 37, 858, 916, 552, 41, 542, 289, 122, 272, 383, 800, 485, + 98, 752, 472, 761, 107, 784, 860, 658, 741, 290, 204, 681, 407, 855, 85, 99, 62, 482, + 180, 20, 297, 451, 593, 913, 142, 808, 684, 287, 536, 561, 76, 653, 899, 729, 567, 744, + 390, 513, 192, 516, 258, 240, 518, 794, 395, 768, 848, 51, 610, 384, 168, 190, 826, + 328, 596, 786, 303, 570, 381, 415, 641, 156, 237, 151, 429, 531, 207, 676, 710, 89, + 168, 304, 402, 40, 708, 575, 162, 864, 229, 65, 861, 841, 512, 164, 477, 221, 92, 358, + 785, 288, 357, 850, 836, 827, 736, 707, 94, 8, 494, 114, 521, 2, 499, 851, 543, 152, + 729, 771, 95, 248, 361, 578, 323, 856, 797, 289, 51, 684, 466, 533, 820, 669, 45, 902, + 452, 167, 342, 244, 173, 35, 463, 651, 51, 699, 591, 452, 578, 37, 124, 298, 332, 552, + 43, 427, 119, 662, 777, 475, 850, 764, 364, 578, 911, 283, 711, 472, 420, 245, 288, + 594, 394, 511, 327, 589, 777, 699, 688, 43, 408, 842, 383, 721, 521, 560, 644, 714, + 559, 62, 145, 873, 663, 713, 159, 672, 729, 624, 59, 193, 417, 158, 209, 563, 564, 343, + 693, 109, 608, 563, 365, 181, 772, 677, 310, 248, 353, 708, 410, 579, 870, 617, 841, + 632, 860, 289, 536, 35, 777, 618, 586, 424, 833, 77, 597, 346, 269, 757, 632, 695, 751, + 331, 247, 184, 45, 787, 680, 18, 66, 407, 369, 54, 492, 228, 613, 830, 922, 437, 519, + 644, 905, 789, 420, 305, 441, 207, 300, 892, 827, 141, 537, 381, 662, 513, 56, 252, + 341, 242, 797, 838, 837, 720, 224, 307, 631, 61, 87, 560, 310, 756, 665, 397, 808, 851, + 309, 473, 795, 378, 31, 647, 915, 459, 806, 590, 731, 425, 216, 548, 249, 321, 881, + 699, 535, 673, 782, 210, 815, 905, 303, 843, 922, 281, 73, 469, 791, 660, 162, 498, + 308, 155, 422, 907, 817, 187, 62, 16, 425, 535, 336, 286, 437, 375, 273, 610, 296, 183, + 923, 116, 667, 751, 353, 62, 366, 691, 379, 687, 842, 37, 357, 720, 742, 330, 5, 39, + 923, 311, 424, 242, 749, 321, 54, 669, 316, 342, 299, 534, 105, 667, 488, 640, 672, + 576, 540, 316, 486, 721, 610, 46, 656, 447, 171, 616, 464, 190, 531, 297, 321, 762, + 752, 533, 175, 134, 14, 381, 433, 717, 45, 111, 20, 596, 284, 736, 138, 646, 411, 877, + 669, 141, 919, 45, 780, 407, 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, + 768, 223, 849, 647, 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, + 303, 263, + ], + ] +}); /** * Determines the number of error correction codewords for a specified error correction diff --git a/src/qrcode/decoder/decoder.rs b/src/qrcode/decoder/decoder.rs index 26c14b2..0df4a3b 100644 --- a/src/qrcode/decoder/decoder.rs +++ b/src/qrcode/decoder/decoder.rs @@ -22,7 +22,7 @@ use std::{collections::HashMap, rc::Rc}; * * @author Sean Owen */ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::{ common::{ @@ -34,10 +34,12 @@ use crate::{ use super::{decoded_bit_stream_parser, BitMatrixParser, DataBlock, QRCodeDecoderMetaData}; -lazy_static! { - //rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256); - static ref RS_DECODER : ReedSolomonDecoder = ReedSolomonDecoder::new(get_predefined_genericgf(PredefinedGenericGF::QrCodeField256)); -} +//rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256); +static RS_DECODER: Lazy = Lazy::new(|| { + ReedSolomonDecoder::new(get_predefined_genericgf( + PredefinedGenericGF::QrCodeField256, + )) +}); pub fn decode_bool_array(image: &Vec>) -> Result { decode_bool_array_with_hints(image, &HashMap::new()) diff --git a/src/qrcode/decoder/version.rs b/src/qrcode/decoder/version.rs index f94cc42..b833909 100755 --- a/src/qrcode/decoder/version.rs +++ b/src/qrcode/decoder/version.rs @@ -20,13 +20,11 @@ use crate::{common::BitMatrix, Exceptions}; use super::{ErrorCorrectionLevel, FormatInformation}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; pub type VersionRef = &'static Version; -lazy_static! { - static ref VERSIONS: Vec = Version::buildVersions(); -} +static VERSIONS: Lazy> = Lazy::new(|| Version::buildVersions()); /** * See ISO 18004:2006 Annex D. diff --git a/src/qrcode/encoder/EncoderTestCase.rs b/src/qrcode/encoder/EncoderTestCase.rs index d34c162..5968ae2 100644 --- a/src/qrcode/encoder/EncoderTestCase.rs +++ b/src/qrcode/encoder/EncoderTestCase.rs @@ -25,14 +25,12 @@ use crate::{ EncodeHintType, EncodeHintValue, }; use encoding::EncodingRef; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use super::QRCode; -lazy_static! { - static ref SHIFT_JIS_CHARSET: EncodingRef = - encoding::label::encoding_from_whatwg_label("SJIS").unwrap(); -} +static SHIFT_JIS_CHARSET: Lazy = + Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap()); /** * @author satorux@google.com (Satoru Takabayashi) - creator diff --git a/src/qrcode/encoder/encoder.rs b/src/qrcode/encoder/encoder.rs index 3ec4b46..8b63d7e 100644 --- a/src/qrcode/encoder/encoder.rs +++ b/src/qrcode/encoder/encoder.rs @@ -21,7 +21,7 @@ use std::collections::HashMap; use encoding::EncodingRef; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use unicode_segmentation::UnicodeSegmentation; use crate::{ @@ -35,10 +35,8 @@ use crate::{ use super::{mask_util, matrix_util, BlockPair, ByteMatrix, MinimalEncoder, QRCode}; -lazy_static! { - static ref SHIFT_JIS_CHARSET: EncodingRef = - encoding::label::encoding_from_whatwg_label("SJIS").unwrap(); -} +static SHIFT_JIS_CHARSET: Lazy = + Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap()); // The original table is defined in the table 5 of JISX0510:2004 (p.19). const ALPHANUMERIC_TABLE: [i8; 96] = [