Skip to content

TEncoding.GetBufferEncoding

Attempt to guess the encoding of a buffer.

Declaration

Source position: sysencodingh.inc line 76

public 
class function GetBufferEncoding(const Buffer: TBytes; 
                                var AEncoding: TEncoding) : Integer
                                ;  overload;  static; overload;

class function GetBufferEncoding(const Buffer: TBytes; 
                                var AEncoding: TEncoding; 
                                ADefaultEncoding: TEncoding) : Integer
                                ;  overload;  static; overload;

Description

GetBufferEncoding checks the BOM marker of an array of bytes Buffer, and returns the found encoding in AEncoding. Only the TEncoding.BigEndianUnicodeTEncoding.Unicode and TEncoding.UTF8 encodings will be tried.

If AEncoding is non-Nil on entry, it will be used to check the BOM marker with. No other encoding will be tried in that case.

If ADefaultEncoding is specified, it will be returned in case no match was found.

The function returns the number of bytes in the BOM Marker.

See also

Name Description
TEncoding.BigEndianUnicode Big-endian Unicode (UTF16BE) encoding instance.
TEncoding.Unicode UTF16 encoding instance.
TEncoding.UTF8 UTF8 encoding instance.
TEncoding.GetPreamble Return the BOM Marker used by the encoding.