sub_converter/parse/uri/
mod.rs1use crate::error::{Error, Result};
2use crate::ir::Node;
3
4pub mod ss;
5pub mod trojan;
6
7pub struct UriListParser;
8
9impl super::Parser for UriListParser {
10 fn parse(&self, input: &str) -> Result<Vec<Node>> {
11 let mut out = Vec::new();
12 for line in input.lines() {
13 let line = line.trim();
14 if line.is_empty() || line.starts_with('#') {
15 continue;
16 }
17 let node_opt = parse_uri_line(line)?;
18 if let Some(node) = node_opt {
19 out.push(node);
20 }
21 }
22 Ok(out)
23 }
24}
25
26pub fn parse_uri_line(line: &str) -> Result<Option<Node>> {
27 if line.starts_with("ss://") {
28 return Ok(Some(ss::parse_ss_uri(line)?));
29 }
30 if line.starts_with("trojan://") {
31 return Ok(Some(trojan::parse_trojan_uri(line)?));
32 }
33 Err(Error::Unsupported {
34 what: format!("unsupported uri scheme: {}", line),
35 })
36}