| 18 | } |
| 19 | |
| 20 | func ExampleNew() { |
| 21 | empty, err := New("") |
| 22 | if err != nil { |
| 23 | fmt.Println(err) |
| 24 | |
| 25 | return |
| 26 | } |
| 27 | fmt.Printf("empty pointer: %q\n", empty.String()) |
| 28 | |
| 29 | key, err := New("/foo") |
| 30 | if err != nil { |
| 31 | fmt.Println(err) |
| 32 | |
| 33 | return |
| 34 | } |
| 35 | fmt.Printf("pointer to object key: %q\n", key.String()) |
| 36 | |
| 37 | elem, err := New("/foo/1") |
| 38 | if err != nil { |
| 39 | fmt.Println(err) |
| 40 | |
| 41 | return |
| 42 | } |
| 43 | fmt.Printf("pointer to array element: %q\n", elem.String()) |
| 44 | |
| 45 | escaped0, err := New("/foo~0") |
| 46 | if err != nil { |
| 47 | fmt.Println(err) |
| 48 | |
| 49 | return |
| 50 | } |
| 51 | // key contains "~" |
| 52 | fmt.Printf("pointer to key %q: %q\n", Unescape("foo~0"), escaped0.String()) |
| 53 | |
| 54 | escaped1, err := New("/foo~1") |
| 55 | if err != nil { |
| 56 | fmt.Println(err) |
| 57 | |
| 58 | return |
| 59 | } |
| 60 | // key contains "/" |
| 61 | fmt.Printf("pointer to key %q: %q\n", Unescape("foo~1"), escaped1.String()) |
| 62 | |
| 63 | // Output: |
| 64 | // empty pointer: "" |
| 65 | // pointer to object key: "/foo" |
| 66 | // pointer to array element: "/foo/1" |
| 67 | // pointer to key "foo~": "/foo~0" |
| 68 | // pointer to key "foo/": "/foo~1" |
| 69 | } |
| 70 | |
| 71 | func ExamplePointer_Get() { |
| 72 | var doc exampleDocument |