github.com/prebid/prebid-server/v2@v2.18.0/util/stringutil/stringutil.go (about)

     1  package stringutil
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  )
     7  
     8  // StrToInt8Slice breaks a string into a series of tokens using a comma as a delimiter but only
     9  // appends the tokens into the return array if tokens can be interpreted as an 'int8'
    10  func StrToInt8Slice(str string) ([]int8, error) {
    11  	var r []int8
    12  
    13  	if len(str) > 0 {
    14  		strSlice := strings.Split(str, ",")
    15  		for _, s := range strSlice {
    16  			v, err := strconv.ParseInt(s, 10, 8)
    17  			if err != nil {
    18  				return nil, err
    19  			}
    20  			r = append(r, int8(v))
    21  		}
    22  	}
    23  
    24  	return r, nil
    25  }