1
0
mirror of https://github.com/golang/go synced 2024-09-24 21:10:12 -06:00

fix sentence extraction

R=rsc
http://go/go-review/1026027
This commit is contained in:
Robert Griesemer 2009-11-08 18:19:06 -08:00
parent 202ede1240
commit e8b580c9aa

View 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];
}