From fa851b17a2fd2350043b3e56dce398a606692c23 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 2 Feb 2015 11:02:09 -0800 Subject: [PATCH] go/printer: clearer logic (clenaup) Change-Id: I278ce47b38ec5732d981aec06b71f9ee5747c3bb Reviewed-on: https://go-review.googlesource.com/3730 Reviewed-by: Alan Donovan --- src/go/printer/printer.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/go/printer/printer.go b/src/go/printer/printer.go index 5160757e14..36f9439a28 100644 --- a/src/go/printer/printer.go +++ b/src/go/printer/printer.go @@ -504,26 +504,25 @@ func stripCommonPrefix(lines []string) { // Note that the first and last line are never empty (they // contain the opening /* and closing */ respectively) and // thus they can be ignored by the blank line check. - var prefix string + prefix := "" + prefixSet := false if len(lines) > 2 { - first := true for i, line := range lines[1 : len(lines)-1] { - switch { - case isBlank(line): + if isBlank(line) { lines[1+i] = "" // range starts with lines[1] - case first: - prefix = commonPrefix(line, line) - first = false - default: + } else { + if !prefixSet { + prefix = line + prefixSet = true + } prefix = commonPrefix(prefix, line) } + } - if first { // all lines were blank (except first and last) - line := lines[len(lines)-1] - prefix = commonPrefix(line, line) - } - } else { // len(lines) == 2, lines cannot be blank (contain /* and */) - line := lines[1] + } + // If we don't have a prefix yet, consider the last line. + if !prefixSet { + line := lines[len(lines)-1] prefix = commonPrefix(line, line) } -- 2.48.1