Skip to main content

Module tools

Module tools 

Source
Expand description

Language detection and the file readers.

Enums§

SkipReason
Why read_file_with_eol_classified declined to hand a file’s bytes to the metric engine.

Functions§

get_language_for_file
Detects the language of a code using the extension of a file.
guess_language
Guesses the language of a code.
is_generated
Returns true when buf looks like generated code: its leading window (first ~50 lines or first 5 KiB, whichever is smaller) contains a known marker phrase. Matching is case-insensitive for the marker and never allocates on the negative path.
normalize_eol
Normalises an in-memory source buffer to match the read_file_with_eol on-disk path: all CR-only and CRLF line endings become LF, and the buffer is guaranteed to end with exactly one \n.
normalize_line_endings
Normalises all CR-only and CRLF line endings to LF throughout the buffer, then ensures the buffer ends with exactly one \n.
read_file
Reads a file, normalising all CR-only and CRLF line endings to LF.
read_file_with_eol
Reads a file, normalising all CR-only and CRLF line endings to LF, and ensures the buffer ends with exactly one \n. Returns None for readable files ≤ 3 bytes or files that appear to be non-UTF-8.
read_file_with_eol_classified
Reads a file exactly as read_file_with_eol does, but names the reason when the file is skipped instead of collapsing every skip into None.
write_file
Writes data to a file.