Commit db645a02 authored by Volker Dobler's avatar Volker Dobler Committed by Brad Fitzpatrick

strconv: consistent parameter names for ParseUint

If ParseUint is like ParseInt it should have the same parameter
names, thus rename b to to base as in ParseInt's documentation.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6453152
parent 20f6a8fd
......@@ -44,7 +44,7 @@ func cutoff64(base int) uint64 {
}
// ParseUint is like ParseInt but for unsigned numbers.
func ParseUint(s string, b int, bitSize int) (n uint64, err error) {
func ParseUint(s string, base int, bitSize int) (n uint64, err error) {
var cutoff, maxVal uint64
if bitSize == 0 {
......@@ -57,32 +57,32 @@ func ParseUint(s string, b int, bitSize int) (n uint64, err error) {
err = ErrSyntax
goto Error
case 2 <= b && b <= 36:
case 2 <= base && base <= 36:
// valid base; nothing to do
case b == 0:
case base == 0:
// Look for octal, hex prefix.
switch {
case s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X'):
b = 16
base = 16
s = s[2:]
if len(s) < 1 {
err = ErrSyntax
goto Error
}
case s[0] == '0':
b = 8
base = 8
default:
b = 10
base = 10
}
default:
err = errors.New("invalid base " + Itoa(b))
err = errors.New("invalid base " + Itoa(base))
goto Error
}
n = 0
cutoff = cutoff64(b)
cutoff = cutoff64(base)
maxVal = 1<<uint(bitSize) - 1
for i := 0; i < len(s); i++ {
......@@ -100,19 +100,19 @@ func ParseUint(s string, b int, bitSize int) (n uint64, err error) {
err = ErrSyntax
goto Error
}
if int(v) >= b {
if int(v) >= base {
n = 0
err = ErrSyntax
goto Error
}
if n >= cutoff {
// n*b overflows
// n*base overflows
n = 1<<64 - 1
err = ErrRange
goto Error
}
n *= uint64(b)
n *= uint64(base)
n1 := n + uint64(v)
if n1 < n || n1 > maxVal {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment