77 "unicode"
88)
99
10+ // Jsonc is the structure for parsing json with comments
1011type Jsonc struct {
1112 comment int
1213 commaPos int
@@ -15,17 +16,20 @@ type Jsonc struct {
1516 len int
1617}
1718
19+ // New creates Jsonc struct with proper defaults
1820func New () * Jsonc {
1921 return & Jsonc {0 , - 1 , false , 0 , 0 }
2022}
2123
24+ // Strip strips comments and trailing commas from input byte array
2225func (j * Jsonc ) Strip (jsonb []byte ) []byte {
2326 s := j .StripS (string (jsonb ))
2427 return []byte (s )
2528}
2629
2730var crlf = map [string ]string {"\n " : `\n` , "\t " : `\t` , "\r " : `\r` }
2831
32+ // StripS strips comments and trailing commas from input string
2933func (j * Jsonc ) StripS (data string ) string {
3034 var oldprev , prev , char , next , s string
3135
@@ -59,10 +63,12 @@ func (j *Jsonc) StripS(data string) string {
5963 return s
6064}
6165
66+ // Unmarshal strips and parses the json byte array
6267func (j * Jsonc ) Unmarshal (jsonb []byte , v interface {}) error {
6368 return json .Unmarshal (j .Strip (jsonb ), v )
6469}
6570
71+ // UnmarshalFile strips and parses the json content from file
6672func (j * Jsonc ) UnmarshalFile (file string , v interface {}) error {
6773 jsonb , err := ioutil .ReadFile (file )
6874 if err != nil {
0 commit comments