1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
new_table! {
pub flags {
/// CText characters
CText = CT,
/// ObsNoWsCtl characters of the `obs-` part of the mime grammar which are not ws and not ctl
/// by combining this with other classes the `obs-` part of the grammar can be supported
/// e.g. `QText` + `ObsNoWsCtl` == `ObsQText` i.e. `QText` in the `obs-` grammar
ObsNoWsCtl = NC,
/// HttToken character allowed in a token given the grammar from RFC7230 (http)
HttpToken = HT,
/// Token (Mime) characters allowed in a token given the grammar from RFC2045 (mime)
Token = TO,
/// Restricted Token, character allowed in a token wrt. to registering media types at IANA,
/// any registered media type has to be compatible with this any other should be, through
/// there is no guarantee for it.
RestrictedToken = RT,
/// QText characters, i.e. characters which can appear in a quoted string
/// without being escaped through quoted pairs
QText = QC,
/// The characters mainly needing escaping (just `'"'` and `'\\'`)
///
/// Note: while using a lookup just for to determine if it is `'"'` or `'\\'` makes little sense
/// using it with a already looked up value or in combination with others can make sense
DQuoteOrEscape = DOE,
/// Ws (just `'\t'` and `'\r'`)
///
/// Note: while using a lookup just for to determine if it is `' '` or `'\t'` makes little sense
/// using it with a already looked up value or in combination with others can make sense
Ws = Ws
}
/// MediaTypeChars is a lookup table for a number of character classes relevant when parsing media types
///
/// This are mainly:
/// `CText`, `ObsNoWsCtl`, `HttpToken`, `Token`, `RestrictedToken`,
/// `QText`, `DQuotesOrEscape` and `Ws`
///
/// The classes `HttpToken`, `Token` and `RestrictedToken` are needed for the different specifications
/// of a "token" in Http, Mime and for IANA registry compatible tokens.
///
/// The class `CText` is needed for Mime as Media-Types in Mime can contain comments :=(
/// The class `ObsNoWsCtl` is needed to support the obs-part of the grammar in Mime, the
/// obs-part in Http is different and do not need a lookup as it "just" includes any higher
/// byte (>0x7f).
///
/// Some of the classes like `Ws` or `DQutesOrEscape` are so small that they make no sense when
/// used for themself, but they do make sense if they are combined with others or used on
/// with lookup result already available.
///
pub struct MediaTypeChars {
static data: [u8; 256] = [
//0x00 + 0/4/8/C
-, NC, NC, NC,
NC, NC, NC, NC,
NC, Ws, -, NC,
NC, -, NC, NC,
//0x10 + 0/4/8/C
NC, NC, NC, NC,
NC, NC, NC, NC,
NC, NC, NC, NC,
NC, NC, NC, NC,
//0x20 + 0/4/8/C
Ws, CT|QC|RT|TO|HT, CT|DOE, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|TO|HT, CT|QC|RT|TO|HT, CT|QC|TO|HT,
QC, QC, CT|QC|TO|HT, CT|QC|RT|TO|HT,
CT|QC, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC,
//0x30+ 0/4/8/C
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC, CT|QC,
CT|QC, CT|QC, CT|QC, CT|QC,
//0x40+ 0/4/8/C
CT|QC, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
//0x50 + 0/4/8/C
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC,
DOE,/*'\\'*/ CT|QC, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
//0x60 + 0/4/8/C
CT|QC|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
//0x70 + 0/4/8/C
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT,
CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|RT|TO|HT, CT|QC|TO,
CT|QC|TO|HT, CT|QC|TO, CT|QC|TO|HT, NC,
//0x80
-, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -,
//0x90
-, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -,
//0xA0
-, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -,
//0xB0
-, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -,
//0xC0
-, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -,
//0xD0
-, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -,
//0xE0
-, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -,
//0xF0
-, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -
];
}
}
accessor_any!{
/// QText or Ws chars
pub QTextWs = QText | Ws }
accessor_any!{
/// QText incl. obs-parts of the mime grammar
pub ObsQText = QText | ObsNoWsCtl }
accessor_any!{
/// QText incl. obs-parts (mime) or ws
pub ObsQTextWs = QText | ObsNoWsCtl }
accessor_any!{
/// VChar printable us-ascii chars (i.e. `'!' <= ch && ch <= '~'`)
pub VChar = QText | DQuoteOrEscape }
accessor_any!{
/// VChar or Ws (i.e. `(' ' <= ch && ch <= '~') || ch == '\t'`)
pub VCharWs = QText | DQuoteOrEscape | Ws }