static ALLOWED_MIME_TYPES: [&str; 2] = ["text/plain;charset=utf-8", "UTF8_STRING"];
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub enum MimeType {
TextPlainUtf8 = 0,
Utf8String = 1,
}
impl MimeType {
pub fn find_allowed(offered_mime_types: &[String]) -> Option<Self> {
for offered_mime_type in offered_mime_types.iter() {
if offered_mime_type == ALLOWED_MIME_TYPES[Self::TextPlainUtf8 as usize] {
return Some(Self::TextPlainUtf8);
} else if offered_mime_type == ALLOWED_MIME_TYPES[Self::Utf8String as usize] {
return Some(Self::Utf8String);
}
}
None
}
}
impl ToString for MimeType {
fn to_string(&self) -> String {
String::from(ALLOWED_MIME_TYPES[*self as usize])
}
}
pub fn normilize_to_lf(text: String) -> String {
text.replace("\r\n", "\n").replace("\r", "\n")
}