checkBOM checks for a Byte Order Mark (BOM) at the start of the stream and adjusts the reader accordingly.
()
| 179 | // checkBOM checks for a Byte Order Mark (BOM) at the start of the stream |
| 180 | // and adjusts the reader accordingly. |
| 181 | func (d *Decoder) checkBOM() { |
| 182 | b, err := d.r.Peek(4) |
| 183 | if err != nil { |
| 184 | return |
| 185 | } |
| 186 | |
| 187 | switch { |
| 188 | case bytes.HasPrefix(b, []byte{0xEF, 0xBB, 0xBF}): |
| 189 | // It's UTF-8 BOM, nothing to do but skip it. |
| 190 | d.discard(3) |
| 191 | case bytes.HasPrefix(b, []byte{0x00, 0x00, 0xFE, 0xFF}): |
| 192 | // UTF-32 BE |
| 193 | d.discard(4) |
| 194 | d.setEncoding("utf-32be") |
| 195 | case bytes.HasPrefix(b, []byte{0xFF, 0xFE, 0x00, 0x00}): |
| 196 | // UTF-32 LE |
| 197 | d.discard(4) |
| 198 | d.setEncoding("utf-32le") |
| 199 | case bytes.HasPrefix(b, []byte{0xFE, 0xFF}): |
| 200 | // UTF-16 BE |
| 201 | d.discard(2) |
| 202 | d.setEncoding("utf-16be") |
| 203 | case bytes.HasPrefix(b, []byte{0xFF, 0xFE}): |
| 204 | // UTF-16 LE |
| 205 | d.discard(2) |
| 206 | d.setEncoding("utf-16le") |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // readText reads text until the `<` character or EOF. |
| 211 | func (d *Decoder) readText() []byte { |
no test coverage detected