From 2afdd17e3f0a453ba330352a7221f4fa9bef19b2 Mon Sep 17 00:00:00 2001 From: Urvil Patel Date: Tue, 25 Sep 2018 13:44:45 +0530 Subject: [PATCH] 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 --- src/strconv/example_test.go | 40 +++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) 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) -- 2.50.0