Expand description
The percent-encoding primitive: validate, decode into a caller buffer, and encode with a named set and hex case.
These are the operations parse-net’s own grammars need (RFC 8187 values,
RFC 9651 Display Strings, RFC 7578 file names). Everything URL-specific
(component encode sets, + as space, normalization) belongs to url-lib,
which builds its sets with EncodeSet::add and EncodeSet::remove.
§Examples
use parse_net::{self as pn, pct::{self, EncodeSet, HexCase}, class::Class};
let mut buf = [0u8; 16];
assert_eq!(pct::decode_utf8_into(b"caf%C3%A9", &mut buf)?, "caf\u{e9}");
assert_eq!(pct::validate(b"%4").unwrap_err().kind(), pn::ErrorKind::InvalidPercentEncoding);
assert!(pct::validate_with(b"/a/b?c=%20", Class::URI_TARGET).is_ok());
let mut out = pn::SliceSink::new(&mut buf);
pct::encode(b"a b/c", &EncodeSet::ATTR_CHAR_COMPLEMENT, HexCase::Upper, &mut out).expect("room");
assert_eq!(out.written(), b"a%20b%2Fc");Structs§
- Encode
Set - A set of bytes that must be percent-encoded: a 256-bit bitmap.
Enums§
Functions§
- decode_
into - Decodes
%XXtriples (either case) intoout, copying every other byte, and returns the written part. - decode_
lower_ only_ into - As
decode_into, refusing uppercase hex (RFC 9651 section 4.2.10). - decode_
utf8_ into - As
decode_into, and the decoded bytes must be UTF-8 (overlong forms and surrogates refused). - decoded_
len - Validates
inputand returns its decoded length. - encode
- Writes
inputwith every byte inset, and every byte above 0x7F, as%XX. - encoded_
len - The length of
inputonce encoded withset. - validate
- Checks that every
%is followed by two hex digits (either case). - validate_
with - As
validate, and every byte other than a%XXtriple is inallowed.