aboutsummaryrefslogtreecommitdiff
path: root/src/strconv
diff options
context:
space:
mode:
authorSabin Mihai Rapan <sabin.rapan@gmail.com>2018-02-05 19:44:09 +0200
committerBrad Fitzpatrick <bradfitz@golang.org>2018-05-07 20:39:37 +0000
commit74879f0f014549f7881539d96d842ae1d6d3aa92 (patch)
treeabc1fe37adcb4098f4b01fddcd92dd398190e24f /src/strconv
parent8e9386db0ee72ffa847b1673d15f6092291724d9 (diff)
downloadgo-74879f0f014549f7881539d96d842ae1d6d3aa92.tar.gz
go-74879f0f014549f7881539d96d842ae1d6d3aa92.zip
strconv: update Unquote example to be more concise
Changed the example to convey the intent of the Unquote function in a more succint way. Fixes #23693 Change-Id: I49465641d730e70b5af0d47057335af39882bcec Reviewed-on: https://go-review.googlesource.com/92015 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/strconv')
-rw-r--r--src/strconv/example_test.go34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/strconv/example_test.go b/src/strconv/example_test.go
index 01fbbc0fb9..5c2e8a9b56 100644
--- a/src/strconv/example_test.go
+++ b/src/strconv/example_test.go
@@ -281,27 +281,23 @@ func ExampleQuoteToASCII() {
}
func ExampleUnquote() {
- test := func(s string) {
- t, err := strconv.Unquote(s)
- if err != nil {
- fmt.Printf("Unquote(%#v): %v\n", s, err)
- } else {
- fmt.Printf("Unquote(%#v) = %v\n", s, t)
- }
- }
-
- s := `\"Fran & Freddie's Diner\t\u263a\"\"`
- // If the string doesn't have quotes, it can't be unquoted.
- test(s) // invalid syntax
- test("`" + s + "`")
- test(`"` + s + `"`)
- test(`'\u263a'`)
+ s, err := strconv.Unquote("You can't unquote a string without quotes")
+ fmt.Printf("%q, %v\n", s, err)
+ s, err = strconv.Unquote("\"The string must be either double-quoted\"")
+ fmt.Printf("%q, %v\n", s, err)
+ s, err = strconv.Unquote("`or backquoted.`")
+ fmt.Printf("%q, %v\n", s, err)
+ s, err = strconv.Unquote("'\u263a'") // single character only allowed in single quotes
+ fmt.Printf("%q, %v\n", s, err)
+ s, err = strconv.Unquote("'\u2639\u2639'")
+ fmt.Printf("%q, %v\n", s, err)
// Output:
- // Unquote("\\\"Fran & Freddie's Diner\\t\\u263a\\\"\\\""): invalid syntax
- // Unquote("`\\\"Fran & Freddie's Diner\\t\\u263a\\\"\\\"`") = \"Fran & Freddie's Diner\t\u263a\"\"
- // Unquote("\"\\\"Fran & Freddie's Diner\\t\\u263a\\\"\\\"\"") = "Fran & Freddie's Diner ☺""
- // Unquote("'\\u263a'") = ☺
+ // "", invalid syntax
+ // "The string must be either double-quoted", <nil>
+ // "or backquoted.", <nil>
+ // "☺", <nil>
+ // "", invalid syntax
}
func ExampleUnquoteChar() {