Module text

Module text 

Source
Expand description

Text and character encoding detection subsystem ported from file (ascmagic.c, encoding.c) and PolyFile.

Provides comprehensive character set identification (UTF-8, UTF-16, UTF-32, ASCII, ISO-8859, non-ISO extended ASCII, EBCDIC), line ending and layout profiling, and text language and syntax heuristics (shebang, programming languages, markup, mail headers).

Structs§

TextProfile
Comprehensive profile of detected text properties and layout conventions.

Enums§

IdentifiedEncoding
Identified character set encoding family.
TextSyntaxKind
Syntax or programming language classification deduced from text content.

Constants§

MAX_LINE_LENGTH
Longest line length considered sane before flagging long lines. Ported from MAXLINELEN in ascmagic.c.
TEXT_ENCODING_MAX_BYTES
Maximum number of bytes inspected for text encoding detection. Ported from FILE_ENCODING_MAX in file.h.

Statics§

EBCDIC_TO_ASCII
EBCDIC-to-ASCII mapping table ported from ebcdic_to_ascii in encoding.c. Based on POSIX P1003.2 draft 11.2 dd(1) rationale.
TEXT_CHARS
Character class table ported from text_chars in encoding.c. Maps each 8-bit byte value to its text membership class.

Functions§

detect_text_candidate
Performs complete text detection on a data source, returning a candidate if text is confirmed.
detect_text_candidate_and_encoding
Performs complete text detection on a data source, returning a candidate if text is confirmed, together with the FormatId of the detected character encoding itself (without syntax-format overrides). The encoding format ID lets callers reason about encoding entailment (e.g. corroborating an extension candidate whose format implies a specific encoding); it is None when the detected encoding has no exact format catalog mapping.
detect_text_encoding
Identifies the character set encoding family of data. Ported from file_encoding in encoding.c.
detect_text_syntax
Detects programming languages, markup formats, and syntax patterns.
format_text_description
Formats the final description string with file parity.
looks_ascii
Checks whether buf consists solely of valid 7-bit ASCII text characters.
looks_ebcdic
Evaluates whether buf is EBCDIC text using the POSIX dd translation table.
looks_extended_ascii
Evaluates whether buf is non-ISO 8-bit extended ASCII (CP437, MacRoman, Windows-1252).
looks_iso8859
Evaluates whether buf is ISO-8859 text (characters in ASCII text or 0xA0..=0xFF).
looks_utf8
Evaluates whether buf is valid UTF-8 text.
looks_utf16
Evaluates whether buf is UTF-16 text (with or without BOM, LE or BE).
looks_utf32
Evaluates whether buf is UTF-32 text (with or without BOM, LE or BE).
profile_text_layout
Profiles text layout conventions, line endings, long lines, and escape sequences. Ported from file_ascmagic_with_encoding in ascmagic.c.
trim_nuls
Trims trailing NUL bytes while preserving parity for UTF-16 character boundaries. Ported from trim_nuls in ascmagic.c.