Commit e8b580c9 authored by Robert Griesemer's avatar Robert Griesemer

fix sentence extraction

R=rsc
http://go/go-review/1026027
parent 202ede12
...@@ -137,14 +137,21 @@ func htmlEscape(s string) string { ...@@ -137,14 +137,21 @@ func htmlEscape(s string) string {
func firstSentence(s string) string { func firstSentence(s string) string {
i := strings.Index(s, ". "); // find first period followed by whitespace, or just the first period
if i < 0 { i := -1;
i = strings.Index(s, "."); for j, ch := range s {
if i < 0 { if ch == '.' {
i = len(s)-1; // compensate for i+1 below 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];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment