// BOMOverride returns a new decoder transformer that is identical to fallback, // except that the presence of a Byte Order Mark at the start of the input // causes it to switch to the corresponding Unicode decoding. It will only // consider BOMs for UTF-8, UTF-16BE, and UTF-16LE. // // This differs from using ExpectBOM by allowing a BOM to switch to UTF-8, not // just UTF-16 variants, and allowing falling back to any encoding scheme. // // This technique is recommended by the W3C for use in HTML 5: "For // compatibility with deployed content, the byte order mark (also known as BOM) // is considered more authoritative than anything else." // http://www.w3.org/TR/encoding/#specification-hooks // // Using BOMOverride is mostly intended for use cases where the first characters // of a fallback encoding are known to not be a BOM, for example, for valid HTML // and most encodings. func BOMOverride(fallback transform.Transformer) transform.Transformer { … } type bomOverride … func (d *bomOverride) Reset() { … } var utf16le … var utf16be … const utf8BOM … func (d *bomOverride) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { … }