File | File | |
| | @@ -31,11 +31,13 @@ import (
|
31 | 31 | //
|
32 | 32 | // This line must appear before the first non-comment, non-blank
|
33 | 33 | // text in the file.
|
34 | 34 | func Parse(src io.Reader) (hasGeneratedComment bool, err error) {
|
35 | 35 | br := bufio.NewReader(src)
|
36 | | var inBlock bool // Whether we're inside a multi-line /* */ comment block.
|
| 36 | // Use inBlock to track whether we're inside a multi-line
|
| 37 | // /* */ comment block across calls to containsNonComment.
|
| 38 | var inBlock bool
|
37 | 39 | for {
|
38 | 40 | s, err := br.ReadBytes('\n')
|
39 | 41 | if err == io.EOF {
|
40 | 42 | return containsGenComment(s), nil
|
41 | 43 | } else if err != nil {
|
| | @@ -54,12 +56,10 @@ func Parse(src io.Reader) (hasGeneratedComment bool, err error) {
|
54 | 56 | }
|
55 | 57 | }
|
56 | 58 |
|
57 | 59 | // containsNonComment reports whether a line of source code s (without newline)
|
58 | 60 | // contains something other than a line comment, block comment, or white space.
|
59 | | // *inBlock, given at the start of the line and updated at the end of the line,
|
60 | | // represents whether we're inside a multi-line /* */ comment block.
|
61 | 61 | func containsNonComment(s []byte, inBlock *bool) bool {
|
62 | 62 | type state int
|
63 | 63 | const (
|
64 | 64 | normal state = iota
|
65 | 65 | normalSlash
|