[chore] update dependencies (#4188)

Update dependencies:
- github.com/gin-gonic/gin v1.10.0 -> v1.10.1
- github.com/gin-contrib/sessions v1.10.3 -> v1.10.4
- github.com/jackc/pgx/v5 v5.7.4 -> v5.7.5
- github.com/minio/minio-go/v7 v7.0.91 -> v7.0.92
- github.com/pquerna/otp v1.4.0 -> v1.5.0
- github.com/tdewolff/minify/v2 v2.23.5 -> v2.23.8
- github.com/yuin/goldmark v1.7.11 -> v1.7.12
- go.opentelemetry.io/otel{,/*} v1.35.0 -> v1.36.0
- modernc.org/sqlite v1.37.0 -> v1.37.1

Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4188
Reviewed-by: Daenney <daenney@noreply.codeberg.org>
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2025-05-22 16:27:55 +02:00 committed by kim
commit b6ff55662e
214 changed files with 44839 additions and 32023 deletions

View file

@ -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 {

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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,
}

View file

@ -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
}