TEncoding.GetBufferEncoding

Attempt to guess the encoding of a buffer

Declaration

Source position: sysencodingh.inc line 64

public 
  class function GetBufferEncoding(const Buffer: TBytes; 
                                  var AEncoding: TEncoding) : Integer
                                  ;  Overload;  Static;
  class function GetBufferEncoding(const Buffer: TBytes; 
                                  var AEncoding: TEncoding; 
                                  ADefaultEncoding: TEncoding) : Integer
                                  ;  Overload;  Static;

Description

GetBufferEncoding checks the BOM marker of an array of bytes Buffer, and returns the found encoding in AEncoding. Only the TEncoding.BigEndianUnicode TEncoding.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.GetPreamble Return the BOM Marker used by the encoding
TEncoding.Unicode UTF16 encoding instance
TEncoding.UTF8 UTF8 encoding instance