From: Urvil Patel Date: Tue, 25 Sep 2018 08:14:45 +0000 (+0530) Subject: strconv: add example for QuoteRuneToGraphic and QuoteToGraphic functions X-Git-Tag: go1.12beta1~854 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2afdd17e3f0a453ba330352a7221f4fa9bef19b2;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/strconv/example_test.go b/src/strconv/example_test.go index 15725456e2..2d1a2a9dbf 100644 --- a/src/strconv/example_test.go +++ b/src/strconv/example_test.go @@ -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)