match *self {
MissingSlash => "a slash (/) was missing between the type and subtype",
MissingEqual => "an equals sign (=) was missing between a parameter and its value",
MissingQuote => "a quote (\") was missing from a parameter value",
InvalidToken { .. } => "an invalid token was encountered",
}
}
}
impl Error for ParseError { // Minimum Rust is 1.15, Error::description was still required then #[allow(deprecated)] fn description(&self) -> &str { self.s()
}
}
pubfn parse(s: &str) -> Result<Mime, ParseError> { if s == "*/*" { return Ok(::STAR_STAR);
}
letmut iter = s.bytes().enumerate(); // toplevel letmut start; let slash; loop { match iter.next() {
Some((_, c)) if is_token(c) => (),
Some((i, b'/')) if i > 0 => {
slash = i;
start = i + 1; break;
},
None => return Err(ParseError::MissingSlash), // EOF and no toplevel is no Mime
Some((pos, byte)) => return Err(ParseError::InvalidToken {
pos: pos,
byte: byte,
})
};
}
// sublevel letmut plus = None; loop { match iter.next() {
Some((i, b'+')) if i > start => {
plus = Some(i);
},
Some((i, b';')) if i > start => {
start = i; break;
},
Some((_, c)) if is_token(c) => (),
None => { return Ok(Mime {
source: Source::Dynamic(s.to_ascii_lowercase()),
slash: slash,
plus: plus,
params: ParamSource::None,
});
},
Some((pos, byte)) => return Err(ParseError::InvalidToken {
pos: pos,
byte: byte,
})
};
}
// params let params = params_from_str(s, &mut iter, start)?;
let src = match params {
ParamSource::Utf8(_) => s.to_ascii_lowercase(),
ParamSource::Custom(semicolon, ref indices) => lower_ascii_with_params(s, semicolon, indices),
ParamSource::None => { // Chop off the empty list
s[..start].to_ascii_lowercase()
}
};
for &(ref name, ref value) in params {
owned[name.0..name.1].make_ascii_lowercase(); // Since we just converted this part of the string to lowercase, // we can skip the `Name == &str` unicase check and do a faster // memcmp instead. if &owned[name.0..name.1] == CHARSET.source {
owned[value.0..value.1].make_ascii_lowercase();
}
}
owned
}
// From [RFC6838](http://tools.ietf.org/html/rfc6838#section-4.2): // // > All registered media types MUST be assigned top-level type and // > subtype names. The combination of these names serves to uniquely // > identify the media type, and the subtype name facet (or the absence // > of one) identifies the registration tree. Both top-level type and // > subtype names are case-insensitive. // > // > Type and subtype names MUST conform to the following ABNF: // > // > type-name = restricted-name // > subtype-name = restricted-name // > // > restricted-name = restricted-name-first *126restricted-name-chars // > restricted-name-first = ALPHA / DIGIT // > restricted-name-chars = ALPHA / DIGIT / "!" / "#" / // > "$" / "&" / "-" / "^" / "_" // > restricted-name-chars =/ "." ; Characters before first dot always // > ; specify a facet name // > restricted-name-chars =/ "+" ; Characters after last plus always // > ; specify a structured syntax suffix
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.