...

Source file src/github.com/launchdarkly/go-server-sdk-evaluation/v2/internal/parse_hex.go

Documentation: github.com/launchdarkly/go-server-sdk-evaluation/v2/internal

     1  package internal
     2  
     3  // ParseHexUint64 is equivalent to using strconv.ParseUint with base 16, except that it operates directly
     4  // on a byte slice without having to allocate a string. (A version of strconv.ParseUint that operates on
     5  // a byte slice has been a frequently requested Go feature for years, but as of the time this comment
     6  // was written, those requests have not been acted on.)
     7  func ParseHexUint64(data []byte) (uint64, bool) {
     8  	if len(data) == 0 {
     9  		return 0, false
    10  	}
    11  	var ret uint64
    12  	for _, ch := range data {
    13  		ret <<= 4
    14  		switch {
    15  		case ch >= '0' && ch <= '9':
    16  			ret += uint64(ch - '0')
    17  		case ch >= 'a' && ch <= 'f':
    18  			ret += uint64(ch - 'a' + 10)
    19  		case ch >= 'A' && ch <= 'F':
    20  			ret += uint64(ch - 'A' + 10)
    21  		default:
    22  			return 0, false
    23  		}
    24  	}
    25  	return ret, true
    26  }
    27  

View as plain text