use regex::Regex;
pub mod ip {
use super::Regex;
pub static V4: fn(&str) -> bool = |data: &str| -> bool {
lazy_static! {
static ref IP_V4_ADDR_RE: Regex = Regex::new(
r"(?x)
^
(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)
\.
(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)
\.
(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)
\.
(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)
$
"
)
.unwrap();
}
IP_V4_ADDR_RE.is_match(data)
};
pub static V6: fn(&str) -> bool = |data: &str| -> bool {
lazy_static! {
static ref IP_V6_ADDR_RE: Regex = Regex::new(
r"(?x)
^(?:[\dA-Fa-f]{1,4}:){6}(?:[\dA-Fa-f]{1,4}:[\dA-Fa-f]{1,4}|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d))$
|
^::(?:[\dA-Fa-f]{1,4}:){5}(?:[\dA-Fa-f]{1,4}:[\dA-Fa-f]{1,4}|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d))$
|
^(?:[\dA-Fa-f]{1,4})?::(?:[\dA-Fa-f]{1,4}:){4}(?:[\dA-Fa-f]{1,4}:[\dA-Fa-f]{1,4}|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\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:(?:[\dA-Fa-f]{1,4}:){0,5}[\dA-Fa-f]{1,4})?::[\dA-Fa-f]{1,4}$
|
^(?:(?:[\dA-Fa-f]{1,4}:){0,6}[\dA-Fa-f]{1,4})?::$
"
)
.unwrap();
}
IP_V6_ADDR_RE.is_match(data)
};
}
pub mod uri {
use super::Regex;
pub static SCHEME: fn(&str) -> bool = |data: &str| -> bool {
lazy_static! {
static ref URI_SCHEME_RE: Regex = Regex::new(r"^[:alpha:][[:alpha:]\d+-\.]*$").unwrap();
}
URI_SCHEME_RE.is_match(data)
};
pub mod authority {
use super::Regex;
pub static PORT: fn(&str) -> bool = |data: &str| -> bool {
lazy_static! {
static ref URI_AUTHORITY_PORT_RE: Regex = Regex::new(r"^\d*$").unwrap();
}
URI_AUTHORITY_PORT_RE.is_match(data)
};
}
}