// slice_suffix = '[' expr? ':' expr?  ':' expr? ']'
424032
func (p *parser) parseSliceSuffix(x Expr) Expr {
	lbrack := p.nextToken()
	var lo, hi, step Expr
	if p.tok != COLON {
		y := p.parseExpr(false)

		// index x[y]
		if p.tok == RBRACK {
			rbrack := p.nextToken()
			return &IndexExpr{X: x, Lbrack: lbrack, Y: y, Rbrack: rbrack}
		}

		lo = y
	}

	// slice or substring x[lo:hi:step]
	if p.tok == COLON {
		p.nextToken()
		if p.tok != COLON && p.tok != RBRACK {
			hi = p.parseTest()
		}
	}
	if p.tok == COLON {
		p.nextToken()
		if p.tok != RBRACK {
			step = p.parseTest()
		}
	}
	rbrack := p.consume(RBRACK)
	return &SliceExpr{X: x, Lbrack: lbrack, Lo: lo, Hi: hi, Step: step, Rbrack: rbrack}
}
1277860
func (p *Partial) SliceOfLength(length int) (a []*Partial, err error) {
	err = p.Unmarshal(&a)
	if err != nil {
		return
	}

	if len(a) != length {
		err = errors.New("Invalid array length")
	}

	return
}
55607
func trimPhrase(v, prefix, suffix string) string {
	if !strings.HasPrefix(v, prefix) {
		return ""
	}
	v = strings.TrimPrefix(v, prefix)

	if !strings.HasSuffix(v, suffix) {
		return ""
	}
	return strings.TrimSuffix(v, suffix)
}
498897
func SliceToPath(unit string) (string, error) {
	if unit == "-.slice" {
		return "", nil
	}

	if !strings.HasSuffix(unit, ".slice") {
		return "", fmt.Errorf("not a slice")
	}

	if !sliceNameIsValid(unit) {
		return "", fmt.Errorf("invalid slice name")
	}

	prefix := unitnameToPrefix(unit)

	// don't allow initial dashes
	if prefix[0] == '-' {
		return "", fmt.Errorf("initial dash")
	}

	prefixParts := strings.Split(prefix, "-")

	var curSlice string
	var slicePath string
	for _, slicePart := range prefixParts {
		if slicePart == "" {
			return "", fmt.Errorf("trailing or double dash")
		}

		if curSlice != "" {
			curSlice = curSlice + "-"
		}
		curSlice = curSlice + slicePart

		curSliceDir := curSlice + ".slice"
		escaped := cgEscape(curSliceDir)

		slicePath = filepath.Join(slicePath, escaped)
	}

	return slicePath, nil
}
1186650
func ExpandSlice(slice string) (string, error) {
	suffix := ".slice"
	// Name has to end with ".slice", but can't be just ".slice".
	if len(slice) < len(suffix) || !strings.HasSuffix(slice, suffix) {
		return "", fmt.Errorf("invalid slice name: %s", slice)
	}

	// Path-separators are not allowed.
	if strings.Contains(slice, "/") {
		return "", fmt.Errorf("invalid slice name: %s", slice)
	}

	var path, prefix string
	sliceName := strings.TrimSuffix(slice, suffix)
	// if input was -.slice, we should just return root now
	if sliceName == "-" {
		return "/", nil
	}
	for _, component := range strings.Split(sliceName, "-") {
		// test--a.slice isn't permitted, nor is -test.slice.
		if component == "" {
			return "", fmt.Errorf("invalid slice name: %s", slice)
		}

		// Append the component to the path and to the prefix.
		path += "/" + prefix + component + suffix
		prefix += component + "-"
	}
	return path, nil
}
1086433
func appendIndex(is []int, i int) []int {
	// Make a new slice with capacity for a single additional element.
	x := make([]int, 0, len(is)+1)
	// Append the old slice to the new slice and then append the new
	// element.
	return append(append(x, is...), i)
}
952448
func ParseHandleExtensionSuffix(s string) ([]HandleExtension, error) {
	exts := handleExtensionRegex.FindAllStringSubmatch(s, 2)
	if len(exts) < 1 || len(exts) > 2 {
		return nil, errHandleExtensionInvalidString
	}
	extMap := make(map[HandleExtensionType]bool)
	var extensions []HandleExtension
	for _, e := range exts {
		ext, err := parseHandleExtension(e)
		if err != nil {
			return nil, err
		}
		if extMap[ext.Type] {
			// No duplicate extension types in the same suffix.
			return nil, errHandleExtensionInvalidString
		}
		extMap[ext.Type] = true
		extensions = append(extensions, *ext)
	}
	return extensions, nil
}
422652
func (p *Prompt) Slice(q string, slice []string, def ...int) (selected []int, err error) {
	w := &w{}
	w.println(p.output, colors.Default, q)
	for i, v := range slice {
		c := colors.Default
		if inIntSlice(i, def) {
			c = p.defaultColor
		}
		w.printf(p.output, c, "（%d）", i)
		w.printf(p.output, colors.Default, "%s\n", v)
	}
	w.print(p.output, colors.Default, "请输入你的选择项，多项请用半角逗号（,）分隔：")

	val := w.read(p)
	if w.err != nil {
		return nil, w.err
	}

	if val == "" {
		return def, nil
	}

	for _, v := range strings.Split(val, ",") {
		vv, err := strconv.Atoi(v)
		if err != nil {
			return nil, err
		}
		selected = append(selected, vv)
	}
	return selected, nil
}
346777
func ArgsWithPrefix(args map[string][]string, prefix string) map[string][]string {
	filtered := map[string][]string{}
	for key, slice := range args {
		if !strings.HasPrefix(key, prefix) {
			continue
		}
		for _, val := range slice {
			filtered[key] = append(filtered[key], val)
		}
	}
	return filtered
}
1298125
func Slice(slice interface{}) {
	rv := reflect.ValueOf(slice)
	swap := reflect.Swapper(slice)
	rand.Shuffle(rv.Len(), swap)
}
1312916
func indexInSlice(slice []*html.Node, node *html.Node) int {
	if node != nil {
		for i, n := range slice {
			if n == node {
				return i
			}
		}
	}
	return -1
}
1171946
func SliceOf(in interface{}) interface{} {
	value := reflect.ValueOf(in)

	sliceType := reflect.SliceOf(reflect.TypeOf(in))
	slice := reflect.New(sliceType)
	sliceValue := reflect.MakeSlice(sliceType, 0, 0)
	sliceValue = reflect.Append(sliceValue, value)
	slice.Elem().Set(sliceValue)

	return slice.Elem().Interface()
}
160370
func Slice(slice interface{}) {
	rv := reflect.ValueOf(slice)
	swap := reflect.Swapper(slice)
	n := rv.Len()
	for i := n - 1; i >= 0; i-- {
		j := rand.Intn(i + 1)
		swap(i, j)
	}
}
509604
func (dec *Decoder) SliceString(s *[]string) error {
	err := dec.Array(DecodeArrayFunc(func(dec *Decoder) error {
		var str string
		if err := dec.String(&str); err != nil {
			return err
		}
		*s = append(*s, str)
		return nil
	}))

	if err != nil {
		return err
	}
	return nil
}
836669
func getPrefixesFromCIDR(cidrs api.CIDRSlice) []*net.IPNet {
	result, _ := ip.ParseCIDRs(cidrs.StringSlice())
	return result
}
581904
func extractSection(s string, start, end rune) (prefix, body, suffix string, found bool) {
	s = trim(s)
	if strings.HasPrefix(s, string(start)) {
		// no prefix
		body = s[1:]
	} else {
		a := strings.SplitN(s, string(start), 2)
		if len(a) != 2 {
			return "", "", s, false
		}
		prefix = a[0]
		body = a[1]
	}
	a := strings.SplitN(body, string(end), 2)
	if len(a) != 2 {
		return "", "", "", false
	}
	return prefix, a[0], a[1], true
}
601286
func InterfaceSlice(slice interface{}) []interface{} {
	s := reflect.ValueOf(slice)
	if s.Kind() != reflect.Slice {
		panic("InterfaceSlice() given a non-slice type")
	}

	ret := make([]interface{}, s.Len())

	for i := 0; i < s.Len(); i++ {
		ret[i] = s.Index(i).Interface()
	}

	return ret
}