1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
mod authority;
use core::marker::PhantomData;
use core::num::NonZeroUsize;
use crate::parser::trusted as trusted_parser;
use crate::spec::Spec;
use crate::types::RiReferenceStr;
pub use self::authority::AuthorityComponents;
#[derive(Debug, Clone, Copy)]
pub(crate) struct RiReferenceComponents<'a, S: Spec> {
pub(crate) iri: &'a RiReferenceStr<S>,
pub(crate) scheme_end: Option<NonZeroUsize>,
pub(crate) authority_end: Option<NonZeroUsize>,
pub(crate) query_start: Option<NonZeroUsize>,
pub(crate) fragment_start: Option<NonZeroUsize>,
pub(crate) _spec: PhantomData<fn() -> S>,
}
impl<'a, S: Spec> RiReferenceComponents<'a, S> {
#[must_use]
pub(crate) fn to_major(
self,
) -> (
Option<&'a str>,
Option<&'a str>,
&'a str,
Option<&'a str>,
Option<&'a str>,
) {
let s = self.iri.as_str();
let (scheme, next_of_scheme) = match self.scheme_end {
Some(end) => (Some(&s[..end.get()]), end.get() + 1),
None => (None, 0),
};
let (authority, next_of_authority) = match self.authority_end {
Some(end) => (Some(&s[(next_of_scheme + 2)..end.get()]), end.get()),
None => (None, next_of_scheme),
};
let (fragment, end_of_prev_of_fragment) = match self.fragment_start {
Some(start) => (Some(&s[start.get()..]), start.get() - 1),
None => (None, s.len()),
};
let (query, end_of_path) = match self.query_start {
Some(start) => (
Some(&s[start.get()..end_of_prev_of_fragment]),
start.get() - 1,
),
None => (None, end_of_prev_of_fragment),
};
let path = &s[next_of_authority..end_of_path];
(scheme, authority, path, query, fragment)
}
#[inline]
#[must_use]
pub(crate) fn iri(&self) -> &'a RiReferenceStr<S> {
self.iri
}
}
impl<'a, S: Spec> From<&'a RiReferenceStr<S>> for RiReferenceComponents<'a, S> {
#[inline]
fn from(s: &'a RiReferenceStr<S>) -> Self {
trusted_parser::decompose_iri_reference(s)
}
}