]> Cypherpunks repositories - gostls13.git/commitdiff
go/doc: exclude lines ending in ':' from possible headings
authorRobert Griesemer <gri@golang.org>
Thu, 1 Dec 2011 23:14:15 +0000 (15:14 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 1 Dec 2011 23:14:15 +0000 (15:14 -0800)
This is a more conservative approach to heading detection and
removes 11 headings from the current repository (several in
fmt). The current headscan output is:

/home/gri/go3/src/cmd/goinstall (package documentation)
        Remote Repositories
        The GOPATH Environment Variable
/home/gri/go3/src/pkg/exp/gotype (package documentation)
        Examples
/home/gri/go3/src/pkg/html/template (package template)
        Introduction
        Contexts
        Errors
        A fuller picture
        Contexts
        Typed Strings
        Security Model
/home/gri/go3/src/pkg/text/template (package template)
        Actions
        Arguments
        Pipelines
        Variables
        Examples
        Functions
        Associated templates
        Nested template definitions
18 headings found

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/5437105

src/pkg/go/doc/comment.go
src/pkg/go/doc/comment_test.go

index ed39268f5a5ab627ba74479c3dfd205633d8cfb7..c9fb55bd54ef1cd4715e70442e1d987943eee0a8 100644 (file)
@@ -241,8 +241,8 @@ func unindent(block []string) {
        }
 }
 
-// heading returns the (possibly trimmed) line if it passes as a valid section
-// heading; otherwise it returns the empty string. 
+// heading returns the trimmed line if it passes as a section heading;
+// otherwise it returns the empty string. 
 func heading(line string) string {
        line = strings.TrimSpace(line)
        if len(line) == 0 {
@@ -255,17 +255,12 @@ func heading(line string) string {
                return ""
        }
 
-       // it must end in a letter, digit or ':'
+       // it must end in a letter or digit:
        r, _ = utf8.DecodeLastRuneInString(line)
-       if !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != ':' {
+       if !unicode.IsLetter(r) && !unicode.IsDigit(r) {
                return ""
        }
 
-       // strip trailing ':', if any
-       if r == ':' {
-               line = line[0 : len(line)-1]
-       }
-
        // exclude lines with illegal characters
        if strings.IndexAny(line, ",.;:!?+*/=()[]{}_^°&§~%#@<\">\\") >= 0 {
                return ""
index f689ac985e106083acad07eee1e5a28d310ac8de..6424053ac9debc47f917ee92a2fa6b97055fef6f 100644 (file)
@@ -18,7 +18,8 @@ var headingTests = []struct {
        {"Foo 42", true},
        {"", false},
        {"section", false},
-       {"A typical usage:", true},
+       {"A typical usage:", false},
+       {"This code:", false},
        {"δ is Greek", false},
        {"Foo §", false},
        {"Fermat's Last Sentence", true},
@@ -26,7 +27,7 @@ var headingTests = []struct {
        {"'sX", false},
        {"Ted 'Too' Bar", false},
        {"Use n+m", false},
-       {"Scanning:", true},
+       {"Scanning:", false},
        {"N:M", false},
 }