summaryrefslogtreecommitdiff
path: root/src/pkg/go/doc/synopsis.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/go/doc/synopsis.go')
-rw-r--r--src/pkg/go/doc/synopsis.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/pkg/go/doc/synopsis.go b/src/pkg/go/doc/synopsis.go
index 2d1817439..c90080b7c 100644
--- a/src/pkg/go/doc/synopsis.go
+++ b/src/pkg/go/doc/synopsis.go
@@ -22,19 +22,28 @@ func firstSentenceLen(s string) int {
if q == ' ' && p == '.' && (!unicode.IsUpper(pp) || unicode.IsUpper(ppp)) {
return i
}
+ if p == '。' || p == '.' {
+ return i
+ }
ppp, pp, p = pp, p, q
}
return len(s)
}
+const (
+ keepNL = 1 << iota
+)
+
// 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 {
+// If the keepNL flag is set, newline characters are passed through
+// instead of being change to spaces.
+func clean(s string, flags int) string {
var b []byte
p := byte(' ')
for i := 0; i < len(s); i++ {
q := s[i]
- if q == '\n' || q == '\r' || q == '\t' {
+ if (flags&keepNL) == 0 && q == '\n' || q == '\r' || q == '\t' {
q = ' '
}
if q != ' ' || p != ' ' {
@@ -57,7 +66,7 @@ func clean(s string) string {
// is the empty string.
//
func Synopsis(s string) string {
- s = clean(s[0:firstSentenceLen(s)])
+ s = clean(s[0:firstSentenceLen(s)], 0)
for _, prefix := range IllegalPrefixes {
if strings.HasPrefix(strings.ToLower(s), prefix) {
return ""