feedparser_rs/namespace/
mod.rs1pub mod content;
28pub mod dublin_core;
30pub mod media_rss;
32
33pub mod namespaces {
35 pub const DUBLIN_CORE: &str = "http://purl.org/dc/elements/1.1/";
37
38 pub const CONTENT: &str = "http://purl.org/rss/1.0/modules/content/";
40
41 pub const MEDIA: &str = "http://search.yahoo.com/mrss/";
43
44 pub const ATOM: &str = "http://www.w3.org/2005/Atom";
46
47 pub const RDF: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
49
50 pub const RSS_10: &str = "http://purl.org/rss/1.0/";
52
53 pub const ITUNES: &str = "http://www.itunes.com/dtds/podcast-1.0.dtd";
55
56 pub const PODCAST: &str = "https://podcastindex.org/namespace/1.0";
58}
59
60pub fn get_namespace_uri(prefix: &str) -> Option<&'static str> {
70 match prefix {
71 "dc" => Some(namespaces::DUBLIN_CORE),
72 "content" => Some(namespaces::CONTENT),
73 "media" => Some(namespaces::MEDIA),
74 "atom" => Some(namespaces::ATOM),
75 "rdf" => Some(namespaces::RDF),
76 "itunes" => Some(namespaces::ITUNES),
77 "podcast" => Some(namespaces::PODCAST),
78 _ => None,
79 }
80}
81
82pub fn get_namespace_prefix(uri: &str) -> Option<&'static str> {
92 match uri {
93 namespaces::DUBLIN_CORE => Some("dc"),
94 namespaces::CONTENT => Some("content"),
95 namespaces::MEDIA => Some("media"),
96 namespaces::ATOM => Some("atom"),
97 namespaces::RDF => Some("rdf"),
98 namespaces::ITUNES => Some("itunes"),
99 namespaces::PODCAST => Some("podcast"),
100 _ => None,
101 }
102}
103
104#[cfg(test)]
105mod tests {
106 use super::*;
107
108 #[test]
109 fn test_get_namespace_uri() {
110 assert_eq!(
111 get_namespace_uri("dc"),
112 Some("http://purl.org/dc/elements/1.1/")
113 );
114 assert_eq!(
115 get_namespace_uri("content"),
116 Some("http://purl.org/rss/1.0/modules/content/")
117 );
118 assert_eq!(
119 get_namespace_uri("media"),
120 Some("http://search.yahoo.com/mrss/")
121 );
122 assert_eq!(get_namespace_uri("unknown"), None);
123 }
124
125 #[test]
126 fn test_get_namespace_prefix() {
127 assert_eq!(
128 get_namespace_prefix("http://purl.org/dc/elements/1.1/"),
129 Some("dc")
130 );
131 assert_eq!(
132 get_namespace_prefix("http://purl.org/rss/1.0/modules/content/"),
133 Some("content")
134 );
135 assert_eq!(
136 get_namespace_prefix("http://search.yahoo.com/mrss/"),
137 Some("media")
138 );
139 assert_eq!(get_namespace_prefix("http://unknown.example.com/"), None);
140 }
141}