page rewrite
Some checks failed
CI / Check typos (push) Failing after 9s
CI / Check links (push) Failing after 14s
CI / Clippy (push) Successful in 53s
CI / Build and test (push) Successful in 1m19s
CI / Build container (push) Has been skipped
CI / Deploy on waypoint (push) Has been skipped
Some checks failed
CI / Check typos (push) Failing after 9s
CI / Check links (push) Failing after 14s
CI / Clippy (push) Successful in 53s
CI / Build and test (push) Successful in 1m19s
CI / Build container (push) Has been skipped
CI / Deploy on waypoint (push) Has been skipped
This commit is contained in:
@@ -251,6 +251,23 @@ impl From<&MimeType> for String {
|
||||
// MARK: fromstr
|
||||
//
|
||||
|
||||
impl MimeType {
|
||||
/// Parse a mimetype from a string that may contain
|
||||
/// whitespace or ";" parameters.
|
||||
///
|
||||
/// Parameters are discarded, write your own parser if you need them.
|
||||
pub fn from_header(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
let s = s.trim();
|
||||
let semi = s.find(';').unwrap_or(s.len());
|
||||
let space = s.find(' ').unwrap_or(s.len());
|
||||
let limit = semi.min(space);
|
||||
let s = &s[0..limit];
|
||||
let s = s.trim();
|
||||
|
||||
return Self::from_str(s);
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for MimeType {
|
||||
type Err = std::convert::Infallible;
|
||||
|
||||
@@ -687,4 +704,108 @@ impl MimeType {
|
||||
Self::Xul => Some("xul"),
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// MARK: is_text
|
||||
//
|
||||
|
||||
/// Returns true if this MIME type is always plain text.
|
||||
pub fn is_text(&self) -> bool {
|
||||
match self {
|
||||
// Text types
|
||||
Self::Text => true,
|
||||
Self::Css => true,
|
||||
Self::Csv => true,
|
||||
Self::Html => true,
|
||||
Self::Javascript => true,
|
||||
Self::Json => true,
|
||||
Self::JsonLd => true,
|
||||
Self::Xml => true,
|
||||
Self::Svg => true,
|
||||
Self::Ics => true,
|
||||
Self::Xhtml => true,
|
||||
|
||||
// Script types
|
||||
Self::Csh => true,
|
||||
Self::Php => true,
|
||||
Self::Sh => true,
|
||||
|
||||
// All other types are not plain text
|
||||
Self::Other(_) => false,
|
||||
Self::Blob => false,
|
||||
|
||||
// Audio
|
||||
Self::Aac => false,
|
||||
Self::Flac => false,
|
||||
Self::Midi => false,
|
||||
Self::Mp3 => false,
|
||||
Self::Oga => false,
|
||||
Self::Opus => false,
|
||||
Self::Wav => false,
|
||||
Self::Weba => false,
|
||||
|
||||
// Video
|
||||
Self::Avi => false,
|
||||
Self::Mp4 => false,
|
||||
Self::Mpeg => false,
|
||||
Self::Ogv => false,
|
||||
Self::Ts => false,
|
||||
Self::WebmVideo => false,
|
||||
Self::ThreeGp => false,
|
||||
Self::ThreeG2 => false,
|
||||
|
||||
// Images
|
||||
Self::Apng => false,
|
||||
Self::Avif => false,
|
||||
Self::Bmp => false,
|
||||
Self::Gif => false,
|
||||
Self::Ico => false,
|
||||
Self::Jpg => false,
|
||||
Self::Png => false,
|
||||
Self::Qoi => false,
|
||||
Self::Tiff => false,
|
||||
Self::Webp => false,
|
||||
|
||||
// Documents
|
||||
Self::Pdf => false,
|
||||
Self::Rtf => false,
|
||||
|
||||
// Archives
|
||||
Self::Arc => false,
|
||||
Self::Bz => false,
|
||||
Self::Bz2 => false,
|
||||
Self::Gz => false,
|
||||
Self::Jar => false,
|
||||
Self::Ogg => false,
|
||||
Self::Rar => false,
|
||||
Self::SevenZ => false,
|
||||
Self::Tar => false,
|
||||
Self::Zip => false,
|
||||
|
||||
// Fonts
|
||||
Self::Eot => false,
|
||||
Self::Otf => false,
|
||||
Self::Ttf => false,
|
||||
Self::Woff => false,
|
||||
Self::Woff2 => false,
|
||||
|
||||
// Applications
|
||||
Self::Abiword => false,
|
||||
Self::Azw => false,
|
||||
Self::Cda => false,
|
||||
Self::Doc => false,
|
||||
Self::Docx => false,
|
||||
Self::Epub => false,
|
||||
Self::Mpkg => false,
|
||||
Self::Odp => false,
|
||||
Self::Ods => false,
|
||||
Self::Odt => false,
|
||||
Self::Ppt => false,
|
||||
Self::Pptx => false,
|
||||
Self::Vsd => false,
|
||||
Self::Xls => false,
|
||||
Self::Xlsx => false,
|
||||
Self::Xul => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user