Detect the encoding of file content. Simple heuristic: if the content contains null bytes, it's binary. Otherwise, check if it's valid UTF-8.
(content: &[u8])
| 425 | /// Simple heuristic: if the content contains null bytes, it's binary. |
| 426 | /// Otherwise, check if it's valid UTF-8. |
| 427 | fn detect_encoding(content: &[u8]) -> Encoding { |
| 428 | if content.contains(&0) { |
| 429 | Encoding::Binary |
| 430 | } else if std::str::from_utf8(content).is_ok() { |
| 431 | Encoding::Utf8 |
| 432 | } else { |
| 433 | Encoding::Binary |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | // ═══════════════════════════════════════════════════════════════════════ |
| 438 | // regenerate_change — the main regeneration function |
no test coverage detected