Lines Matching +full:whatwg +full:- +full:encoding
1 // Copyright 2013-2016 The rust-url developers.
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
13 //! Percent encoding replaces reserved characters with the `%` escape character
17 //! When encoding, the set of characters that can (and should, for readability) be left alone
34 //! /// https://url.spec.whatwg.org/#fragment-percent-encode-set
58 /// This is similar to [percent-encode sets](https://url.spec.whatwg.org/#percent-encoded-bytes).
65 /// /// https://url.spec.whatwg.org/#fragment-percent-encode-set
79 /// Called with UTF-8 bytes rather than code points.
80 /// Not used for non-ASCII bytes.
81 const fn contains(&self, byte: u8) -> bool { in contains()
87 fn should_percent_encode(&self, byte: u8) -> bool { in should_percent_encode()
91 pub const fn add(&self, byte: u8) -> Self { in add()
97 pub const fn remove(&self, byte: u8) -> Self { in remove()
108 /// <https://url.spec.whatwg.org/#c0-control-percent-encode-set>
153 .add(b'-')
174 /// Return the percent-encoding of the given byte.
186 pub fn percent_encode_byte(byte: u8) -> &'static str { in percent_encode_byte()
208 /// Percent-encode the given bytes with the given set.
210 /// Non-ASCII bytes and bytes in `ascii_set` are encoded.
226 pub fn percent_encode<'a>(input: &'a [u8], ascii_set: &'static AsciiSet) -> PercentEncode<'a> { in percent_encode()
233 /// Percent-encode the UTF-8 encoding of the given string.
245 pub fn utf8_percent_encode<'a>(input: &'a str, ascii_set: &'static AsciiSet) -> PercentEncode<'a> { in utf8_percent_encode()
259 fn next(&mut self) -> Option<&'a str> { in next()
266 // confirmed as a subset of UTF-8 in should_percent_encode. in next()
284 fn size_hint(&self) -> (usize, Option<usize>) { in size_hint()
294 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { in fmt()
304 fn from(mut iter: PercentEncode<'a>) -> Self { in from()
320 /// Percent-decode the given string.
322 /// <https://url.spec.whatwg.org/#string-percent-decode>
326 pub fn percent_decode_str(input: &str) -> PercentDecode<'_> { in percent_decode_str()
330 /// Percent-decode the given bytes.
332 /// <https://url.spec.whatwg.org/#percent-decode>
337 /// * Implements `Into<Cow<u8>>` borrowing `input` when it contains no percent-encoded sequence,
349 pub fn percent_decode(input: &[u8]) -> PercentDecode<'_> { in percent_decode()
361 fn after_percent_sign(iter: &mut slice::Iter<'_, u8>) -> Option<u8> { in after_percent_sign()
372 fn next(&mut self) -> Option<u8> { in next()
382 fn size_hint(&self) -> (usize, Option<usize>) { in size_hint()
390 fn from(iter: PercentDecode<'a>) -> Self { in from()
399 /// If the percent-decoding is different from the input, return it as a new bytes vector.
401 fn if_any(&self) -> Option<Vec<u8>> { in if_any()
406 let unchanged_bytes_len = initial_bytes.len() - bytes_iter.len() - 3; in if_any()
417 /// Decode the result of percent-decoding as UTF-8.
419 /// This is return `Err` when the percent-decoded bytes are not well-formed in UTF-8.
421 pub fn decode_utf8(self) -> Result<Cow<'a, str>, str::Utf8Error> { in decode_utf8()
434 /// Decode the result of percent-decoding as UTF-8, lossily.
436 /// Invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD,
439 pub fn decode_utf8_lossy(self) -> Cow<'a, str> { in decode_utf8_lossy()
445 fn decode_utf8_lossy(input: Cow<'_, [u8]>) -> Cow<'_, str> { in decode_utf8_lossy()
453 // be sure our original bytes were valid UTF-8. This is because in decode_utf8_lossy()
454 // if the bytes were invalid UTF-8 from_utf8_lossy would have in decode_utf8_lossy()
462 // Given we know the original input bytes are valid UTF-8, in decode_utf8_lossy()
463 // and we have ownership of those bytes, we re-use them and in decode_utf8_lossy()