Skip to main content

Module class

Module class 

Source
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§

Class
A set of byte classes, for all and the scanning functions.

Functions§

all
Whether every byte of s is in class (true for an empty s). Stops at the first byte outside.
hex_value
The value of one hex digit (either case), or None.
is_atext
Whether b is an atext byte (RFC 5322 section 3.2.3).
is_attr_char
Whether b is an attr-char (RFC 8187 section 3.2.1).
is_av_octet
Whether b may appear in a cookie attribute value (rfc6265bis section 4.1.1).
is_base64_char
Whether b is in the base64 alphabet (RFC 4648 section 4), padding aside.
is_bchar_nospace
Whether b is a bcharsnospace byte (RFC 2046 section 5.1.1).
is_cookie_octet
Whether b is a cookie-octet (rfc6265bis section 4.1.1).
is_ctext
Whether b may appear unescaped in a comment (RFC 9110 section 5.6.5).
is_etagc
Whether b is an etagc (RFC 9110 section 8.8.3).
is_field_text
Whether b may appear in a field value: field-vchar / SP / HTAB (RFC 9110 section 5.5).
is_hexdig
Whether b is a hex digit, either case.
is_mime_token_char
Whether b may appear in a MIME token (RFC 2045 section 5.1).
is_obs_text
Whether b is obs-text, 0x80 to 0xFF.
is_pchar_no_pct
Whether b is a pchar other than the % of pct-encoded (RFC 3986 section 3.3).
is_qdtext
Whether b may appear unescaped in a quoted string (RFC 9110 section 5.6.4).
is_quoted_pair_char
Whether b may follow \ in a quoted-pair: HTAB / SP / VCHAR / obs-text.
is_sf_key_char
Whether b may appear in a Structured Field key.
is_sf_key_start
Whether b may start a Structured Field key: lcalpha / "*".
is_sf_string_char
Whether b may appear unescaped in a Structured Field string.
is_sf_token_char
Whether b may appear in a Structured Field token after its first byte.
is_sub_delim
Whether b is a sub-delims byte (RFC 3986 section 2.2).
is_tchar
Whether b is a tchar, a byte allowed in a token (RFC 9110 section 5.6.2).
is_token68_char
Whether b is a token68 byte other than the = padding.
is_unreserved
Whether b is unreserved (RFC 3986 section 2.3).
is_uri_target
Whether b may appear in a request target: pchar / "/" / "?" or the % of a pct-encoded triple (whose digits are checked apart).
is_vchar
Whether b is a visible ASCII character, 0x21 to 0x7E.