smithay_clipboard/
mime.rs1pub static ALLOWED_MIME_TYPES: [&str; 3] =
3 ["text/plain;charset=utf-8", "UTF8_STRING", "text/plain"];
4
5#[derive(Clone, Copy, Eq, PartialEq, Debug)]
7pub enum MimeType {
8 TextPlainUtf8 = 0,
12 Utf8String = 1,
17 TextPlain = 2,
21}
22
23impl MimeType {
24 pub fn find_allowed(offered_mime_types: &[String]) -> Option<Self> {
29 let mut fallback = None;
30 for offered_mime_type in offered_mime_types.iter() {
31 if offered_mime_type == ALLOWED_MIME_TYPES[Self::TextPlainUtf8 as usize] {
32 return Some(Self::TextPlainUtf8);
33 } else if offered_mime_type == ALLOWED_MIME_TYPES[Self::Utf8String as usize] {
34 return Some(Self::Utf8String);
35 } else if offered_mime_type == ALLOWED_MIME_TYPES[Self::TextPlain as usize] {
36 fallback = Some(Self::TextPlain);
38 }
39 }
40
41 fallback
42 }
43}
44
45impl std::fmt::Display for MimeType {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 write!(f, "{}", ALLOWED_MIME_TYPES[*self as usize])
48 }
49}
50
51pub fn normalize_to_lf(text: String) -> String {
57 text.replace("\r\n", "\n").replace('\r', "\n")
58}