]> Cypherpunks repositories - gostls13.git/commitdiff
fix sentence extraction
authorRobert Griesemer <gri@golang.org>
Mon, 9 Nov 2009 02:19:06 +0000 (18:19 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 9 Nov 2009 02:19:06 +0000 (18:19 -0800)
R=rsc
http://go/go-review/1026027

src/cmd/godoc/godoc.go

index 02e5119f01e3cdf7af5c9910d31060ad93dd63da..30f92b674edb5b1f6717fbcd112c991844ee9f22 100644 (file)
@@ -137,14 +137,21 @@ func htmlEscape(s string) string {
 
 
 func firstSentence(s string) string {
-       i := strings.Index(s, ". ");
-       if i < 0 {
-               i = strings.Index(s, ".");
-               if i < 0 {
-                       i = len(s)-1;   // compensate for i+1 below
+       // find first period followed by whitespace, or just the first period
+       i := -1;
+       for j, ch := range s {
+               if ch == '.' {
+                       i = j+1;        // include period
+                       if i < len(s) && s[i] <= ' ' {
+                               break;
+                       }
                }
        }
-       return s[0 : i+1];      // include ".", if any
+       if i < 0 {
+               // no period found, use the enire string
+               i = len(s);
+       }
+       return s[0:i];
 }