~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/go/doc/synopsis.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
package doc
6
6
 
7
 
import "unicode"
 
7
import (
 
8
        "strings"
 
9
        "unicode"
 
10
)
8
11
 
9
12
// firstSentenceLen returns the length of the first sentence in s.
10
13
// The sentence ends after the first period followed by space and
24
27
        return len(s)
25
28
}
26
29
 
27
 
// Synopsis returns a cleaned version of the first sentence in s.
28
 
// That sentence ends after the first period followed by space and
29
 
// not preceded by exactly one uppercase letter. The result string
30
 
// has no \n, \r, or \t characters and uses only single spaces between
31
 
// words.
32
 
//
33
 
func Synopsis(s string) string {
34
 
        n := firstSentenceLen(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 {
35
33
        var b []byte
36
34
        p := byte(' ')
37
 
        for i := 0; i < n; i++ {
 
35
        for i := 0; i < len(s); i++ {
38
36
                q := s[i]
39
37
                if q == '\n' || q == '\r' || q == '\t' {
40
38
                        q = ' '
50
48
        }
51
49
        return string(b)
52
50
}
 
51
 
 
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.
 
58
//
 
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 ""
 
64
                }
 
65
        }
 
66
        return s
 
67
}
 
68
 
 
69
var IllegalPrefixes = []string{
 
70
        "copyright",
 
71
        "all rights",
 
72
        "author",
 
73
}