Expand description
Hexadecimal escapes shared by quoted-printable (=XX), percent-encoding
(%XX) and xtext (+XX).
decode_pair is the primitive every decoder in the crate uses. The
HexEscape engines apply a whole scheme: bytes outside the scheme’s
safe set are written as a marker followed by two uppercase hexadecimal
digits, and decoding turns every marker and the two digits after it back
into a byte.
use encodify::hex;
use std::borrow::Cow;
assert_eq!(hex::PERCENT.encode("naïve.txt"), "na%C3%AFve.txt");
assert_eq!(hex::PERCENT.decode("na%c3%afve.txt")?, "naïve.txt".as_bytes());
assert_eq!(
hex::XTEXT.encode("rfc822;a+b@example.org"),
"rfc822;a+2Bb@example.org"
);
assert!(matches!(
hex::XTEXT.decode("rfc822;user@example.org")?,
Cow::Borrowed(_)
));Structs§
- HexEscape
- A hexadecimal escaping scheme: a marker byte followed by two hexadecimal digits stands for any byte outside the scheme’s safe set.
Constants§
- PERCENT
- Percent-encoding (
%XX). Encoding keeps the RFC 2231attribute-charset (letters, digits and! # $ & + - . ^ _ ` { | } ~) and escapes every other byte, as RFC 2231 extended parameter values require. It is not a URI component encoder: RFC 3986 reserves some of those characters. Decoding accepts any literal byte, so URIs andmailto:URLs decode too;+is not a space. - XTEXT
- SMTP xtext (RFC 3461,
+XX), used by theENVIDandORCPTparameters. Encoding keeps the printable ASCII characters other than+and=.
Functions§
- decode_
pair - Decodes two hexadecimal digits (either case) into a byte.