Add parse::url::scheme function for parsing a url protocol/scheme

Closes #1304
This commit is contained in:
Tobie Morgan Hitchcock 2022-10-04 00:28:30 +01:00
parent e13a4c7742
commit 80040152a2
3 changed files with 10 additions and 0 deletions

View file

@ -140,6 +140,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Va
"parse::url::path" => parse::url::path, "parse::url::path" => parse::url::path,
"parse::url::port" => parse::url::port, "parse::url::port" => parse::url::port,
"parse::url::query" => parse::url::query, "parse::url::query" => parse::url::query,
"parse::url::scheme" => parse::url::scheme,
// //
"rand::bool" => rand::bool, "rand::bool" => rand::bool,
"rand::enum" => rand::r#enum, "rand::enum" => rand::r#enum,

View file

@ -110,4 +110,12 @@ pub mod url {
Err(_) => Ok(Value::None), Err(_) => Ok(Value::None),
} }
} }
pub fn scheme((string,): (String,)) -> Result<Value, Error> {
// Parse the URL
match Url::parse(&string) {
Ok(v) => Ok(v.scheme().into()),
Err(_) => Ok(Value::None),
}
}
} }

View file

@ -387,6 +387,7 @@ fn function_parse(i: &str) -> IResult<&str, &str> {
tag("parse::url::port"), tag("parse::url::port"),
tag("parse::url::path"), tag("parse::url::path"),
tag("parse::url::query"), tag("parse::url::query"),
tag("parse::url::scheme"),
))(i) ))(i)
} }