1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-05-22 10:15:43 +02:00
Files
lazygit/vendor/github.com/buger/jsonparser/bytes.go
T
dependabot[bot] 3b9177c919 Bump github.com/buger/jsonparser from 1.1.1 to 1.1.2
Bumps [github.com/buger/jsonparser](https://github.com/buger/jsonparser) from 1.1.1 to 1.1.2.
- [Release notes](https://github.com/buger/jsonparser/releases)
- [Commits](https://github.com/buger/jsonparser/compare/v1.1.1...v1.1.2)

---
updated-dependencies:
- dependency-name: github.com/buger/jsonparser
  dependency-version: 1.1.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-30 14:19:07 +02:00

48 lines
852 B
Go

package jsonparser
const absMinInt64 = 1 << 63
const maxInt64 = 1<<63 - 1
const maxUint64 = 1<<64 - 1
// About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON
func parseInt(bytes []byte) (v int64, ok bool, overflow bool) {
if len(bytes) == 0 {
return 0, false, false
}
var neg bool = false
if bytes[0] == '-' {
neg = true
bytes = bytes[1:]
}
var n uint64 = 0
for _, c := range bytes {
if c < '0' || c > '9' {
return 0, false, false
}
if n > maxUint64/10 {
return 0, false, true
}
n *= 10
n1 := n + uint64(c-'0')
if n1 < n {
return 0, false, true
}
n = n1
}
if n > maxInt64 {
if neg && n == absMinInt64 {
return -absMinInt64, true, false
}
return 0, false, true
}
if neg {
return -int64(n), true, false
} else {
return int64(n), true, false
}
}