Add parse::url::scheme function for parsing a url protocol/scheme
Closes #1304
This commit is contained in:
parent
e13a4c7742
commit
80040152a2
3 changed files with 10 additions and 0 deletions
|
@ -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,
|
||||||
|
|
|
@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue