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§
- Text
Profile - Comprehensive profile of detected text properties and layout conventions.
Enums§
- Identified
Encoding - Identified character set encoding family.
- Text
Syntax Kind - Syntax or programming language classification deduced from text content.
Constants§
- MAX_
LINE_ LENGTH - Longest line length considered sane before flagging long lines.
Ported from
MAXLINELENinascmagic.c. - TEXT_
ENCODING_ MAX_ BYTES - Maximum number of bytes inspected for text encoding detection.
Ported from
FILE_ENCODING_MAXinfile.h.
Statics§
- EBCDIC_
TO_ ASCII - EBCDIC-to-ASCII mapping table ported from
ebcdic_to_asciiinencoding.c. Based on POSIX P1003.2 draft 11.2dd(1)rationale. - TEXT_
CHARS - Character class table ported from
text_charsinencoding.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
FormatIdof 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 isNonewhen the detected encoding has no exact format catalog mapping. - detect_
text_ encoding - Identifies the character set encoding family of
data. Ported fromfile_encodinginencoding.c. - detect_
text_ syntax - Detects programming languages, markup formats, and syntax patterns.
- format_
text_ description - Formats the final description string with
fileparity. - looks_
ascii - Checks whether
bufconsists solely of valid 7-bit ASCII text characters. - looks_
ebcdic - Evaluates whether
bufis EBCDIC text using the POSIX dd translation table. - looks_
extended_ ascii - Evaluates whether
bufis non-ISO 8-bit extended ASCII (CP437,MacRoman, Windows-1252). - looks_
iso8859 - Evaluates whether
bufis ISO-8859 text (characters in ASCII text or 0xA0..=0xFF). - looks_
utf8 - Evaluates whether
bufis valid UTF-8 text. - looks_
utf16 - Evaluates whether
bufis UTF-16 text (with or without BOM, LE or BE). - looks_
utf32 - Evaluates whether
bufis 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_encodinginascmagic.c. - trim_
nuls - Trims trailing NUL bytes while preserving parity for UTF-16 character boundaries.
Ported from
trim_nulsinascmagic.c.