...
1 package vfsgen
2
3 import "io"
4
5
6
7 type commentWriter struct {
8 W io.Writer
9 wroteSlashes bool
10 }
11
12 func (c *commentWriter) Write(p []byte) (int, error) {
13 var n int
14 for i, b := range p {
15 if !c.wroteSlashes {
16 s := "//"
17 if b != '\n' {
18 s = "// "
19 }
20 if _, err := io.WriteString(c.W, s); err != nil {
21 return n, err
22 }
23 c.wroteSlashes = true
24 }
25 n0, err := c.W.Write(p[i : i+1])
26 n += n0
27 if err != nil {
28 return n, err
29 }
30 if b == '\n' {
31 c.wroteSlashes = false
32 }
33 }
34 return len(p), nil
35 }
36
37 func (c *commentWriter) Close() error {
38 if !c.wroteSlashes {
39 if _, err := io.WriteString(c.W, "//"); err != nil {
40 return err
41 }
42 c.wroteSlashes = true
43 }
44 return nil
45 }
46
View as plain text