MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / detect_encoding

Function detect_encoding

atomic-repository/src/semantic_regen.rs:427–435  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

425/// Simple heuristic: if the content contains null bytes, it's binary.
426/// Otherwise, check if it's valid UTF-8.
427fn 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

Callers 1

tokenize_single_fileFunction · 0.70

Calls 1

containsMethod · 0.45

Tested by

no test coverage detected