Skip to main content

web_url/parse/path_plus/
path_plus.rs

1use crate::parse::path_plus::{parse_fragment, parse_path, parse_query};
2use crate::parse::Error;
3
4/// The parsing data for a web-based URL from the path to the end.
5#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
6pub struct PathPlus {
7    pub path_len: usize,  // length of the path including the '/' (will be 1+)
8    pub query_len: usize, // length of query including the '?' (will be 0+)
9}
10
11/// Parses the `path_plus`.
12///
13/// The path, query, and fragment will be validated.
14pub fn parse_path_plus(path_plus: &str) -> Result<PathPlus, Error> {
15    let (path, after_path) = parse_path(path_plus)?;
16    let (query, after_query) = parse_query(after_path)?;
17    parse_fragment(after_query)?;
18
19    let path_len: usize = path.as_str().len();
20    let query_len: usize = query.map(|q| q.as_str().len()).unwrap_or(0);
21
22    Ok(PathPlus {
23        path_len,
24        query_len,
25    })
26}