MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / FormatPath

Function FormatPath

pkg/ijson/ijson.go:141–168  ·  view source on GitHub ↗
(path Path)

Source from the content-addressed store, hash-verified

139var simplePathStrRe = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
140
141func FormatPath(path Path) string {
142 if len(path) == 0 {
143 return "$"
144 }
145 var buf bytes.Buffer
146 buf.WriteByte('$')
147 for _, elem := range path {
148 switch elem := elem.(type) {
149 case string:
150 if simplePathStrRe.MatchString(elem) {
151 buf.WriteByte('.')
152 buf.WriteString(elem)
153 } else {
154 buf.WriteByte('[')
155 buf.WriteString(strconv.Quote(elem))
156 buf.WriteByte(']')
157 }
158 case int:
159 buf.WriteByte('[')
160 buf.WriteString(strconv.Itoa(elem))
161 buf.WriteByte(']')
162 default:
163 // a placeholder for a bad value
164 buf.WriteString(".*")
165 }
166 }
167 return buf.String()
168}
169
170type pathWithPos struct {
171 Path Path

Callers 4

MakePathTypeErrorFunction · 0.85
MakePathErrorFunction · 0.85
MakeSetTypeErrorFunction · 0.85
MakeBudgetErrorFunction · 0.85

Calls 2

WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected