Expand description
The byte classes of the ABNF, in one table.
One static table of 256 u32 entries (1 KiB), built at compile time from
the ABNF, holds one bit per class, so classifying a byte is one load and
one mask. The table is the single reviewable source of every class; the
tests compare it, for all 256 bytes, with slow functions written straight
from the RFC text.
Every class is ASCII-only except OBS_TEXT, FIELD_TEXT, QDTEXT,
CTEXT, QUOTED_PAIR, and ETAGC, which include 0x80 to 0xFF as
obs-text. DEL (0x7F) is in no class.
§Examples
use parse_net::class::{self, Class};
assert!(class::is_tchar(b'!') && !class::is_tchar(b'('));
assert!(class::is_mime_token_char(b'{') && !class::is_tchar(b'{'));
assert_eq!(class::hex_value(b'f'), Some(15));
assert!(class::all(b"no-cache", Class::TCHAR));
assert!(Class::UNRESERVED.union(Class::SUB_DELIM).contains(b'~'));Structs§
Functions§
- all
- Whether every byte of
sis inclass(true for an emptys). Stops at the first byte outside. - hex_
value - The value of one hex digit (either case), or
None. - is_
atext - Whether
bis anatextbyte (RFC 5322 section 3.2.3). - is_
attr_ char - Whether
bis anattr-char(RFC 8187 section 3.2.1). - is_
av_ octet - Whether
bmay appear in a cookie attribute value (rfc6265bis section 4.1.1). - is_
base64_ char - Whether
bis in the base64 alphabet (RFC 4648 section 4), padding aside. - is_
bchar_ nospace - Whether
bis abcharsnospacebyte (RFC 2046 section 5.1.1). - is_
cookie_ octet - Whether
bis acookie-octet(rfc6265bis section 4.1.1). - is_
ctext - Whether
bmay appear unescaped in a comment (RFC 9110 section 5.6.5). - is_
etagc - Whether
bis anetagc(RFC 9110 section 8.8.3). - is_
field_ text - Whether
bmay appear in a field value:field-vchar / SP / HTAB(RFC 9110 section 5.5). - is_
hexdig - Whether
bis a hex digit, either case. - is_
mime_ token_ char - Whether
bmay appear in a MIMEtoken(RFC 2045 section 5.1). - is_
obs_ text - Whether
bisobs-text, 0x80 to 0xFF. - is_
pchar_ no_ pct - Whether
bis apcharother than the%ofpct-encoded(RFC 3986 section 3.3). - is_
qdtext - Whether
bmay appear unescaped in a quoted string (RFC 9110 section 5.6.4). - is_
quoted_ pair_ char - Whether
bmay follow\in aquoted-pair:HTAB / SP / VCHAR / obs-text. - is_
sf_ key_ char - Whether
bmay appear in a Structured Field key. - is_
sf_ key_ start - Whether
bmay start a Structured Field key:lcalpha / "*". - is_
sf_ string_ char - Whether
bmay appear unescaped in a Structured Field string. - is_
sf_ token_ char - Whether
bmay appear in a Structured Field token after its first byte. - is_
sub_ delim - Whether
bis asub-delimsbyte (RFC 3986 section 2.2). - is_
tchar - Whether
bis atchar, a byte allowed in a token (RFC 9110 section 5.6.2). - is_
token68_ char - Whether
bis atoken68byte other than the=padding. - is_
unreserved - Whether
bisunreserved(RFC 3986 section 2.3). - is_
uri_ target - Whether
bmay appear in a request target:pchar / "/" / "?"or the%of apct-encodedtriple (whose digits are checked apart). - is_
vchar - Whether
bis a visible ASCII character, 0x21 to 0x7E.