summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spkg/bom/bom.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spkg/bom/bom.go')
-rw-r--r--vendor/github.com/spkg/bom/bom.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/spkg/bom/bom.go b/vendor/github.com/spkg/bom/bom.go
new file mode 100644
index 000000000..93b811c6d
--- /dev/null
+++ b/vendor/github.com/spkg/bom/bom.go
@@ -0,0 +1,39 @@
+// Package bom is used to clean up UTF-8 Byte Order Marks.
+package bom
+
+import (
+ "bufio"
+ "io"
+)
+
+const (
+ bom0 = 0xef
+ bom1 = 0xbb
+ bom2 = 0xbf
+)
+
+// Clean returns b with the 3 byte BOM stripped off the front if it is present.
+// If the BOM is not present, then b is returned.
+func Clean(b []byte) []byte {
+ if len(b) >= 3 &&
+ b[0] == bom0 &&
+ b[1] == bom1 &&
+ b[2] == bom2 {
+ return b[3:]
+ }
+ return b
+}
+
+// NewReader returns an io.Reader that will skip over initial UTF-8 byte order marks.
+func NewReader(r io.Reader) io.Reader {
+ buf := bufio.NewReader(r)
+ b, err := buf.Peek(3)
+ if err != nil {
+ // not enough bytes
+ return buf
+ }
+ if b[0] == bom0 && b[1] == bom1 && b[2] == bom2 {
+ discardBytes(buf, 3)
+ }
+ return buf
+}