Skip to content

Commit

Permalink
chore: annotate exported symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Nov 12, 2022
1 parent b154238 commit 137689a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jsonc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"unicode"
)

// Jsonc is the structure for parsing json with comments
type Jsonc struct {
comment int
commaPos int
Expand All @@ -15,17 +16,20 @@ type Jsonc struct {
len int
}

// New creates Jsonc struct with proper defaults
func New() *Jsonc {
return &Jsonc{0, -1, false, 0, 0}
}

// Strip strips comments and trailing commas from input byte array
func (j *Jsonc) Strip(jsonb []byte) []byte {
s := j.StripS(string(jsonb))
return []byte(s)
}

var crlf = map[string]string{"\n": `\n`, "\t": `\t`, "\r": `\r`}

// StripS strips comments and trailing commas from input string
func (j *Jsonc) StripS(data string) string {
var oldprev, prev, char, next, s string

Expand Down Expand Up @@ -59,10 +63,12 @@ func (j *Jsonc) StripS(data string) string {
return s
}

// Unmarshal strips and parses the json byte array
func (j *Jsonc) Unmarshal(jsonb []byte, v interface{}) error {
return json.Unmarshal(j.Strip(jsonb), v)
}

// UnmarshalFile strips and parses the json content from file
func (j *Jsonc) UnmarshalFile(file string, v interface{}) error {
jsonb, err := ioutil.ReadFile(file)
if err != nil {
Expand Down

0 comments on commit 137689a

Please sign in to comment.