* gcc.dg/guality/guality.exp: Skip on AIX.
[official-gcc.git] / libgo / go / go / doc / synopsis.go
blob2d18174393e67201f002a8ae6f68d7e08d398464
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.
5 package doc
7 import (
8 "strings"
9 "unicode"
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 {
17 var ppp, pp, p rune
18 for i, q := range s {
19 if q == '\n' || q == '\r' || q == '\t' {
20 q = ' '
22 if q == ' ' && p == '.' && (!unicode.IsUpper(pp) || unicode.IsUpper(ppp)) {
23 return i
25 ppp, pp, p = pp, p, q
27 return len(s)
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 {
33 var b []byte
34 p := byte(' ')
35 for i := 0; i < len(s); i++ {
36 q := s[i]
37 if q == '\n' || q == '\r' || q == '\t' {
38 q = ' '
40 if q != ' ' || p != ' ' {
41 b = append(b, q)
42 p = q
45 // remove trailing blank, if any
46 if n := len(b); n > 0 && p == ' ' {
47 b = b[0 : n-1]
49 return string(b)
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) {
63 return ""
66 return s
69 var IllegalPrefixes = []string{
70 "copyright",
71 "all rights",
72 "author",