]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: add example for QuoteRuneToGraphic and QuoteToGraphic functions
authorUrvil Patel <patelurvil38@gmail.com>
Tue, 25 Sep 2018 08:14:45 +0000 (13:44 +0530)
committerIan Lance Taylor <iant@golang.org>
Mon, 8 Oct 2018 19:13:38 +0000 (19:13 +0000)
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>
src/strconv/example_test.go

index 15725456e26339c05406588c0c404fa42cfd5289..2d1a2a9dbfd506eaaa55f46e2be56b4bec3984b9 100644 (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)