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

Method Int

gjson.go:125–148  ·  view source on GitHub ↗

Int returns an integer representation.

()

Source from the content-addressed store, hash-verified

123
124// Int returns an integer representation.
125func (t Result) Int() int64 {
126 switch t.Type {
127 default:
128 return 0
129 case True:
130 return 1
131 case String:
132 n, _ := parseInt(t.Str)
133 return n
134 case Number:
135 // try to directly convert the float64 to int64
136 i, ok := safeInt(t.Num)
137 if ok {
138 return i
139 }
140 // now try to parse the raw string
141 i, ok = parseInt(t.Raw)
142 if ok {
143 return i
144 }
145 // fallback to a standard conversion
146 return int64(t.Num)
147 }
148}
149
150// Uint returns an unsigned integer representation.
151func (t Result) Uint() uint64 {

Callers 15

TestRandomDataFunction · 0.80
TestRandomValidStringsFunction · 0.80
TestPlus53BitIntsFunction · 0.80
TestTypesFunction · 0.80
TestBasic1Function · 0.80
TestRandomManyFunction · 0.80
makeRandomJSONCharsFunction · 0.80
TestValidRandomFunction · 0.80
TestParenQueriesFunction · 0.80
TestIssue141Function · 0.80
TestEncodedQueryStringFunction · 0.80
TestNaNInfFunction · 0.80

Calls 2

parseIntFunction · 0.85
safeIntFunction · 0.85

Tested by 14

TestRandomDataFunction · 0.64
TestRandomValidStringsFunction · 0.64
TestPlus53BitIntsFunction · 0.64
TestTypesFunction · 0.64
TestBasic1Function · 0.64
TestRandomManyFunction · 0.64
makeRandomJSONCharsFunction · 0.64
TestValidRandomFunction · 0.64
TestParenQueriesFunction · 0.64
TestIssue141Function · 0.64
TestEncodedQueryStringFunction · 0.64
TestNaNInfFunction · 0.64