]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: rewrite if-else-if-else chain to switch statement
authorMotkov.Kirill <Motkov.Kirill@gmail.com>
Wed, 6 Mar 2019 11:16:14 +0000 (11:16 +0000)
committerIan Lance Taylor <iant@golang.org>
Wed, 6 Mar 2019 15:12:49 +0000 (15:12 +0000)
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>
src/fmt/scan.go

index d42703cb717feb8e5064b5d5fe119a17964ca8a8..fe6cbd477f717f9ebf43a3d0a50b757c8242fd7a 100644 (file)
@@ -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