forked from lavina/lavina
1
0
Fork 0

used regex_static in Jid (#1)

Reviewed-on: lavina/lavina#1
Co-authored-by: JustTestingV <JustTestingV@gmail.com>
Co-committed-by: JustTestingV <JustTestingV@gmail.com>
This commit is contained in:
JustTestingV 2023-08-26 15:50:05 +00:00 committed by Nikita Vilunov
parent 6ed1f6be40
commit e9fc74b46b
3 changed files with 7 additions and 3 deletions

1
Cargo.lock generated
View File

@ -759,6 +759,7 @@ dependencies = [
"futures-util",
"http-body-util",
"hyper 1.0.0-rc.3",
"lazy_static",
"nom",
"prometheus",
"quick-xml",

View File

@ -16,6 +16,7 @@ tracing-subscriber = "0.3.16"
futures-util = "0.3.25"
prometheus = { version = "0.13.3", default-features = false }
regex = "1.7.1"
lazy_static = "1.4.0"
nom = "7.1.3"
tokio-rustls = "0.24.1"
rustls-pemfile = "1.0.2"

View File

@ -42,10 +42,12 @@ impl Display for Jid {
impl Jid {
pub fn from_string(i: &str) -> Result<Jid> {
// TODO make regex static
use regex::Regex;
let re = Regex::new(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$").unwrap();
let m = re
use lazy_static::lazy_static;
lazy_static! {
static ref RE: Regex = Regex::new(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$").unwrap();
}
let m = RE
.captures(i)
.ok_or(ffail!("Incorrectly format jid: {i}"))?;