forked from valyala/fastjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner_example_test.go
More file actions
53 lines (45 loc) · 855 Bytes
/
scanner_example_test.go
File metadata and controls
53 lines (45 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package fastjson_test
import (
"fmt"
"github.com/valyala/fastjson"
"log"
)
func ExampleScanner() {
var sc fastjson.Scanner
sc.Init(` {"foo": "bar" }[ ]
12345"xyz" true false null `)
for sc.Next() {
fmt.Printf("%s\n", sc.Value())
}
if err := sc.Error(); err != nil {
log.Fatalf("unexpected error: %s", err)
}
// Output:
// {"foo":"bar"}
// []
// 12345
// "xyz"
// true
// false
// null
}
func ExampleScanner_reuse() {
var sc fastjson.Scanner
// The sc may be re-used in order to reduce the number
// of memory allocations.
for i := 0; i < 3; i++ {
s := fmt.Sprintf(`[%d] "%d"`, i, i)
sc.Init(s)
for sc.Next() {
fmt.Printf("%s,", sc.Value())
}
if err := sc.Error(); err != nil {
log.Fatalf("unexpected error: %s", err)
}
fmt.Printf("\n")
}
// Output:
// [0],"0",
// [1],"1",
// [2],"2",
}