summaryrefslogtreecommitdiff
path: root/vendor/github.com/tdewolff
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tdewolff')
-rw-r--r--vendor/github.com/tdewolff/minify/v2/common.go47
-rw-r--r--vendor/github.com/tdewolff/parse/v2/common.go24
-rw-r--r--vendor/github.com/tdewolff/parse/v2/strconv/decimal.go78
-rw-r--r--vendor/github.com/tdewolff/parse/v2/strconv/float.go2
-rw-r--r--vendor/github.com/tdewolff/parse/v2/strconv/int.go40
-rw-r--r--vendor/github.com/tdewolff/parse/v2/strconv/number.go3
6 files changed, 167 insertions, 27 deletions
diff --git a/vendor/github.com/tdewolff/minify/v2/common.go b/vendor/github.com/tdewolff/minify/v2/common.go
index 3773a9b47..8efb5b9f9 100644
--- a/vendor/github.com/tdewolff/minify/v2/common.go
+++ b/vendor/github.com/tdewolff/minify/v2/common.go
@@ -328,7 +328,9 @@ func Number(num []byte, prec int) []byte {
// normExp would be the exponent if it were normalised (0.1 <= f < 1)
n := 0
normExp := 0
- if dot == start {
+ if start == end {
+ return num // no number before exponent
+ } else if dot == start {
for i = dot + 1; i < end; i++ {
if num[i] != '0' {
n = end - i
@@ -404,24 +406,24 @@ func Number(num []byte, prec int) []byte {
} else if zeroes < 0 {
copy(num[start+1:], num[start:dot])
num[start] = '.'
+ } else {
+ return num
}
num[end] = 'e'
num[end+1] = '-'
end += 2
- for i := end + lenNormExp - 1; end <= i; i-- {
+ for i := end + lenNormExp - 2; end <= i; i-- {
num[i] = -byte(normExp%10) + '0'
normExp /= 10
}
- end += lenNormExp
- } else if -lenIntExp-1 <= normExp {
+ end += lenNormExp - 1
+ } else if -lenIntExp <= normExp {
// case 3: print number without exponent
zeroes := -normExp
if 0 < zeroes {
- // dot placed at the front and negative exponent, adding zeroes
- newDot := end - n - zeroes - 1
- if newDot != dot {
- d := start - newDot
- if 0 < d {
+ // place dot at the front, adding zeroes after the dot
+ if newDot := end - n - zeroes - 1; newDot != dot {
+ if d := start - newDot; 0 < d {
if dot < end {
// copy original digits after the dot towards the end
copy(num[dot+1+d:], num[dot+1:end])
@@ -444,18 +446,18 @@ func Number(num []byte, prec int) []byte {
}
}
} else {
- // dot placed in the middle of the number
- if dot == start {
- // when there are zeroes after the dot
- dot = end - n - 1
- start = dot
- } else if end <= dot {
+ // place dot in the middle of the number
+ if end <= dot {
// when input has no dot in it
dot = end
end++
+ } else if dot == start {
+ // when there are zeroes after the dot
+ dot = end - n - 1
+ start = dot
}
- newDot := start + normExp
// move digits between dot and newDot towards the end
+ newDot := start + normExp
if dot < newDot {
copy(num[dot:], num[dot+1:newDot+1])
} else if newDot < dot {
@@ -468,11 +470,11 @@ func Number(num []byte, prec int) []byte {
// find new end, considering moving numbers to the front, removing the dot and increasing the length of the exponent
newEnd := end
if dot == start {
- newEnd = start + n
+ newEnd = dot + n
} else {
newEnd--
}
- newEnd += 2 + lenIntExp
+ newEnd += 1 + lenIntExp
exp := intExp
lenExp := lenIntExp
@@ -490,19 +492,16 @@ func Number(num []byte, prec int) []byte {
} else {
// it does not save space and will panic, so we revert to the original representation
exp = origExp
- lenExp = 1
- if origExp <= -10 || 10 <= origExp {
- lenExp = strconv.LenInt(int64(origExp))
- }
+ lenExp = strconv.LenInt(int64(origExp))
}
num[end] = 'e'
num[end+1] = '-'
end += 2
- for i := end + lenExp - 1; end <= i; i-- {
+ for i := end + lenExp - 2; end <= i; i-- {
num[i] = -byte(exp%10) + '0'
exp /= 10
}
- end += lenExp
+ end += lenExp - 1
}
if neg {
diff --git a/vendor/github.com/tdewolff/parse/v2/common.go b/vendor/github.com/tdewolff/parse/v2/common.go
index 05f881739..68863a5ca 100644
--- a/vendor/github.com/tdewolff/parse/v2/common.go
+++ b/vendor/github.com/tdewolff/parse/v2/common.go
@@ -544,3 +544,27 @@ func DecodeURL(b []byte) []byte {
}
return b
}
+
+func AppendEscape(b, str, chars []byte, escape byte) []byte {
+ i := 0
+ for j := 0; j < len(str); j++ {
+ has := false
+ for _, c := range chars {
+ if c == str[j] {
+ has = true
+ break
+ }
+ }
+ if has || str[j] == escape {
+ if i < j {
+ b = append(b, str[i:j]...)
+ }
+ b = append(b, escape)
+ i = j
+ }
+ }
+ if i < len(str) {
+ b = append(b, str[i:]...)
+ }
+ return b
+}
diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go b/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go
index 788bb9622..137c87936 100644
--- a/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go
+++ b/vendor/github.com/tdewolff/parse/v2/strconv/decimal.go
@@ -69,3 +69,81 @@ func ParseDecimal(b []byte) (float64, int) {
}
return f * math.Pow10(exp), i
}
+
+// AppendDecimal appends a float to `b` with `dec` the maximum number of decimals.
+func AppendDecimal(b []byte, f float64, dec int) []byte {
+ if math.IsNaN(float64(f)) || math.IsInf(float64(f), 0) {
+ return b
+ }
+
+ if dec < 0 || 17 < dec {
+ dec = 17
+ }
+ f *= math.Pow10(dec)
+
+ // correct rounding
+ if 0.0 <= f {
+ f += 0.5
+ } else {
+ f -= 0.5
+ }
+
+ // calculate mantissa and exponent
+ num := int64(f)
+ if num == 0 {
+ return append(b, '0')
+ }
+ for 0 < dec && num%10 == 0 {
+ num /= 10
+ dec-- // remove trailing zeros
+ }
+
+ i, n := len(b), LenInt(num)
+ if 0 < dec {
+ if n < dec {
+ n = dec // number has zero after dot
+ }
+ n++ // dot
+ if lim := int64pow10[dec]; 0 < num && num < lim || num < 0 && -lim < num {
+ n++ // zero at beginning
+ }
+ }
+ if cap(b) < i+n {
+ b = append(b, make([]byte, n)...)
+ } else {
+ b = b[:i+n]
+ }
+
+ // print sign
+ if num < 0 {
+ num = -num
+ b[i] = '-'
+ }
+ i += n - 1
+
+ // print number
+ if 0 < dec {
+ b[i] = byte(num%10) + '0'
+ num /= 10
+ dec--
+ i--
+ for 0 < dec {
+ b[i] = byte(num%10) + '0'
+ num /= 10
+ dec--
+ i--
+ }
+ b[i] = '.'
+ i--
+ }
+ if num == 0 {
+ b[i] = '0'
+ } else {
+ for num != 0 {
+ b[i] = byte(num%10) + '0'
+ num /= 10
+ i--
+ }
+ }
+ return b
+}
diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/float.go b/vendor/github.com/tdewolff/parse/v2/strconv/float.go
index 35558fc98..103db72e0 100644
--- a/vendor/github.com/tdewolff/parse/v2/strconv/float.go
+++ b/vendor/github.com/tdewolff/parse/v2/strconv/float.go
@@ -145,7 +145,7 @@ func AppendFloat(b []byte, f float64, prec int) ([]byte, bool) {
expLen = 1 + LenInt(int64(exp)) // e + digits
} else if mantExp < -3 {
exp = mantExp
- expLen = 2 + LenInt(int64(exp)) // e + minus + digits
+ expLen = 1 + LenInt(int64(exp)) // e + minus + digits
} else if mantExp < -1 {
mantLen += -mantExp - 1 // extra zero between dot and first digit
}
diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/int.go b/vendor/github.com/tdewolff/parse/v2/strconv/int.go
index 2f45d1e21..1e9578eb5 100644
--- a/vendor/github.com/tdewolff/parse/v2/strconv/int.go
+++ b/vendor/github.com/tdewolff/parse/v2/strconv/int.go
@@ -60,13 +60,45 @@ func ParseUint(b []byte) (uint64, int) {
return n, i
}
+// AppendInt will append an int64.
+func AppendInt(b []byte, num int64) []byte {
+ if num == 0 {
+ return append(b, '0')
+ } else if num == -9223372036854775808 {
+ return append(b, "-9223372036854775808"...)
+ }
+
+ // resize byte slice
+ i, n := len(b), LenInt(num)
+ if cap(b) < i+n {
+ b = append(b, make([]byte, n)...)
+ } else {
+ b = b[:i+n]
+ }
+
+ // print sign
+ if num < 0 {
+ num = -num
+ b[i] = '-'
+ }
+ i += n - 1
+
+ // print number
+ for num != 0 {
+ b[i] = byte(num%10) + '0'
+ num /= 10
+ i--
+ }
+ return b
+}
+
// LenInt returns the written length of an integer.
func LenInt(i int64) int {
if i < 0 {
if i == -9223372036854775808 {
- return 19
+ return 20
}
- i = -i
+ return 1 + LenUint(uint64(-i))
}
return LenUint(uint64(i))
}
@@ -114,3 +146,7 @@ func LenUint(i uint64) int {
}
return 20
}
+
+var int64pow10 = []int64{
+ 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000, 100000000000000000, 1000000000000000000,
+}
diff --git a/vendor/github.com/tdewolff/parse/v2/strconv/number.go b/vendor/github.com/tdewolff/parse/v2/strconv/number.go
index eb2a909b2..cc3014cdf 100644
--- a/vendor/github.com/tdewolff/parse/v2/strconv/number.go
+++ b/vendor/github.com/tdewolff/parse/v2/strconv/number.go
@@ -61,6 +61,9 @@ func AppendNumber(b []byte, num int64, dec int, groupSize int, groupSym rune, de
// calculate size
n := LenInt(num)
+ if sign == -1 {
+ n-- // ignore minux sign, add later
+ }
if dec < n && 0 < groupSize && groupSym != 0 {
n += utf8.RuneLen(groupSym) * (n - dec - 1) / groupSize
}