1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#[derive(Debug, Clone, PartialEq)]
pub enum UriType {
    Full,
    Relative,
    Prefixed,
    PrefixedWithBase,
    BlankNode
}

#[derive(Debug, Clone, PartialEq)]
pub struct Uri {
    pub prefix: String,
    pub name: String,
    pub uri_type: UriType
}

impl Uri {
    pub fn new(prefix: &str, name: &str, uri_type: UriType) -> Self {
        Self {
            prefix: prefix.into(),
            name: name.into(),
            uri_type
        }
    }
}

impl ToString for Uri {
    fn to_string(&self) -> String {
        format!("{}{}", self.prefix, self.name)
    }
}

pub mod matches {
    use regex::Regex;
    use lazy_static::lazy_static;

    lazy_static! {
        pub static ref FULL_URL: Regex = Regex::new(r"<(http://(?:[\w\d\-_]{3,}\.)+[a-z]{2,}/(?:[\w\d\-_]+)*[#/])([\w\d\-_]+)>").unwrap();
        pub static ref RELATIVE_URL: Regex = Regex::new(r"<#?([\w\d\-_]+)>").unwrap();
        pub static ref PREFIXED: Regex = Regex::new(r"([\w\d\-_]+:)([\w\d\-_]+)").unwrap();
        pub static ref EMPTY_PREFIX: Regex = Regex::new(r":([\w\d\-_]+)").unwrap();
    }
}