code: func strToInt(str string) (int64, error) {
  	str = strings.TrimSpace(str)
  	if len(str) == 0 {
  		return 0, ErrTruncated
  	}
  	negative := false
  	i := 0
  	if str[i] == '-' {
  		negative = true
  		i++
  	} else if str[i] == '+' {
  		i++
  	}
  
  	var (
  		err    error
  		hasNum = false
  	)
  	r := uint64(0)
  	for ; i < len(str); i++ {
  		if !unicode.IsDigit(rune(str[i])) {
  			err = ErrTruncated
  			break
  		}
  		hasNum = true
  		if r >= uintCutOff {
  			r = 0
  			err = errors.Trace(ErrBadNumber)
  			break
  		}
  		r = r * uint64(10)
  
  		r1 := r + uint64(str[i]-'0')
  		if r1 < r || r1 > maxUint {
  			r = 0
  			err = errors.Trace(ErrBadNumber)
  			break
  		}
  		r = r1
  	}
  	if !hasNum {
  		err = ErrTruncated
  	}
  
  	if !negative && r >= intCutOff {
  		return math.MaxInt64, errors.Trace(ErrBadNumber)
  	}
  
  	if negative && r > intCutOff {
  		return math.MinInt64, errors.Trace(ErrBadNumber)
  	}
  
  	if negative {
  		r = -r
  	}
  	return int64(r), err
  }
docs: // strToInt converts a string to an integer in best effort.