mirror of https://github.com/golang/go.git
strconv/atoi.go: use switch to handle leading '+' and '-' in Atoi
Replace if-else with a switch statement to handle leading '+' and '-' characters.
This commit is contained in:
parent
1647896aa2
commit
6d2fd44bc4
|
|
@ -204,11 +204,12 @@ func ParseInt(s string, base int, bitSize int) (i int64, err error) {
|
|||
// Pick off leading sign.
|
||||
s0 := s
|
||||
neg := false
|
||||
if s[0] == '+' {
|
||||
switch s[0] {
|
||||
case '+':
|
||||
s = s[1:]
|
||||
case '-':
|
||||
s = s[1:]
|
||||
} else if s[0] == '-' {
|
||||
neg = true
|
||||
s = s[1:]
|
||||
}
|
||||
|
||||
// Convert unsigned and check range.
|
||||
|
|
|
|||
Loading…
Reference in New Issue