github.com/sandwich-go/boost@v1.3.29/xmath/integer.go (about)

     1  package xmath
     2  
     3  import "strconv"
     4  
     5  // ParseUint64 parses s as an integer in decimal or hexadecimal syntax.
     6  // Leading zeros are accepted. The empty string parses as zero.
     7  func ParseUint64(s string) (uint64, bool) {
     8  	if s == "" {
     9  		return 0, true
    10  	}
    11  	if len(s) >= 2 && (s[:2] == "0x" || s[:2] == "0X") {
    12  		v, err := strconv.ParseUint(s[2:], 16, 64)
    13  		return v, err == nil
    14  	}
    15  	v, err := strconv.ParseUint(s, 10, 64)
    16  	return v, err == nil
    17  }
    18  
    19  // MustParseUint64 parses s as an integer and panics if the string is invalid.
    20  func MustParseUint64(s string) uint64 {
    21  	v, ok := ParseUint64(s)
    22  	if !ok {
    23  		panic("invalid unsigned 64 bit integer: " + s)
    24  	}
    25  	return v
    26  }