All Manuals > LispWorks® User Guide and Reference Manual > 47 The SYSTEM Package

*file-encoding-detection-algorithm* Variable

Summary

List of functions to call to work out an encoding.

Package

system

Initial Value
(find-filename-pattern-encoding-match
 find-encoding-option
 detect-utf32-bom
 detect-unicode-bom
 detect-utf8-bom
 specific-valid-file-encoding
 locale-file-encoding)
Description

The variable *file-encoding-detection-algorithm* contains a list of functions to call to work out an encoding for a file.

Functions on this list take four arguments—the pathname of the file; an external format spec; a vector of element-type (unsigned-byte 8) which contains the first bytes of the file; and a non-negative integer which is the maximum extent of buffer to be searched. This length argument is 0 in the case that the file does not exist, or the direction is :output. They return an external format spec, which normally is either ef-spec unmodified, or the result of merging ef-spec with another external format spec via merge-ef-specs.

See the entry for guess-external-format for details of how *file-encoding-detection-algorithm* is used.

Notes

For files starting with 0xff 0xfe 0x00 0x00, both detect-utf32-bom and detect-unicode-bom may match it. detect-utf32-bom is called first so by default the encoding will be detected as (:utf-32 :little-endian t). You can change this behavior by setting *file-encoding-detection-algorithm* to a re-ordered list.

Examples

If you want open and so on, when opening a file for input, to inspect the attribute line and then fall back to a default if no attribute line is found, then set the variable to this value:

(find-encoding-option locale-file-encoding)

There are further examples in 26.6.3.3 Guessing the external format.

See also

find-filename-pattern-encoding-match
find-encoding-option
detect-unicode-bom
detect-japanese-encoding-in-file
guess-external-format
locale-file-encoding


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:31:02