MCPcopy Index your code
hub / github.com/tidwall/gjson / parseQuery

Function parseQuery

gjson.go:857–937  ·  view source on GitHub ↗

splitQuery takes a query and splits it into three parts: path, op, middle, and right. So for this query: #(first_name=="Murphy").last Becomes first_name # path =="Murphy" # middle .last # right Or, #(service_roles.#(=="one")).cap Becomes service_roles.#(=="one") # path

(query string)

Source from the content-addressed store, hash-verified

855// # middle
856// .cap # right
857func parseQuery(query string) (
858 path, op, value, remain string, i int, vesc, ok bool,
859) {
860 if len(query) < 2 || query[0] != '#' ||
861 (query[1] != '(' && query[1] != '[') {
862 return "", "", "", "", i, false, false
863 }
864 i = 2
865 j := 0 // start of value part
866 depth := 1
867 for ; i < len(query); i++ {
868 if depth == 1 && j == 0 {
869 switch query[i] {
870 case '!', '=', '<', '>', '%':
871 // start of the value part
872 j = i
873 continue
874 }
875 }
876 if query[i] == '\\' {
877 i++
878 } else if query[i] == '[' || query[i] == '(' {
879 depth++
880 } else if query[i] == ']' || query[i] == ')' {
881 depth--
882 if depth == 0 {
883 break
884 }
885 } else if query[i] == '"' {
886 // inside selector string, balance quotes
887 i++
888 for ; i < len(query); i++ {
889 if query[i] == '\\' {
890 vesc = true
891 i++
892 } else if query[i] == '"' {
893 break
894 }
895 }
896 }
897 }
898 if depth > 0 {
899 return "", "", "", "", i, false, false
900 }
901 if j > 0 {
902 path = trim(query[2:j])
903 value = trim(query[j:i])
904 remain = query[i+1:]
905 // parse the compare op from the value
906 var opsz int
907 switch {
908 case len(value) == 1:
909 opsz = 1
910 case value[0] == '!' && value[1] == '=':
911 opsz = 2
912 case value[0] == '!' && value[1] == '%':
913 opsz = 2
914 case value[0] == '<' && value[1] == '=':

Callers 2

TestParseQueryFunction · 0.85
parseArrayPathFunction · 0.85

Calls 1

trimFunction · 0.85

Tested by 1

TestParseQueryFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…