You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stringwriter.go 580B

123456789101112131415161718192021222324252627
  1. package vfsgen
  2. import (
  3. "io"
  4. )
  5. // stringWriter writes given bytes to underlying io.Writer as a Go interpreted string literal value,
  6. // not including double quotes. It tracks the total number of bytes written.
  7. type stringWriter struct {
  8. io.Writer
  9. N int64 // Total bytes written.
  10. }
  11. func (sw *stringWriter) Write(p []byte) (n int, err error) {
  12. const hex = "0123456789abcdef"
  13. buf := []byte{'\\', 'x', 0, 0}
  14. for _, b := range p {
  15. buf[2], buf[3] = hex[b/16], hex[b%16]
  16. _, err = sw.Writer.Write(buf)
  17. if err != nil {
  18. return n, err
  19. }
  20. n++
  21. sw.N++
  22. }
  23. return n, nil
  24. }