MCPcopy
hub / github.com/tidwall/gjson / parseInt

Function parseInt

gjson.go:2782–2803  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

2780}
2781
2782func parseInt(s string) (n int64, ok bool) {
2783 var i int
2784 var sign bool
2785 if len(s) > 0 && s[0] == '-' {
2786 sign = true
2787 i++
2788 }
2789 if i == len(s) {
2790 return 0, false
2791 }
2792 for ; i < len(s); i++ {
2793 if s[i] >= '0' && s[i] <= '9' {
2794 n = n*10 + int64(s[i]-'0')
2795 } else {
2796 return 0, false
2797 }
2798 }
2799 if sign {
2800 return n * -1, true
2801 }
2802 return n, true
2803}
2804
2805// safeInt validates a given JSON number
2806// ensures it lies within the minimum and maximum representable JSON numbers

Callers 1

IntMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…