aboutsummaryrefslogtreecommitdiff
path: root/src/fmt
diff options
context:
space:
mode:
authorMotkov.Kirill <Motkov.Kirill@gmail.com>2019-03-06 11:16:14 +0000
committerIan Lance Taylor <iant@golang.org>2019-03-06 15:12:49 +0000
commit0ff0df8be3b2e532de6a18ba4040d2a7ebaee37f (patch)
tree4f248ac5c0bf70e361290c51a1848eb4187d2cab /src/fmt
parent958e212db799e609b2a8df51cdd85c9341e7a404 (diff)
downloadgo-0ff0df8be3b2e532de6a18ba4040d2a7ebaee37f.tar.gz
go-0ff0df8be3b2e532de6a18ba4040d2a7ebaee37f.zip
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: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/fmt')
-rw-r--r--src/fmt/scan.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/fmt/scan.go b/src/fmt/scan.go
index d42703cb71..fe6cbd477f 100644
--- a/src/fmt/scan.go
+++ b/src/fmt/scan.go
@@ -612,25 +612,25 @@ func (s *ss) scanRune(bitSize int) int64 {
// scanBasePrefix reports whether the integer begins with a bas prefix
// and returns the base, digit string, and whether a zero was found.
// 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") {
return 0, decimalDigits + "_", false
}
s.accept("0")
- found = true // We've put a digit into the token buffer.
// Special cases for 0, 0b, 0o, 0x.
- base, digits = 0, octalDigits+"_"
- if s.peek("bB") {
+ switch {
+ case s.peek("bB"):
s.consume("bB", true)
- base, digits = 0, binaryDigits+"_"
- } else if s.peek("oO") {
+ return 0, binaryDigits + "_", true
+ case s.peek("oO"):
s.consume("oO", true)
- base, digits = 0, octalDigits+"_"
- } else if s.peek("xX") {
+ return 0, octalDigits + "_", true
+ case s.peek("xX"):
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