parsePath parses an XPath-like string describing a path through an element tree and returns a slice of segment descriptors.
(path string)
| 225 | // through an element tree and returns a slice of segment |
| 226 | // descriptors. |
| 227 | func (c *compiler) parsePath(path string) []segment { |
| 228 | // If path ends with //, fix it |
| 229 | if strings.HasSuffix(path, "//") { |
| 230 | path += "*" |
| 231 | } |
| 232 | |
| 233 | var segments []segment |
| 234 | |
| 235 | // Check for an absolute path |
| 236 | if strings.HasPrefix(path, "/") { |
| 237 | segments = append(segments, segment{new(selectRoot), []filter{}}) |
| 238 | path = path[1:] |
| 239 | } |
| 240 | |
| 241 | // Split path into segments |
| 242 | for _, s := range splitPath(path) { |
| 243 | segments = append(segments, c.parseSegment(s)) |
| 244 | if c.err != ErrPath("") { |
| 245 | break |
| 246 | } |
| 247 | } |
| 248 | return segments |
| 249 | } |
| 250 | |
| 251 | func splitPath(path string) []string { |
| 252 | var pieces []string |
no test coverage detected