summaryrefslogtreecommitdiff
path: root/vendor/github.com/tdewolff/parse
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tdewolff/parse')
-rw-r--r--vendor/github.com/tdewolff/parse/v2/binary.go66
-rw-r--r--vendor/github.com/tdewolff/parse/v2/common.go2
-rw-r--r--vendor/github.com/tdewolff/parse/v2/strconv/decimal.go23
3 files changed, 56 insertions, 35 deletions
diff --git a/vendor/github.com/tdewolff/parse/v2/binary.go b/vendor/github.com/tdewolff/parse/v2/binary.go
index 0b2dd8d19..c412bd997 100644
--- a/vendor/github.com/tdewolff/parse/v2/binary.go
+++ b/vendor/github.com/tdewolff/parse/v2/binary.go
@@ -55,6 +55,11 @@ func (r *BinaryReader) Len() uint32 {
return uint32(len(r.buf)) - r.pos
}
+// SetLen sets the remaining length of the underlying buffer.
+func (r *BinaryReader) SetLen(n uint32) {
+ r.buf = r.buf[: r.pos+n : r.pos+n]
+}
+
// EOF returns true if we reached the end-of-file.
func (r *BinaryReader) EOF() bool {
return r.eof
@@ -110,6 +115,18 @@ func (r *BinaryReader) ReadUint16() uint16 {
return r.Endianness.Uint16(b)
}
+// ReadUint24 reads a uint24 into a uint32.
+func (r *BinaryReader) ReadUint24() uint32 {
+ b := r.ReadBytes(3)
+ if b == nil {
+ return 0
+ } else if r.Endianness == binary.LittleEndian {
+ return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16
+ } else {
+ return uint32(b[2]) | uint32(b[1])<<8 | uint32(b[0])<<16
+ }
+}
+
// ReadUint32 reads a uint32.
func (r *BinaryReader) ReadUint32() uint32 {
b := r.ReadBytes(4)
@@ -128,22 +145,27 @@ func (r *BinaryReader) ReadUint64() uint64 {
return r.Endianness.Uint64(b)
}
-// ReadInt8 reads a int8.
+// ReadInt8 reads an int8.
func (r *BinaryReader) ReadInt8() int8 {
return int8(r.ReadByte())
}
-// ReadInt16 reads a int16.
+// ReadInt16 reads an int16.
func (r *BinaryReader) ReadInt16() int16 {
return int16(r.ReadUint16())
}
-// ReadInt32 reads a int32.
+// ReadInt24 reads a int24 into an int32.
+func (r *BinaryReader) ReadInt24() int32 {
+ return int32(r.ReadUint24())
+}
+
+// ReadInt32 reads an int32.
func (r *BinaryReader) ReadInt32() int32 {
return int32(r.ReadUint32())
}
-// ReadInt64 reads a int64.
+// ReadInt64 reads an int64.
func (r *BinaryReader) ReadInt64() int64 {
return int64(r.ReadUint64())
}
@@ -386,8 +408,8 @@ type binaryReaderBytes struct {
data []byte
}
-func newBinaryReaderBytes(data []byte) (*binaryReaderBytes, error) {
- return &binaryReaderBytes{data}, nil
+func newBinaryReaderBytes(data []byte) *binaryReaderBytes {
+ return &binaryReaderBytes{data}
}
// Close closes the reader.
@@ -414,10 +436,10 @@ type binaryReaderReader struct {
seeker bool
}
-func newBinaryReaderReader(r io.Reader, n int64) (*binaryReaderReader, error) {
+func newBinaryReaderReader(r io.Reader, n int64) *binaryReaderReader {
_, readerAt := r.(io.ReaderAt)
_, seeker := r.(io.Seeker)
- return &binaryReaderReader{r, n, readerAt, seeker}, nil
+ return &binaryReaderReader{r, n, readerAt, seeker}
}
// Close closes the reader.
@@ -482,24 +504,20 @@ func NewBinaryReader2Reader(r io.Reader, n int64) (*BinaryReader2, error) {
var f IBinaryReader
if isReaderAt || isSeeker {
- var err error
- f, err = newBinaryReaderReader(r, n)
- if err != nil {
- return nil, err
- }
+ f = newBinaryReaderReader(r, n)
} else {
b := make([]byte, n)
if _, err := io.ReadFull(r, b); err != nil {
return nil, err
}
- f, _ = newBinaryReaderBytes(b)
+ f = newBinaryReaderBytes(b)
}
return NewBinaryReader2(f), nil
}
-func NewBinaryReader2Bytes(data []byte) (*BinaryReader2, error) {
- f, _ := newBinaryReaderBytes(data)
- return NewBinaryReader2(f), nil
+func NewBinaryReader2Bytes(data []byte) *BinaryReader2 {
+ f := newBinaryReaderBytes(data)
+ return NewBinaryReader2(f)
}
func NewBinaryReader2File(filename string) (*BinaryReader2, error) {
@@ -641,12 +659,16 @@ func (r *BinaryReader2) ReadInt64() int64 {
// BinaryWriter is a big endian binary file format writer.
type BinaryWriter struct {
- buf []byte
+ buf []byte
+ Endian binary.ByteOrder
}
// NewBinaryWriter returns a big endian binary file format writer.
func NewBinaryWriter(buf []byte) *BinaryWriter {
- return &BinaryWriter{buf}
+ return &BinaryWriter{
+ buf: buf,
+ Endian: binary.BigEndian,
+ }
}
// Len returns the buffer's length in bytes.
@@ -689,21 +711,21 @@ func (w *BinaryWriter) WriteUint8(v uint8) {
func (w *BinaryWriter) WriteUint16(v uint16) {
pos := len(w.buf)
w.buf = append(w.buf, make([]byte, 2)...)
- binary.BigEndian.PutUint16(w.buf[pos:], v)
+ w.Endian.PutUint16(w.buf[pos:], v)
}
// WriteUint32 writes the given uint32 to the buffer.
func (w *BinaryWriter) WriteUint32(v uint32) {
pos := len(w.buf)
w.buf = append(w.buf, make([]byte, 4)...)
- binary.BigEndian.PutUint32(w.buf[pos:], v)
+ w.Endian.PutUint32(w.buf[pos:], v)
}
// WriteUint64 writes the given uint64 to the buffer.
func (w *BinaryWriter) WriteUint64(v uint64) {
pos := len(w.buf)
w.buf = append(w.buf, make([]byte, 8)...)
- binary.BigEndian.PutUint64(w.buf[pos:], v)
+ w.Endian.PutUint64(w.buf[pos:], v)
}
// WriteInt8 writes the given int8 to the buffer.
diff --git a/vendor/github.com/tdewolff/parse/v2/common.go b/vendor/github.com/tdewolff/parse/v2/common.go
index 1883d1bd4..05f881739 100644
--- a/vendor/github.com/tdewolff/parse/v2/common.go
+++ b/vendor/github.com/tdewolff/parse/v2/common.go
@@ -534,7 +534,7 @@ func DecodeURL(b []byte) []byte {
c = c<<4 + int(b[j]-'a') + 10
}
}
- if j == i+3 && c < 128 {
+ if j == i+3 {
b[i] = byte(c)
b = append(b[:i+1], b[i+3:]...)
}
diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go b/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go
index 8427cb4ac..788bb9622 100644
--- a/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go
+++ b/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go
@@ -8,11 +8,11 @@ import (
func ParseDecimal(b []byte) (float64, int) {
// float64 has up to 17 significant decimal digits and an exponent in [-1022,1023]
i := 0
- //sign := 1.0
- //if 0 < len(b) && b[0] == '-' {
- // sign = -1.0
- // i++
- //}
+ sign := 1.0
+ if 0 < len(b) && b[0] == '-' {
+ sign = -1.0
+ i++
+ }
start := -1
dot := -1
@@ -52,17 +52,16 @@ func ParseDecimal(b []byte) (float64, int) {
exp++
}
if 1023 < exp {
- return math.Inf(1), i
- //if sign == 1.0 {
- // return math.Inf(1), i
- //} else {
- // return math.Inf(-1), i
- //}
+ if sign == 1.0 {
+ return math.Inf(1), i
+ } else {
+ return math.Inf(-1), i
+ }
} else if exp < -1022 {
return 0.0, i
}
- f := float64(n) // sign * float64(n)
+ f := sign * float64(n)
if 0 <= exp && exp < 23 {
return f * float64pow10[exp], i
} else if 23 < exp && exp < 0 {