1
0
mirror of https://github.com/golang/go synced 2024-09-29 17:14:29 -06:00

strconv: add example for QuoteRuneToGraphic and QuoteToGraphic functions

Change-Id: Ie5b2ef0087dbc7b8191de8c8b4190396631e3c7f
Reviewed-on: https://go-review.googlesource.com/c/137215
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Urvil Patel 2018-09-25 13:44:45 +05:30 committed by Ian Lance Taylor
parent e99082fc40
commit 2afdd17e3f

View File

@ -265,7 +265,7 @@ func ExampleParseUint() {
}
func ExampleQuote() {
s := strconv.Quote(`"Fran & Freddie's Diner ☺"`)
s := strconv.Quote(`"Fran & Freddie's Diner ☺"`) // there is a tab character inside the string literal
fmt.Println(s)
// Output:
@ -288,14 +288,50 @@ func ExampleQuoteRuneToASCII() {
// '\u263a'
}
func ExampleQuoteRuneToGraphic() {
s := strconv.QuoteRuneToGraphic('☺')
fmt.Println(s)
s = strconv.QuoteRuneToGraphic('\u263a')
fmt.Println(s)
s = strconv.QuoteRuneToGraphic('\u000a')
fmt.Println(s)
s = strconv.QuoteRuneToGraphic(' ') // tab character
fmt.Println(s)
// Output:
// '☺'
// '☺'
// '\n'
// '\t'
}
func ExampleQuoteToASCII() {
s := strconv.QuoteToASCII(`"Fran & Freddie's Diner ☺"`)
s := strconv.QuoteToASCII(`"Fran & Freddie's Diner ☺"`) // there is a tab character inside the string literal
fmt.Println(s)
// Output:
// "\"Fran & Freddie's Diner\t\u263a\""
}
func ExampleQuoteToGraphic() {
s := strconv.QuoteToGraphic("☺")
fmt.Println(s)
s = strconv.QuoteToGraphic("This is a \u263a \u000a") // there is a tab character inside the string literal
fmt.Println(s)
s = strconv.QuoteToGraphic(`" This is a ☺ \n "`)
fmt.Println(s)
// Output:
// "☺"
// "This is a ☺\t\n"
// "\" This is a ☺ \\n \""
}
func ExampleUnquote() {
s, err := strconv.Unquote("You can't unquote a string without quotes")
fmt.Printf("%q, %v\n", s, err)