Skip to content

Commit 2afdd17

Browse files
urvil38ianlancetaylor
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent e99082f commit 2afdd17

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

src/strconv/example_test.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func ExampleParseUint() {
265265
}
266266

267267
func ExampleQuote() {
268-
s := strconv.Quote(`"Fran & Freddie's Diner ☺"`)
268+
s := strconv.Quote(`"Fran & Freddie's Diner ☺"`) // there is a tab character inside the string literal
269269
fmt.Println(s)
270270

271271
// Output:
@@ -288,14 +288,50 @@ func ExampleQuoteRuneToASCII() {
288288
// '\u263a'
289289
}
290290

291+
func ExampleQuoteRuneToGraphic() {
292+
s := strconv.QuoteRuneToGraphic('☺')
293+
fmt.Println(s)
294+
295+
s = strconv.QuoteRuneToGraphic('\u263a')
296+
fmt.Println(s)
297+
298+
s = strconv.QuoteRuneToGraphic('\u000a')
299+
fmt.Println(s)
300+
301+
s = strconv.QuoteRuneToGraphic(' ') // tab character
302+
fmt.Println(s)
303+
304+
// Output:
305+
// '☺'
306+
// '☺'
307+
// '\n'
308+
// '\t'
309+
}
310+
291311
func ExampleQuoteToASCII() {
292-
s := strconv.QuoteToASCII(`"Fran & Freddie's Diner ☺"`)
312+
s := strconv.QuoteToASCII(`"Fran & Freddie's Diner ☺"`) // there is a tab character inside the string literal
293313
fmt.Println(s)
294314

295315
// Output:
296316
// "\"Fran & Freddie's Diner\t\u263a\""
297317
}
298318

319+
func ExampleQuoteToGraphic() {
320+
s := strconv.QuoteToGraphic("☺")
321+
fmt.Println(s)
322+
323+
s = strconv.QuoteToGraphic("This is a \u263a \u000a") // there is a tab character inside the string literal
324+
fmt.Println(s)
325+
326+
s = strconv.QuoteToGraphic(`" This is a ☺ \n "`)
327+
fmt.Println(s)
328+
329+
// Output:
330+
// "☺"
331+
// "This is a ☺\t\n"
332+
// "\" This is a ☺ \\n \""
333+
}
334+
299335
func ExampleUnquote() {
300336
s, err := strconv.Unquote("You can't unquote a string without quotes")
301337
fmt.Printf("%q, %v\n", s, err)

0 commit comments

Comments
 (0)