1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 // firstSentenceLen returns the length of the first sentence in s.
13 // The sentence ends after the first period followed by space and
14 // not preceded by exactly one uppercase letter.
16 func firstSentenceLen(s
string) int {
19 if q
== '\n' || q
== '\r' || q
== '\t' {
22 if q
== ' ' && p
== '.' && (!unicode
.IsUpper(pp
) || unicode
.IsUpper(ppp
)) {
30 // clean replaces each sequence of space, \n, \r, or \t characters
31 // with a single space and removes any trailing and leading spaces.
32 func clean(s
string) string {
35 for i
:= 0; i
< len(s
); i
++ {
37 if q
== '\n' || q
== '\r' || q
== '\t' {
40 if q
!= ' ' || p
!= ' ' {
45 // remove trailing blank, if any
46 if n
:= len(b
); n
> 0 && p
== ' ' {
52 // Synopsis returns a cleaned version of the first sentence in s.
53 // That sentence ends after the first period followed by space and
54 // not preceded by exactly one uppercase letter. The result string
55 // has no \n, \r, or \t characters and uses only single spaces between
56 // words. If s starts with any of the IllegalPrefixes, the result
57 // is the empty string.
59 func Synopsis(s
string) string {
60 s
= clean(s
[0:firstSentenceLen(s
)])
61 for _
, prefix
:= range IllegalPrefixes
{
62 if strings
.HasPrefix(strings
.ToLower(s
), prefix
) {
69 var IllegalPrefixes
= []string{