json_pointer_simd/parser/
mod.rs

1mod string_repr;
2mod uri_fragment;
3
4use crate::JsonPointer;
5
6/// A parser for JSON pointers. If the string starts with a `#`, it is parsed
7/// as a URI fragment. Otherwise, it is parsed in the string representation.
8pub fn parse(s: &str) -> Result<JsonPointer<String, Vec<String>>, ParseError> {
9    if s.starts_with('#') {
10        let s = uri_fragment::UnescapeIter::new(s.chars().skip(1)).collect::<Result<String, _>>()?;
11        string_repr::parse(s.chars())
12    } else {
13        string_repr::parse(s.chars())
14    }
15}
16
17/// An error that can be encountered when parsing.
18#[derive(Clone, Debug, PartialEq)]
19pub enum ParseError {
20    /// An invalid escape sequence was encountered, either a `~` escape or a
21    /// `%` escape.
22    InvalidEscape(String),
23    /// An error caused by not having a leading slash on the JSON pointer.
24    ///
25    /// For example, the string `a/b/c` is not a valid JSON pointer, while
26    /// `/a/b/c` is.
27    NoLeadingSlash,
28}