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

Function parseSubSelectors

gjson.go:1925–1983  ·  view source on GitHub ↗

parseSubSelectors returns the subselectors belonging to a '[path1,path2]' or '{"field1":path1,"field2":path2}' type subSelection. It's expected that the first character in path is either '[' or '{', and has already been checked prior to calling this function.

(path string)

Source from the content-addressed store, hash-verified

1923// first character in path is either '[' or '{', and has already been checked
1924// prior to calling this function.
1925func parseSubSelectors(path string) (sels []subSelector, out string, ok bool) {
1926 modifier := 0
1927 depth := 1
1928 colon := 0
1929 start := 1
1930 i := 1
1931 pushSel := func() {
1932 var sel subSelector
1933 if colon == 0 {
1934 sel.path = path[start:i]
1935 } else {
1936 sel.name = path[start:colon]
1937 sel.path = path[colon+1 : i]
1938 }
1939 sels = append(sels, sel)
1940 colon = 0
1941 modifier = 0
1942 start = i + 1
1943 }
1944 for ; i < len(path); i++ {
1945 switch path[i] {
1946 case '\\':
1947 i++
1948 case '@':
1949 if modifier == 0 && i > 0 && (path[i-1] == '.' || path[i-1] == '|') {
1950 modifier = i
1951 }
1952 case ':':
1953 if modifier == 0 && colon == 0 && depth == 1 {
1954 colon = i
1955 }
1956 case ',':
1957 if depth == 1 {
1958 pushSel()
1959 }
1960 case '"':
1961 i++
1962 loop:
1963 for ; i < len(path); i++ {
1964 switch path[i] {
1965 case '\\':
1966 i++
1967 case '"':
1968 break loop
1969 }
1970 }
1971 case '[', '(', '{':
1972 depth++
1973 case ']', ')', '}':
1974 depth--
1975 if depth == 0 {
1976 pushSel()
1977 path = path[i+1:]
1978 return sels, path, true
1979 }
1980 }
1981 }
1982 return

Callers 1

GetFunction · 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…