MCPcopy Create free account
hub / github.com/stretchr/objx / getKey

Function getKey

accessors.go:83–112  ·  view source on GitHub ↗

getKey returns the key which is held in s by two brackets. It also returns the next selector.

(s string)

Source from the content-addressed store, hash-verified

81// getKey returns the key which is held in s by two brackets.
82// It also returns the next selector.
83func getKey(s string) (string, string) {
84 selSegs := strings.SplitN(s, PathSeparator, 2)
85 thisSel := selSegs[0]
86 nextSel := ""
87
88 if len(selSegs) > 1 {
89 nextSel = selSegs[1]
90 }
91
92 mapMatches := mapAccessRegex.FindStringSubmatch(s)
93 if len(mapMatches) > 0 {
94 if _, err := strconv.Atoi(mapMatches[2]); err != nil {
95 thisSel = mapMatches[1]
96 nextSel = "[" + mapMatches[2] + "]" + mapMatches[3]
97
98 if thisSel == "" {
99 thisSel = mapMatches[2]
100 nextSel = mapMatches[3]
101 }
102
103 if nextSel == "" {
104 selSegs = []string{"", ""}
105 } else if nextSel[0] == '.' {
106 nextSel = nextSel[1:]
107 }
108 }
109 }
110
111 return thisSel, nextSel
112}
113
114// access accesses the object using the selector and performs the
115// appropriate action.

Callers 1

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