You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
560 B
Rust
28 lines
560 B
Rust
use lazy_regex::regex;
|
|
|
|
pub enum UrlType {
|
|
Reddit,
|
|
Twitter,
|
|
Other,
|
|
}
|
|
|
|
pub fn find_url_type(url: &str) -> UrlType {
|
|
if is_reddit_url(url) {
|
|
UrlType::Reddit
|
|
} else if is_twitter_url(url) {
|
|
UrlType::Twitter
|
|
} else {
|
|
UrlType::Other
|
|
}
|
|
}
|
|
|
|
fn is_reddit_url(url: &str) -> bool {
|
|
let r = regex!(r#"^http(s)?://(www\.)?(reddit\.com|redd\.it|reddit\.app\.link).*$"#i);
|
|
r.is_match(url)
|
|
}
|
|
|
|
fn is_twitter_url(url: &str) -> bool {
|
|
let r = regex!(r#"^http(s)?://(www\.)?twitter\.com.*$"#);
|
|
r.is_match(url)
|
|
}
|