Commit 2afdd17e authored by Urvil Patel's avatar Urvil Patel Committed by Ian Lance Taylor

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: 's avatarIan Lance Taylor <iant@golang.org>
parent e99082fc
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment