example_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package quotedprintable_test
  5. import (
  6. "fmt"
  7. "io"
  8. "mime/quotedprintable"
  9. "os"
  10. "strings"
  11. )
  12. func ExampleNewReader() {
  13. for _, s := range []string{
  14. `=48=65=6C=6C=6F=2C=20=47=6F=70=68=65=72=73=21`,
  15. `invalid escape: <b style="font-size: 200%">hello</b>`,
  16. "Hello, Gophers! This symbol will be unescaped: =3D and this will be written in =\r\none line.",
  17. } {
  18. b, err := io.ReadAll(quotedprintable.NewReader(strings.NewReader(s)))
  19. fmt.Printf("%s %v\n", b, err)
  20. }
  21. // Output:
  22. // Hello, Gophers! <nil>
  23. // invalid escape: <b style="font-size: 200%">hello</b> <nil>
  24. // Hello, Gophers! This symbol will be unescaped: = and this will be written in one line. <nil>
  25. }
  26. func ExampleNewWriter() {
  27. w := quotedprintable.NewWriter(os.Stdout)
  28. w.Write([]byte("These symbols will be escaped: = \t"))
  29. w.Close()
  30. // Output:
  31. // These symbols will be escaped: =3D =09
  32. }