uniform_resource_identifier/uri/query/
mod.rs

1use std::error::Error;
2
3use crate::utils::while_pchar;
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum Query {
7    Query(String),
8}
9
10pub fn parse_query(
11    input: &[u8],
12    start: &mut usize,
13    end: &usize,
14) -> Result<Option<Query>, Box<dyn Error>> {
15    let mut index = *start;
16
17    let query = if input[index] == 0x3f {
18        index += 1;
19        while index <= *end
20            && (while_pchar(input, &mut index, end)?
21                || input[index] == 0x2f
22                || input[index] == 0x3f)
23        {
24            index += 1;
25        }
26        let q = Query::Query(String::from_utf8(input[*start + 1..index].to_vec())?);
27        *start = index;
28        Some(q)
29    } else {
30        None
31    };
32
33    Ok(query)
34}