Add SQL is::url() function for checking if a string is a URL
This commit is contained in:
parent
65f219ffe5
commit
e9615cd5ff
3 changed files with 8 additions and 0 deletions
|
@ -4,6 +4,7 @@ use once_cell::sync::Lazy;
|
|||
use regex::Regex;
|
||||
use semver::Version;
|
||||
use std::char;
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[rustfmt::skip] static LATITUDE_RE: Lazy<Regex> = Lazy::new(|| Regex::new("^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$").unwrap());
|
||||
|
@ -59,6 +60,11 @@ pub fn semver((arg,): (String,)) -> Result<Value, Error> {
|
|||
Ok(Version::parse(arg.as_str()).is_ok().into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn url((arg,): (String,)) -> Result<Value, Error> {
|
||||
Ok(Url::parse(&arg).is_ok().into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn uuid((arg,): (Value,)) -> Result<Value, Error> {
|
||||
Ok(match arg {
|
||||
|
|
|
@ -101,6 +101,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Va
|
|||
"is::longitude" => is::longitude,
|
||||
"is::numeric" => is::numeric,
|
||||
"is::semver" => is::semver,
|
||||
"is::url" => is::url,
|
||||
"is::uuid" => is::uuid,
|
||||
//
|
||||
"math::abs" => math::abs,
|
||||
|
|
|
@ -309,6 +309,7 @@ fn function_is(i: &str) -> IResult<&str, &str> {
|
|||
tag("is::longitude"),
|
||||
tag("is::numeric"),
|
||||
tag("is::semver"),
|
||||
tag("is::url"),
|
||||
tag("is::uuid"),
|
||||
))(i)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue