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

Function queryMatches

gjson.go:1407–1507  ·  view source on GitHub ↗
(rp *arrayPathResult, value Result)

Source from the content-addressed store, hash-verified

1405}
1406
1407func queryMatches(rp *arrayPathResult, value Result) bool {
1408 rpv := rp.query.value
1409 if len(rpv) > 0 {
1410 if rpv[0] == '~' {
1411 // convert to bool
1412 rpv = rpv[1:]
1413 var ish, ok bool
1414 switch rpv {
1415 case "*":
1416 ish, ok = value.Exists(), true
1417 case "null":
1418 ish, ok = nullish(value), true
1419 case "true":
1420 ish, ok = trueish(value), true
1421 case "false":
1422 ish, ok = falseish(value), true
1423 }
1424 if ok {
1425 rpv = "true"
1426 if ish {
1427 value = Result{Type: True}
1428 } else {
1429 value = Result{Type: False}
1430 }
1431 } else {
1432 rpv = ""
1433 value = Result{}
1434 }
1435 }
1436 }
1437 if !value.Exists() {
1438 return false
1439 }
1440 if rp.query.op == "" {
1441 // the query is only looking for existence, such as:
1442 // friends.#(name)
1443 // which makes sure that the array "friends" has an element of
1444 // "name" that exists
1445 return true
1446 }
1447 switch value.Type {
1448 case String:
1449 switch rp.query.op {
1450 case "=":
1451 return value.Str == rpv
1452 case "!=":
1453 return value.Str != rpv
1454 case "<":
1455 return value.Str < rpv
1456 case "<=":
1457 return value.Str <= rpv
1458 case ">":
1459 return value.Str > rpv
1460 case ">=":
1461 return value.Str >= rpv
1462 case "%":
1463 return matchLimit(value.Str, rpv)
1464 case "!%":

Callers 1

parseArrayFunction · 0.85

Calls 5

nullishFunction · 0.85
trueishFunction · 0.85
falseishFunction · 0.85
matchLimitFunction · 0.85
ExistsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…