From: Andrew Gerrand Date: Mon, 7 Jan 2013 02:42:25 +0000 (+1100) Subject: go/doc: trim only first space or newline from example output comment X-Git-Tag: go1.1rc2~1464 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a88bbbb771141598e492d123e15e1e9752c134ca;p=gostls13.git go/doc: trim only first space or newline from example output comment Fixes #4487. R=rsc CC=golang-dev https://golang.org/cl/7057048 --- diff --git a/src/pkg/go/doc/example.go b/src/pkg/go/doc/example.go index 9fc0b415f0..d9e8c39a54 100644 --- a/src/pkg/go/doc/example.go +++ b/src/pkg/go/doc/example.go @@ -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