~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/strconv/quote_example_test.go

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}