func ParsePath()

in llpath/path.go [170:201]


func ParsePath(in string) (p Path, err error) {
	keyParts := strings.Split(in, ".")

	// We return empty paths for empty strings
	// Empty paths are valid when working with scalar values
	if in == "" {
		return Path{}, nil
	}

	p = make(Path, len(keyParts))
	for idx, part := range keyParts {
		r := arrMatcher.FindStringSubmatch(part)
		pc := PathComponent{Index: -1}
		if len(r) > 0 {
			pc.Type = pcSliceIdx
			// Cannot fail, validated by regexp already
			pc.Index, err = strconv.Atoi(r[1])
			if err != nil {
				return p, err
			}
		} else if len(part) > 0 {
			pc.Type = pcMapKey
			pc.Key = part
		} else {
			return nil, InvalidPathString(in)
		}

		p[idx] = pc
	}

	return p, nil
}