quote_example_test.go 755 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2013 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 strconv_test
  5. import (
  6. "fmt"
  7. "strconv"
  8. )
  9. func ExampleUnquote() {
  10. test := func(s string) {
  11. t, err := strconv.Unquote(s)
  12. if err != nil {
  13. fmt.Printf("Unquote(%#v): %v\n", s, err)
  14. } else {
  15. fmt.Printf("Unquote(%#v) = %v\n", s, t)
  16. }
  17. }
  18. s := `cafe\u0301`
  19. // If the string doesn't have quotes, it can't be unquoted.
  20. test(s) // invalid syntax
  21. test("`" + s + "`")
  22. test(`"` + s + `"`)
  23. test(`'\u00e9'`)
  24. // Output:
  25. // Unquote("cafe\\u0301"): invalid syntax
  26. // Unquote("`cafe\\u0301`") = cafe\u0301
  27. // Unquote("\"cafe\\u0301\"") = café
  28. // Unquote("'\\u00e9'") = é
  29. }