Source File
atoi.go
Belonging Package
strconv
package strconv
import
type NumError struct {
Func string // the failing function (ParseBool, ParseInt, ParseUint, ParseFloat, ParseComplex)
Num string // the input
Err error // the reason the conversion failed (e.g. ErrRange, ErrSyntax, etc.)
}
func ( *NumError) () string {
return "strconv." + .Func + ": " + "parsing " + Quote(.Num) + ": " + .Err.Error()
}
func ( *NumError) () error { return .Err }
func (, string) *NumError {
return &NumError{, , ErrSyntax}
}
func (, string) *NumError {
return &NumError{, , ErrRange}
}
func (, string, int) *NumError {
return &NumError{, , errors.New("invalid base " + Itoa())}
}
func (, string, int) *NumError {
return &NumError{, , errors.New("invalid bit size " + Itoa())}
}
const intSize = 32 << (^uint(0) >> 63)
= 10
if [0] == '0' {
switch {
case len() >= 3 && lower([1]) == 'b':
= 2
= [2:]
case len() >= 3 && lower([1]) == 'o':
= 8
= [2:]
case len() >= 3 && lower([1]) == 'x':
= 16
= [2:]
default:
= 8
= [1:]
}
}
default:
return 0, baseError(, , )
}
if == 0 {
= IntSize
} else if < 0 || > 64 {
return 0, bitSizeError(, , )
}
var uint64
switch {
case 10:
= maxUint64/10 + 1
case 16:
= maxUint64/16 + 1
default:
= maxUint64/uint64() + 1
}
:= uint64(1)<<uint() - 1
:= false
var uint64
for , := range []byte() {
var byte
switch {
case == '_' && :
= true
continue
case '0' <= && <= '9':
= - '0'
case 'a' <= lower() && lower() <= 'z':
= lower() - 'a' + 10
default:
return 0, syntaxError(, )
}
if >= byte() {
return 0, syntaxError(, )
}
return , rangeError(, )
}
*= uint64()
:= + uint64()
return , rangeError(, )
}
=
}
if && !underscoreOK() {
return 0, syntaxError(, )
}
return , nil
}
var uint64
, = ParseUint(, , )
if != nil && .(*NumError).Err != ErrRange {
.(*NumError).Func =
.(*NumError).Num =
return 0,
}
if == 0 {
= IntSize
}
:= uint64(1 << uint(-1))
if ! && >= {
return int64( - 1), rangeError(, )
}
if && > {
return -int64(), rangeError(, )
}
:= int64()
if {
= -
}
return , nil
}
:= '^'
:= 0
if len() >= 1 && ([0] == '-' || [0] == '+') {
= [1:]
}
if [] == '_' {
if != '0' {
return false
}
= '_'
continue
if == '_' {
return false
= '!'
}
return != '_'
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |