// SliceToString converts a slice of strings into a natural-language list with
// appropriately placed commas and a custom and/or separator.
6596
func SliceToString(ss []string, andor string) string {
	l := len(ss)
	if l == 0 {
		return ""
	}
	if l == 1 {
		return ss[0]
	}
	if l == 2 {
		if andor == "." {
			tmp := strings.Title(ss[1][:1]) + ss[1][1:]
			return fmt.Sprintf("%s%s %s", ss[0], andor, tmp)
		}
		return fmt.Sprintf("%s %s %s", ss[0], andor, ss[1])
	}
	var ret string
	// TODO handle andor == "."
	for i, s := range ss {
		if i == l-2 {
			ret += fmt.Sprintf("%s %s", s, andor)
		} else if i == l-1 {
			ret += " " + s
		} else {
			ret += s + ", "
		}
	}
	return ret
}
236925
func ValueToStrings(val Value) ([]string, bool) {
	if val == nil || val.Err() {
		return nil, false
	}
	switch v := val.(type) {
	case StringValue:
		return []string{v.Val()}, true
	case TimeValue:
		return []string{fmt.Sprintf("%v", v.Val())}, true
	case ByteSliceValue:
		return []string{string(v.Val())}, true
	case NumericValue, BoolValue, IntValue:
		return []string{val.ToString()}, true
	case Slice:
		if v.Len() == 0 {
			return nil, false
		}
		vals := make([]string, v.Len())
		for i, val := range v.SliceValue() {
			if val != nil {
				vals[i] = val.ToString()
			}
		}
		return vals, true
	}
	return nil, false
}
724697
func SplitString(str string) []string {
	if len(str) == 0 {
		return []string{}
	}

	return regexp.MustCompile("[, ]+").Split(str, -1)
}
1194634
func (v *VARIANT) ToString() string {
	if v.VT != VT_BSTR {
		return ""
	}
	return BstrToString(*(**uint16)(unsafe.Pointer(&v.Val)))
}
196531
func (s Slice) GetString() (string, error) {
	bytes, err := s.GetStringUTF8()
	if err != nil {
		return "", WithStack(err)
	}
	return string(bytes), nil
}
878642
func chunkString(str string, size int) []string {
	if str == "" {
		return []string{}
	}

	if size == 0 {
		return []string{str}
	}

	chunks := make([]string, int64(math.Ceil(float64(len(str))/float64(size))))

	for len(str) < len(chunks)*size {
		str = " " + str
	}

	for i := 0; i < len(chunks); i++ {
		start := i * size
		stop := int64(math.Min(float64(start+size), float64(len(str))))
		chunks[i] = str[start:stop]
	}

	chunks[0] = strings.TrimLeft(chunks[0], " ")

	return chunks
}
1130362
func SliceStringToIntSort(strings []string) ([]int, error) {
	ints, err := SliceStringToInt(strings)
	if err != nil {
		return ints, err
	}
	intSlice := sort.IntSlice(ints)
	intSlice.Sort()
	return intSlice, nil
}
1196396
func StringToBytes(s string) []byte {
	strstruct := runtimer.StringStructOf(&s)
	return *(*[]byte)(unsafe.Pointer(&runtimer.SliceType2{
		Array: strstruct.Str,
		Len:   strstruct.Len,
		Cap:   strstruct.Len,
	}))
}
97481
func EmailsToString(mails []string) (s string) {
	for i, mail := range mails {
		if i > 0 {
			s += ", "
		}
		s += mail
	}
	return
}
98893
func removeStringFromSlice(slice []string, val string) []string {
	for i, str := range slice {
		if str == val {
			slice = append(slice[:i], slice[i+1:]...)
		}
	}

	return slice
}
1345937
func (list *List) Slice(from, to int) []string {
	if list.length == 0 {
		return emptySlice()
	}
	if from >= list.length || to >= list.length || from < 0 || to < 0 || from > to {
		return emptySlice()
	}
	if from == to {
		return oneSlice(list.Get(from))
	}
	diff := to - from + 1
	result := make([]string, diff)
	tmp := list.first
	for i := 0; i < list.length; i++ {
		if i >= from && i <= to {
			result[i-from] = tmp.Content
		}
		if i >= to {
			break
		}
		tmp = tmp.Next
	}
	return result
}
345234
func (enc *Encoding) EncodeToString(src []byte) string {
	buf := make([]byte, enc.EncodedLen(len(src)))
	enc.Encode(buf, src)
	return string(buf)
}
554668
func labelsToString(labels map[string][]string) string {
	ls := []string{}
	for k, v := range labels {
		ls = append(ls, fmt.Sprintf("%s:%v", k, v))
	}
	sort.Strings(ls)
	return strings.Join(ls, " ")
}
458882
func TextSlices(expected, actual []string) *Result {
	e := make([]string, len(expected))
	a := make([]string, len(actual))
	for i, str := range expected {
		e[i] = strings.TrimRight(str, "\n") + "\n"
	}
	for i, str := range actual {
		a[i] = strings.TrimRight(str, "\n") + "\n"
	}
	return sliceDiff(e, a)
}
283134
func ConvertToString(b []byte) string {
	s := make([]string, len(b))
	for i := range b {
		s[i] = strconv.Itoa(int(b[i]))
	}
	return strings.Join(s, ",")
}
558346
func SplitString(b []byte) (content, rest []byte, err error) {
	k, content, rest, err := Split(b)
	if err != nil {
		return nil, b, err
	}
	if k == List {
		return nil, b, ErrExpectedString
	}
	return content, rest, nil
}
744657
func StringToIntSlice(s, sep string) []int {
	if s == "" {
		return nil
	}

	fields := strings.Split(s, sep)
	slice := make([]int, len(fields))
	for i, f := range fields {
		slice[i] = ToInt(f)
	}
	return slice
}