aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/shurcooL/vfsgen/commentwriter.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-16 23:20:23 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-16 23:23:43 +0200
commit1d678dfdfa026968dbb19795c9bed16385603b21 (patch)
treecac862609d0103ee30da39cd0054b11884248e9d /vendor/github.com/shurcooL/vfsgen/commentwriter.go
parent131a862d313f12808d63e832126317a27226940b (diff)
downloadgit-bug-1d678dfdfa026968dbb19795c9bed16385603b21.tar.gz
vendor dependencies with dep
Diffstat (limited to 'vendor/github.com/shurcooL/vfsgen/commentwriter.go')
-rw-r--r--vendor/github.com/shurcooL/vfsgen/commentwriter.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/github.com/shurcooL/vfsgen/commentwriter.go b/vendor/github.com/shurcooL/vfsgen/commentwriter.go
new file mode 100644
index 00000000..b6847f52
--- /dev/null
+++ b/vendor/github.com/shurcooL/vfsgen/commentwriter.go
@@ -0,0 +1,45 @@
+package vfsgen
+
+import "io"
+
+// commentWriter writes a Go comment to the underlying io.Writer,
+// using line comment form (//).
+type commentWriter struct {
+ W io.Writer
+ wroteSlashes bool // Wrote "//" at the beginning of the current line.
+}
+
+func (c *commentWriter) Write(p []byte) (int, error) {
+ var n int
+ for i, b := range p {
+ if !c.wroteSlashes {
+ s := "//"
+ if b != '\n' {
+ s = "// "
+ }
+ if _, err := io.WriteString(c.W, s); err != nil {
+ return n, err
+ }
+ c.wroteSlashes = true
+ }
+ n0, err := c.W.Write(p[i : i+1])
+ n += n0
+ if err != nil {
+ return n, err
+ }
+ if b == '\n' {
+ c.wroteSlashes = false
+ }
+ }
+ return len(p), nil
+}
+
+func (c *commentWriter) Close() error {
+ if !c.wroteSlashes {
+ if _, err := io.WriteString(c.W, "//"); err != nil {
+ return err
+ }
+ c.wroteSlashes = true
+ }
+ return nil
+}