(path Path)
| 139 | var simplePathStrRe = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`) |
| 140 | |
| 141 | func 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 | |
| 170 | type pathWithPos struct { |
| 171 | Path Path |
no test coverage detected