]> Cypherpunks repositories - gostls13.git/commitdiff
go/doc: trim only first space or newline from example output comment
authorAndrew Gerrand <adg@golang.org>
Mon, 7 Jan 2013 02:42:25 +0000 (13:42 +1100)
committerAndrew Gerrand <adg@golang.org>
Mon, 7 Jan 2013 02:42:25 +0000 (13:42 +1100)
Fixes #4487.

R=rsc
CC=golang-dev
https://golang.org/cl/7057048

src/pkg/go/doc/example.go

index 9fc0b415f0d4ab98bf73e5cec1a9d0ec158a5222..d9e8c39a540e92951d9ab538a08e04ffd4c4f6f1 100644 (file)
@@ -84,7 +84,13 @@ func exampleOutput(b *ast.BlockStmt, comments []*ast.CommentGroup) string {
                // test that it begins with the correct prefix
                text := last.Text()
                if loc := outputPrefix.FindStringIndex(text); loc != nil {
-                       return strings.TrimSpace(text[loc[1]:])
+                       text = text[loc[1]:]
+                       // Strip zero or more spaces followed by \n or a single space.
+                       text = strings.TrimLeft(text, " ")
+                       if len(text) > 0 && text[0] == '\n' {
+                               text = text[1:]
+                       }
+                       return text
                }
        }
        return "" // no suitable comment found