mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
change to using once_cell for lazy init
This commit is contained in:
@@ -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<Regex> = Lazy::new(|| Regex::new("[0-9]{8}(T[0-9]{6}Z?)?").unwrap());
|
||||
static RFC2445_DURATION: Lazy<Regex> = 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?)?";
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Regex> = Lazy::new(|| Regex::new(",").unwrap());
|
||||
static ATEXT_ALPHANUMERIC: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap());
|
||||
|
||||
use super::{
|
||||
EmailAddressParsedRXingResult, EmailDoCoMoResultParser, ParsedClientResult, ResultParser,
|
||||
|
||||
@@ -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<Regex> =
|
||||
Lazy::new(|| Regex::new("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+").unwrap());
|
||||
|
||||
/**
|
||||
* Implements the "MATMSG" email message entry format.
|
||||
|
||||
@@ -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<regex::Regex> = Lazy::new(|| regex::Regex::new(GEO_URL_PATTERN).unwrap());
|
||||
|
||||
const GEO_URL_PATTERN: &str = "geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?";
|
||||
|
||||
|
||||
@@ -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<ParsedClientResult>;
|
||||
|
||||
lazy_static! {
|
||||
static ref DIGITS: Regex = Regex::new("\\d+").unwrap();
|
||||
}
|
||||
static DIGITS: Lazy<Regex> = Lazy::new(|| Regex::new("\\d+").unwrap());
|
||||
|
||||
// const DIGITS: &'static str = "\\d+"; //= Pattern.compile("\\d+");
|
||||
const AMPERSAND: &str = "&"; // private static final Pattern AMPERSAND = Pattern.compile("&");
|
||||
|
||||
@@ -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<Regex> = Lazy::new(|| {
|
||||
Regex::new(ALLOWED_URI_CHARS_PATTERN).expect("Regex patterns should always copile")
|
||||
});
|
||||
static USER_IN_HOST: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(":/*([^/@]+)@[^/]+").expect("Regex patterns should always copile"));
|
||||
static URL_WITH_PROTOCOL_PATTERN: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new("[a-zA-Z][a-zA-Z0-9+-.]+:").unwrap());
|
||||
static URL_WITHOUT_PROTOCOL_PATTERN: Lazy<Regex> =
|
||||
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 = ":/*([^/@]+)@[^/]+";
|
||||
|
||||
@@ -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("(?<!\\\\);+").unwrap();
|
||||
static ref SEMICOLON_OR_COMMA: Regex = Regex::new("[;,]").unwrap();
|
||||
}
|
||||
static BEGIN_VCARD: Lazy<Regex> = Lazy::new(|| Regex::new("(?i:BEGIN:VCARD)").unwrap());
|
||||
static VCARD_LIKE_DATE: Lazy<Regex> = Lazy::new(|| Regex::new("\\d{4}-?\\d{2}-?\\d{2}").unwrap());
|
||||
static CR_LF_SPACE_TAB: Lazy<Regex> = Lazy::new(|| Regex::new("\r\n[ \t]").unwrap());
|
||||
static NEWLINE_ESCAPE: Lazy<Regex> = Lazy::new(|| Regex::new("\\\\[nN]").unwrap());
|
||||
static VCARD_ESCAPE: Lazy<Regex> = Lazy::new(|| Regex::new("\\\\([,;\\\\])").unwrap());
|
||||
static EQUALS: Lazy<Regex> = Lazy::new(|| Regex::new("=").unwrap());
|
||||
static UNESCAPED_SEMICOLONS: Lazy<fancy_regex::Regex> =
|
||||
Lazy::new(|| fancy_regex::Regex::new("(?<!\\\\);+").unwrap());
|
||||
static SEMICOLON_OR_COMMA: Lazy<Regex> = 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}";
|
||||
|
||||
@@ -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<Regex> = Lazy::new(|| Regex::new(IOQ).unwrap());
|
||||
static AZ09_MATCHER: Lazy<Regex> = Lazy::new(|| Regex::new(AZ09).unwrap());
|
||||
|
||||
/**
|
||||
* Detects a result that is likely a vehicle identification number.
|
||||
|
||||
Reference in New Issue
Block a user