(encoding: &str)
| 452 | const UTF_32_NE: Self = Self::Utf32Be; |
| 453 | |
| 454 | fn parse(encoding: &str) -> Option<Self> { |
| 455 | if let Some(encoding) = encoding.to_lowercase().strip_prefix("utf") { |
| 456 | let encoding = encoding |
| 457 | .strip_prefix(|c| ['-', '_'].contains(&c)) |
| 458 | .unwrap_or(encoding); |
| 459 | if encoding == "8" { |
| 460 | Some(Self::Utf8) |
| 461 | } else if let Some(encoding) = encoding.strip_prefix("16") { |
| 462 | if encoding.is_empty() { |
| 463 | return Some(Self::UTF_16_NE); |
| 464 | } |
| 465 | let encoding = encoding.strip_prefix(['-', '_']).unwrap_or(encoding); |
| 466 | match encoding { |
| 467 | "be" => Some(Self::Utf16Be), |
| 468 | "le" => Some(Self::Utf16Le), |
| 469 | _ => None, |
| 470 | } |
| 471 | } else if let Some(encoding) = encoding.strip_prefix("32") { |
| 472 | if encoding.is_empty() { |
| 473 | return Some(Self::UTF_32_NE); |
| 474 | } |
| 475 | let encoding = encoding.strip_prefix(['-', '_']).unwrap_or(encoding); |
| 476 | match encoding { |
| 477 | "be" => Some(Self::Utf32Be), |
| 478 | "le" => Some(Self::Utf32Le), |
| 479 | _ => None, |
| 480 | } |
| 481 | } else { |
| 482 | None |
| 483 | } |
| 484 | } else if encoding == "cp65001" { |
| 485 | Some(Self::Utf8) |
| 486 | } else { |
| 487 | None |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | struct SurrogatePass; |
no test coverage detected