From 04b08da9af0c450d645ab7389d1467308cfc2db8 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 4 Mar 2013 21:27:36 +0100 Subject: Imported Upstream version 1.1~hg20130304 --- src/pkg/go/doc/synopsis.go | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'src/pkg/go/doc/synopsis.go') diff --git a/src/pkg/go/doc/synopsis.go b/src/pkg/go/doc/synopsis.go index 2192d78c0..2d1817439 100644 --- a/src/pkg/go/doc/synopsis.go +++ b/src/pkg/go/doc/synopsis.go @@ -4,7 +4,10 @@ package doc -import "unicode" +import ( + "strings" + "unicode" +) // firstSentenceLen returns the length of the first sentence in s. // The sentence ends after the first period followed by space and @@ -24,17 +27,12 @@ func firstSentenceLen(s string) int { return len(s) } -// Synopsis returns a cleaned version of the first sentence in s. -// That sentence ends after the first period followed by space and -// not preceded by exactly one uppercase letter. The result string -// has no \n, \r, or \t characters and uses only single spaces between -// words. -// -func Synopsis(s string) string { - n := firstSentenceLen(s) +// clean replaces each sequence of space, \n, \r, or \t characters +// with a single space and removes any trailing and leading spaces. +func clean(s string) string { var b []byte p := byte(' ') - for i := 0; i < n; i++ { + for i := 0; i < len(s); i++ { q := s[i] if q == '\n' || q == '\r' || q == '\t' { q = ' ' @@ -50,3 +48,26 @@ func Synopsis(s string) string { } return string(b) } + +// Synopsis returns a cleaned version of the first sentence in s. +// That sentence ends after the first period followed by space and +// not preceded by exactly one uppercase letter. The result string +// has no \n, \r, or \t characters and uses only single spaces between +// words. If s starts with any of the IllegalPrefixes, the result +// is the empty string. +// +func Synopsis(s string) string { + s = clean(s[0:firstSentenceLen(s)]) + for _, prefix := range IllegalPrefixes { + if strings.HasPrefix(strings.ToLower(s), prefix) { + return "" + } + } + return s +} + +var IllegalPrefixes = []string{ + "copyright", + "all rights", + "author", +} -- cgit v1.2.3