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
//! This module contains a number of lookup tables.
//!
//! Any of this lookup tables can be enabled by a feature. The additive property of
//! rust features has the effect, that if multiple crates require (a semver compatible
//! version of) lut the compiler will include only one instance of lut into the binary
//! with all features enabled which are enabled in any of the crates. As such any
//! lookup table will should only appear one time in the resulting binary.
//!
//! The benefit of having a collection of "generalish" lookup tables in on crate is that:
//!
//! 1. crates can share the same tables, even if they e.g. implement different parser algorithm
//!    decresing developer overhead and code size (if they are used in the same binary)
//! 2. developers have a place where they can look for them improving discoverability

/// a lookup table for parsing/validating Media Types (also know as MIME-Types)
///
/// To use lookup the table compile the crate with the `media-type-chars` feature enabled,
/// else wise this module will be empty.
pub mod media_type_chars {
    #[cfg(feature = "media-type-chars")]
    new_table! {

        pub flags {
            /// CText
            CText = CT,
            /// ObsNoWsCtl
            ObsNoWsCtl = NC,
            /// Rfc7230Token
            HttpToken = HT,
            /// Token (Mime)
            Token = TO,
            /// Restricted Token
            RestrictedToken = RT,
            /// QText
            QText = QC,
            /// The characters mainly needing escaping i.e. '"' and '\\'
            DQuoteOrEscape = DOE,
            /// Ws  (\t and \r)
            Ws = Ws
        }

        ///
        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
                -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -
            ];
        }
    }
    #[cfg(feature = "media-type-chars")]
    accessor_any!{ pub QTextWs = QText | Ws }
    #[cfg(feature = "media-type-chars")]
    accessor_any!{ pub ObsQText = QText | ObsNoWsCtl }
    #[cfg(feature = "media-type-chars")]
    accessor_any!{ pub ObsQTextWs = QText | ObsNoWsCtl }
    #[cfg(feature = "media-type-chars")]
    accessor_any!{ pub VChar = QText | DQuoteOrEscape }
    #[cfg(feature = "media-type-chars")]
    accessor_any!{ pub VCharWs = QText | DQuoteOrEscape | Ws }

}