MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / checkBOM

Method checkBOM

xmlparser/decoder.go:181–208  ·  view source on GitHub ↗

checkBOM checks for a Byte Order Mark (BOM) at the start of the stream and adjusts the reader accordingly.

()

Source from the content-addressed store, hash-verified

179// checkBOM checks for a Byte Order Mark (BOM) at the start of the stream
180// and adjusts the reader accordingly.
181func (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.
211func (d *Decoder) readText() []byte {

Callers 1

NewDecoderFunction · 0.95

Calls 3

discardMethod · 0.95
setEncodingMethod · 0.95
PeekMethod · 0.65

Tested by

no test coverage detected