strconv: use switch to handle '+' and '-' in readFloat and decimal.set

This commit is contained in:
zhi.wang 2025-04-06 20:51:01 +08:00
parent 6d2fd44bc4
commit 0c9d2efb5a
1 changed files with 14 additions and 12 deletions

View File

@ -77,12 +77,12 @@ func (b *decimal) set(s string) (ok bool) {
if i >= len(s) {
return
}
switch {
case s[i] == '+':
switch s[i] {
case '+':
i++
case '-':
i++
case s[i] == '-':
b.neg = true
i++
}
// digits
@ -135,9 +135,10 @@ func (b *decimal) set(s string) (ok bool) {
return
}
esign := 1
if s[i] == '+' {
switch s[i] {
case '+':
i++
} else if s[i] == '-' {
case '-':
i++
esign = -1
}
@ -176,12 +177,12 @@ func readFloat(s string) (mantissa uint64, exp int, neg, trunc, hex bool, i int,
if i >= len(s) {
return
}
switch {
case s[i] == '+':
switch s[i] {
case '+':
i++
case '-':
i++
case s[i] == '-':
neg = true
i++
}
// digits
@ -268,9 +269,10 @@ loop:
return
}
esign := 1
if s[i] == '+' {
switch s[i] {
case '+':
i++
} else if s[i] == '-' {
case '-':
i++
esign = -1
}