]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: accept '.', '!', and '?' as end of first sentence of package documentation
authorRobert Griesemer <gri@golang.org>
Tue, 27 Jul 2010 00:34:40 +0000 (17:34 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 27 Jul 2010 00:34:40 +0000 (17:34 -0700)
R=rsc
CC=golang-dev
https://golang.org/cl/1875049

src/cmd/godoc/godoc.go

index 658749b879fd5d85e8d06bb75973ec89427369e5..9daaacdb3f6919463f0810a86f3c088f356076c7 100644 (file)
@@ -152,18 +152,18 @@ func htmlEscape(s string) string {
 
 
 func firstSentence(s string) string {
-       i := -1 // index+1 of first period
-       j := -1 // index+1 of first period that is followed by white space
+       i := -1 // index+1 of first terminator (punctuation ending a sentence)
+       j := -1 // index+1 of first terminator followed by white space
        prev := 'A'
        for k, ch := range s {
                k1 := k + 1
-               if ch == '.' {
+               if ch == '.' || ch == '!' || ch == '?' {
                        if i < 0 {
-                               i = k1 // first period
+                               i = k1 // first terminator
                        }
                        if k1 < len(s) && s[k1] <= ' ' {
                                if j < 0 {
-                                       j = k1 // first period followed by white space
+                                       j = k1 // first terminator followed by white space
                                }
                                if !unicode.IsUpper(prev) {
                                        j = k1
@@ -175,10 +175,10 @@ func firstSentence(s string) string {
        }
 
        if j < 0 {
-               // use the next best period
+               // use the next best terminator
                j = i
                if j < 0 {
-                       // no period at all, use the entire string
+                       // no terminator at all, use the entire string
                        j = len(s)
                }
        }