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

Function parseAny

gjson.go:2376–2449  ·  view source on GitHub ↗

parseAny parses the next value from a json string. A Result is returned when the hit param is set. The return values are (i int, res Result, ok bool)

(json string, i int, hit bool)

Source from the content-addressed store, hash-verified

2374// A Result is returned when the hit param is set.
2375// The return values are (i int, res Result, ok bool)
2376func parseAny(json string, i int, hit bool) (int, Result, bool) {
2377 var res Result
2378 var val string
2379 for ; i < len(json); i++ {
2380 if json[i] == '{' || json[i] == '[' {
2381 i, val = parseSquash(json, i)
2382 if hit {
2383 res.Raw = val
2384 res.Type = JSON
2385 }
2386 var tmp parseContext
2387 tmp.value = res
2388 fillIndex(json, &tmp)
2389 return i, tmp.value, true
2390 }
2391 if json[i] <= ' ' {
2392 continue
2393 }
2394 var num bool
2395 switch json[i] {
2396 case '"':
2397 i++
2398 var vesc bool
2399 var ok bool
2400 i, val, vesc, ok = parseString(json, i)
2401 if !ok {
2402 return i, res, false
2403 }
2404 if hit {
2405 res.Type = String
2406 res.Raw = val
2407 if vesc {
2408 res.Str = unescape(val[1 : len(val)-1])
2409 } else {
2410 res.Str = val[1 : len(val)-1]
2411 }
2412 }
2413 return i, res, true
2414 case 'n':
2415 if i+1 < len(json) && json[i+1] != 'u' {
2416 num = true
2417 break
2418 }
2419 fallthrough
2420 case 't', 'f':
2421 vc := json[i]
2422 i, val = parseLiteral(json, i)
2423 if hit {
2424 res.Raw = val
2425 switch vc {
2426 case 't':
2427 res.Type = True
2428 case 'f':
2429 res.Type = False
2430 }
2431 return i, res, true
2432 }
2433 case '+', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',

Callers 3

ForEachMethod · 0.85
parseArrayFunction · 0.85
ForEachLineFunction · 0.85

Calls 6

parseSquashFunction · 0.85
fillIndexFunction · 0.85
parseStringFunction · 0.85
unescapeFunction · 0.85
parseLiteralFunction · 0.85
parseNumberFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…