Lines Matching full:url
1 // Copyright 2016 The rust-url developers.
10 use crate::Url;
13 /// Exposes methods to manipulate the path of an URL that is not cannot-be-base.
21 /// use url::Url;
25 /// let mut url = Url::parse("mailto:me@example.com")?;
26 /// assert!(url.path_segments_mut().is_err());
28 /// let mut url = Url::parse("http://example.net/foo/index.html")?;
29 /// url.path_segments_mut().map_err(|_| "cannot be base")?
31 /// assert_eq!(url.as_str(), "http://example.net/foo/img/2%2F100%25.png");
38 url: &'a mut Url, field
45 pub fn new(url: &mut Url) -> PathSegmentsMut<'_> { in new()
46 let after_path = url.take_after_path(); in new()
47 let old_after_path_position = to_u32(url.serialization.len()).unwrap(); in new()
49 if SchemeType::from(url.scheme()).is_special() { in new()
50 debug_assert!(url.byte_at(url.path_start) == b'/'); in new()
53 url.serialization.len() == url.path_start as usize in new()
54 || url.byte_at(url.path_start) == b'/' in new()
58 after_first_slash: url.path_start as usize + "/".len(), in new()
59 url, in new()
67 self.url in drop()
73 /// Remove all segments in the path, leaving the minimal `url.path() == "/"`.
80 /// use url::Url;
84 /// let mut url = Url::parse("https://github.com/servo/rust-url/")?;
85 /// url.path_segments_mut().map_err(|_| "cannot be base")?
87 /// assert_eq!(url.as_str(), "https://github.com/logout");
93 self.url.serialization.truncate(self.after_first_slash); in clear()
97 /// Remove the last segment of this URL’s path if it is empty,
101 /// unless it is also the initial slash (so this does nothing if `url.path() == "/")`.
108 /// use url::Url;
112 /// let mut url = Url::parse("https://github.com/servo/rust-url/")?;
113 /// url.path_segments_mut().map_err(|_| "cannot be base")?
115 /// assert_eq!(url.as_str(), "https://github.com/servo/rust-url//pulls");
117 /// let mut url = Url::parse("https://github.com/servo/rust-url/")?;
118 /// url.path_segments_mut().map_err(|_| "cannot be base")?
120 /// assert_eq!(url.as_str(), "https://github.com/servo/rust-url/pulls");
126 if self.after_first_slash >= self.url.serialization.len() { in pop_if_empty()
129 if self.url.serialization[self.after_first_slash..].ends_with('/') { in pop_if_empty()
130 self.url.serialization.pop(); in pop_if_empty()
135 /// Remove the last segment of this URL’s path.
137 /// If the path only has one segment, make it empty such that `url.path() == "/"`.
141 if self.after_first_slash >= self.url.serialization.len() { in pop()
144 let last_slash = self.url.serialization[self.after_first_slash..] in pop()
147 self.url in pop()
153 /// Append the given segment at the end of this URL’s path.
162 /// Append each segment from the given iterator at the end of this URL’s path.
164 /// Each segment is percent-encoded like in `Url::parse` or `Url::join`,
166 /// This is unlike `Url::parse` where `%` is left as-is in case some of the input
176 /// To obtain a behavior similar to `Url::join`, call `.pop()` unconditionally first.
183 /// use url::Url;
187 /// let mut url = Url::parse("https://github.com/")?;
189 /// let repo = "rust-url";
191 /// url.path_segments_mut().map_err(|_| "cannot be base")?
193 /// assert_eq!(url.as_str(), "https://github.com/servo/rust-url/issues/188");
199 /// In order to make sure that parsing the serialization of an URL gives the same URL,
203 /// use url::Url;
207 /// let mut url = Url::parse("https://github.com/servo")?;
208 /// url.path_segments_mut().map_err(|_| "cannot be base")?
209 /// .extend(&["..", "rust-url", ".", "pulls"]);
210 /// assert_eq!(url.as_str(), "https://github.com/servo/rust-url/pulls");
220 let scheme_type = SchemeType::from(self.url.scheme()); in extend()
221 let path_start = self.url.path_start as usize; in extend()
222 self.url.mutate(|parser| { in extend()
230 // Non special url's path might still be empty in extend()