// Returns slice of the original data without padding.
971155
func PKCS7Unpad(in []byte) []byte {
	if len(in) == 0 {
		return nil
	}

	padding := in[len(in)-1]
	if int(padding) > len(in) || padding > aes.BlockSize {
		return nil
	} else if padding == 0 {
		return nil
	}

	for i := len(in) - 1; i > len(in)-int(padding)-1; i-- {
		if in[i] != padding {
			return nil
		}
	}
	return in[:len(in)-int(padding)]
}
1257547
func (d *Dataset) Slice(lower, upperNonInclusive int) (*Dataset, error) {
	if lower > upperNonInclusive || lower < 0 || upperNonInclusive > d.rows {
		return nil, ErrInvalidRowIndex
	}

	rowCount := upperNonInclusive - lower
	cols := d.cols
	nd := NewDataset(d.headers)
	nd.data = make([][]interface{}, 0, rowCount)
	nd.tags = make([][]string, 0, rowCount)
	nd.rows = upperNonInclusive - lower
	j := 0
	for i := lower; i < upperNonInclusive; i++ {
		nd.data = append(nd.data, make([]interface{}, 0, cols))
		nd.data[j] = make([]interface{}, 0, cols)
		nd.data[j] = append(nd.data[j], d.data[i]...)
		nd.tags = append(nd.tags, make([]string, 0, cols))
		nd.tags[j] = make([]string, 0, cols)
		nd.tags[j] = append(nd.tags[j], d.tags[i]...)
		j++
	}

	return nd, nil
}
828903
func RemoveFromSlice(slice []string, values ...string) []string {
	output := make([]string, 0, len(slice))

	remove := make(map[string]bool)
	for _, value := range values {
		remove[value] = true
	}

	for _, s := range slice {
		_, ok := remove[s]
		if ok {
			continue
		}
		output = append(output, s)
	}

	return output
}
460534
func (dt *DbfTable) convertToByteSlice(value string, numberOfBytes int) (s []byte) {
	e := mahonia.NewEncoder(dt.fileEncoding)
	b := []byte(e.ConvertString(value))

	if len(b) <= numberOfBytes {
		s = b
	} else {
		s = b[0:numberOfBytes]
	}
	return
}
62762
func SliceNot(s1 []byte) []byte {
	mini := len(s1)
	s := make([]byte, mini)
	for i := 0; i < mini; i++ {
		s[i] = ^s1[i]
	}
	return s
}
149129
func appendSlice(slice, data []byte) []byte {
	l := len(slice)
	if l+len(data) > cap(slice) { // reallocate
		// Allocate double what's needed, for future growth.
		// increase capcity %20
		//cap := (l+len(data))*(5/4)
		//newSlice := make([]byte, cap)
		newSlice := make([]byte, (l+len(data))*2)
		// The copy function is predeclared and works for any slice type.
		copy(newSlice, slice)
		slice = newSlice
	}
	slice = slice[0 : l+len(data)]
	//fmt.Printf("appendSlice son:%v\n", len(slice))
	//fmt.Printf("appendSlice cap:%v\n", cap(slice))
	for i, c := range data {
		slice[l+i] = c
	}
	return slice
}
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
}
61169
func sliceCompress(data []byte) []byte {
	var buf bytes.Buffer
	cmp, _ := zlib.NewWriterLevel(&buf, zlib.BestSpeed)
	cmp.Write(data)
	cmp.Close()
	return buf.Bytes()
}
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
}
709097
func (dec *Decoder) SliceFloat64(s *[]float64) error {
	err := dec.Array(DecodeArrayFunc(func(dec *Decoder) error {
		var i float64
		if err := dec.Float64(&i); err != nil {
			return err
		}
		*s = append(*s, i)
		return nil
	}))

	if err != nil {
		return err
	}
	return nil
}
254035
func appendSlice(slice, data []byte) []byte {
	slice = append(slice, data...)
	return slice
}
368541
func copySlice(slice []byte) []byte {
	ret := make([]byte, len(slice))
	copy(ret, slice)
	return ret
}
563585
func SliceRemove(s []string, index int) []string {
	copy(s[index:], s[index+1:])
	// Remove the reference
	s[len(s)-1] = ""
	return s[:len(s)-1]
}
1179695
func (o *Buffer) enc_slice_slice_byte(p *Properties, base structPointer) error {
	ss := *structPointer_BytesSlice(base, p.field)
	l := len(ss)
	if l == 0 {
		return ErrNil
	}
	for i := 0; i < l; i++ {
		o.buf = append(o.buf, p.tagcode...)
		o.EncodeRawBytes(ss[i])
	}
	return nil
}
1015675
func CopyByteSlices(in [][]byte) [][]byte {
	if in == nil {
		return nil
	}
	out := make([][]byte, len(in))
	for i := range in {
		out[i] = CopyByteSlice(in[i])
	}
	return out
}
1184298
func BytesSlice(val, sep string) ([][]byte, error) {
	s := strings.Split(val, sep)
	values := make([][]byte, len(s))
	for i, v := range s {
		value, err := Bytes(v)
		if err != nil {
			return values, err
		}
		values[i] = value
	}
	return values, nil
}
431223
func CopyRulesSlice(in []Rule) []Rule {
	out := make([]Rule, len(in))
	copy(out, in)
	return out
}