Commit 0ff0df8b authored by Motkov.Kirill's avatar Motkov.Kirill Committed by Ian Lance Taylor

fmt: rewrite if-else-if-else chain to switch statement

This commit rewrites if-else-if-else chain in scanBasePrefix function as a switch.

Based on Go style guide https://golang.org/doc/effective_go.html#switch

Change-Id: I6392bfd4ad0384f3dc8896de4763bb2164c3eead
GitHub-Last-Rev: 9bd8dfdac03c466bf8cacf3119f6245dfb61c009
GitHub-Pull-Request: golang/go#30621
Reviewed-on: https://go-review.googlesource.com/c/go/+/165619
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 958e212d
...@@ -612,25 +612,25 @@ func (s *ss) scanRune(bitSize int) int64 { ...@@ -612,25 +612,25 @@ func (s *ss) scanRune(bitSize int) int64 {
// scanBasePrefix reports whether the integer begins with a bas prefix // scanBasePrefix reports whether the integer begins with a bas prefix
// and returns the base, digit string, and whether a zero was found. // and returns the base, digit string, and whether a zero was found.
// It is called only if the verb is %v. // It is called only if the verb is %v.
func (s *ss) scanBasePrefix() (base int, digits string, found bool) { func (s *ss) scanBasePrefix() (int, string, bool) {
if !s.peek("0") { if !s.peek("0") {
return 0, decimalDigits + "_", false return 0, decimalDigits + "_", false
} }
s.accept("0") s.accept("0")
found = true // We've put a digit into the token buffer.
// Special cases for 0, 0b, 0o, 0x. // Special cases for 0, 0b, 0o, 0x.
base, digits = 0, octalDigits+"_" switch {
if s.peek("bB") { case s.peek("bB"):
s.consume("bB", true) s.consume("bB", true)
base, digits = 0, binaryDigits+"_" return 0, binaryDigits + "_", true
} else if s.peek("oO") { case s.peek("oO"):
s.consume("oO", true) s.consume("oO", true)
base, digits = 0, octalDigits+"_" return 0, octalDigits + "_", true
} else if s.peek("xX") { case s.peek("xX"):
s.consume("xX", true) s.consume("xX", true)
base, digits = 0, hexadecimalDigits+"_" return 0, hexadecimalDigits + "_", true
default:
return 0, octalDigits + "_", true
} }
return
} }
// scanInt returns the value of the integer represented by the next // scanInt returns the value of the integer represented by the next
......
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