7
7
"unicode"
8
8
)
9
9
10
+ // Jsonc is the structure for parsing json with comments
10
11
type Jsonc struct {
11
12
comment int
12
13
commaPos int
@@ -15,17 +16,20 @@ type Jsonc struct {
15
16
len int
16
17
}
17
18
19
+ // New creates Jsonc struct with proper defaults
18
20
func New () * Jsonc {
19
21
return & Jsonc {0 , - 1 , false , 0 , 0 }
20
22
}
21
23
24
+ // Strip strips comments and trailing commas from input byte array
22
25
func (j * Jsonc ) Strip (jsonb []byte ) []byte {
23
26
s := j .StripS (string (jsonb ))
24
27
return []byte (s )
25
28
}
26
29
27
30
var crlf = map [string ]string {"\n " : `\n` , "\t " : `\t` , "\r " : `\r` }
28
31
32
+ // StripS strips comments and trailing commas from input string
29
33
func (j * Jsonc ) StripS (data string ) string {
30
34
var oldprev , prev , char , next , s string
31
35
@@ -59,10 +63,12 @@ func (j *Jsonc) StripS(data string) string {
59
63
return s
60
64
}
61
65
66
+ // Unmarshal strips and parses the json byte array
62
67
func (j * Jsonc ) Unmarshal (jsonb []byte , v interface {}) error {
63
68
return json .Unmarshal (j .Strip (jsonb ), v )
64
69
}
65
70
71
+ // UnmarshalFile strips and parses the json content from file
66
72
func (j * Jsonc ) UnmarshalFile (file string , v interface {}) error {
67
73
jsonb , err := ioutil .ReadFile (file )
68
74
if err != nil {
0 commit comments