Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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. }