github.com/hbdrawn/golang@v0.0.0-20141214014649-6b835209aba2/src/strconv/quote_example_test.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package strconv_test
     6  
     7  import (
     8  	"fmt"
     9  	"strconv"
    10  )
    11  
    12  func ExampleUnquote() {
    13  	test := func(s string) {
    14  		t, err := strconv.Unquote(s)
    15  		if err != nil {
    16  			fmt.Printf("Unquote(%#v): %v\n", s, err)
    17  		} else {
    18  			fmt.Printf("Unquote(%#v) = %v\n", s, t)
    19  		}
    20  	}
    21  
    22  	s := `cafe\u0301`
    23  	// If the string doesn't have quotes, it can't be unquoted.
    24  	test(s) // invalid syntax
    25  	test("`" + s + "`")
    26  	test(`"` + s + `"`)
    27  
    28  	test(`'\u00e9'`)
    29  
    30  	// Output:
    31  	// Unquote("cafe\\u0301"): invalid syntax
    32  	// Unquote("`cafe\\u0301`") = cafe\u0301
    33  	// Unquote("\"cafe\\u0301\"") = café
    34  	// Unquote("'\\u00e9'") = é
    35  }