Skip to content

Commit

Permalink
docs: improve consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Nov 7, 2021
1 parent 308058c commit 01c601c
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (d *Decoder) Any() (Any, error) {
return v, nil
}

// Any writes Any value.
// Any encodes Any value.
func (e *Encoder) Any(a Any) {
a.Write(e)
}
Expand Down
4 changes: 2 additions & 2 deletions dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func init() {
types['{'] = Object
}

// Decoder is streaming json decoder.
// Decoder decodes json.
//
// Can read from io.Reader or byte slice directly.
// Can decode from io.Reader or byte slice directly.
type Decoder struct {
reader io.Reader

Expand Down
4 changes: 2 additions & 2 deletions dec_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestDecoder_Raw(t *testing.T) {
t.Run("Positive", func(t *testing.T) {
v := `{"foo": [1, 2, 3, 4, 5] }}`
t.Run("Raw", func(t *testing.T) {
t.Run("RawStr", func(t *testing.T) {
d := DecodeStr(v)
require.NoError(t, d.Obj(func(d *Decoder, key string) error {
raw, err := d.Raw()
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestDecoder_Raw(t *testing.T) {
})
t.Run("Negative", func(t *testing.T) {
v := `{"foo": [1, 2, 3, 4, 5`
t.Run("Raw", func(t *testing.T) {
t.Run("RawStr", func(t *testing.T) {
d := DecodeStr(v)
var called bool
require.Error(t, d.Obj(func(d *Decoder, key string) error {
Expand Down
14 changes: 7 additions & 7 deletions enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ func (e *Encoder) fiveBytes(c1, c2, c3, c4, c5 byte) {
e.buf = append(e.buf, c1, c2, c3, c4, c5)
}

// Raw writes string as raw json.
func (e *Encoder) Raw(v string) {
// RawStr writes string as raw json.
func (e *Encoder) RawStr(v string) {
e.buf = append(e.buf, v...)
}

// RawBytes writes byte slice as raw json.
func (e *Encoder) RawBytes(b []byte) {
// Raw writes byte slice as raw json.
func (e *Encoder) Raw(b []byte) {
e.buf = append(e.buf, b...)
}

// Null writes null to stream.
// Null writes null.
func (e *Encoder) Null() {
e.comma()
e.fourBytes('n', 'u', 'l', 'l')
Expand All @@ -108,7 +108,7 @@ func (e *Encoder) False() {
e.fiveBytes('f', 'a', 'l', 's', 'e')
}

// Bool writes boolean.
// Bool encodes boolean.
func (e *Encoder) Bool(val bool) {
if val {
e.True()
Expand All @@ -125,7 +125,7 @@ func (e *Encoder) ObjStart() {
e.writeIndent()
}

// Field writes field name and colon.
// Field encodes field name and writes colon.
//
// For non-zero indentation also writes single space after colon.
func (e *Encoder) Field(field string) {
Expand Down
8 changes: 4 additions & 4 deletions enc_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (e *Encoder) Int32(v int32) {
e.Uint32(val)
}

// Uint64 writes uint64 to stream.
// Uint64 encodes uint64.
func (e *Encoder) Uint64(val uint64) {
e.comma()
q1 := val / 1000
Expand Down Expand Up @@ -129,7 +129,7 @@ func (e *Encoder) Uint64(val uint64) {
e.buf = writeBuf(e.buf, digits[r1])
}

// Int64 writes int64 to stream
// Int64 encodes int64.
func (e *Encoder) Int64(nval int64) {
var val uint64
if nval < 0 {
Expand All @@ -143,12 +143,12 @@ func (e *Encoder) Int64(nval int64) {
e.Uint64(val)
}

// Int writes int to stream.
// Int encodes int.
func (e *Encoder) Int(val int) {
e.Int64(int64(val))
}

// Uint writes uint to stream.
// Uint encodes uint.
func (e *Encoder) Uint(val uint) {
e.Uint64(uint64(val))
}
2 changes: 1 addition & 1 deletion enc_num.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ func (e *Encoder) Num(v Num) {
return
}
e.comma()
e.RawBytes(v)
e.Raw(v)
}
20 changes: 10 additions & 10 deletions enc_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (e *Encoder) strEscape(i int, v string, valLen int) {
continue
}
if start < i {
e.Raw(v[start:i])
e.RawStr(v[start:i])
}
switch b {
case '\\', '"':
Expand All @@ -266,7 +266,7 @@ func (e *Encoder) strEscape(i int, v string, valLen int) {
// because they can lead to security holes when
// user-controlled strings are rendered into JSON
// and served to some browsers.
e.Raw(`\u00`)
e.RawStr(`\u00`)
e.twoBytes(hexChars[b>>4], hexChars[b&0xF])
}
i++
Expand All @@ -276,9 +276,9 @@ func (e *Encoder) strEscape(i int, v string, valLen int) {
c, size := utf8.DecodeRuneInString(v[i:])
if c == utf8.RuneError && size == 1 {
if start < i {
e.Raw(v[start:i])
e.RawStr(v[start:i])
}
e.Raw(`\ufffd`)
e.RawStr(`\ufffd`)
i++
start = i
continue
Expand All @@ -292,9 +292,9 @@ func (e *Encoder) strEscape(i int, v string, valLen int) {
// See http://timelessrepo.com/json-isnt-a-javascript-subset for discussion.
if c == '\u2028' || c == '\u2029' {
if start < i {
e.Raw(v[start:i])
e.RawStr(v[start:i])
}
e.Raw(`\u202`)
e.RawStr(`\u202`)
e.byte(hexChars[c&0xF])
i += size
start = i
Expand All @@ -303,7 +303,7 @@ func (e *Encoder) strEscape(i int, v string, valLen int) {
i += size
}
if start < len(v) {
e.Raw(v[start:])
e.RawStr(v[start:])
}
e.byte('"')
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func (e *Encoder) strSlow(i int, v string, length int) {
continue
}
if start < i {
e.Raw(v[start:i])
e.RawStr(v[start:i])
}
switch b {
case '\\', '"':
Expand All @@ -360,7 +360,7 @@ func (e *Encoder) strSlow(i int, v string, length int) {
// because they can lead to security holes when
// user-controlled strings are rendered into JSON
// and served to some browsers.
e.Raw(`\u00`)
e.RawStr(`\u00`)
e.twoBytes(hexChars[b>>4], hexChars[b&0xF])
}
i++
Expand All @@ -371,7 +371,7 @@ func (e *Encoder) strSlow(i int, v string, length int) {
continue
}
if start < len(v) {
e.Raw(v[start:])
e.RawStr(v[start:])
}
e.byte('"')
}
6 changes: 3 additions & 3 deletions enc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func TestEncoder(t *testing.T) {
require.Equal(t, n, len(buf))
require.Equal(t, data, e.String())
})
t.Run("RawBytes", func(t *testing.T) {
t.Run("Raw", func(t *testing.T) {
e.Reset()
e.RawBytes(buf)
e.Raw(buf)
require.Equal(t, data, e.String())
})
t.Run("SetBytes", func(t *testing.T) {
Expand All @@ -45,7 +45,7 @@ func TestEncoder(t *testing.T) {
func TestEncoder_Raw_should_grow_buffer(t *testing.T) {
should := require.New(t)
e := GetEncoder()
e.Raw("123")
e.RawStr("123")
should.Equal("123", string(e.Bytes()))
}

Expand Down
8 changes: 4 additions & 4 deletions int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func Test_write_uint32(t *testing.T) {
}
should := require.New(t)
e := GetEncoder()
e.Raw("a")
e.RawStr("a")
e.Uint32(0xffffffff) // should clear buffer
should.Equal("a4294967295", e.String())
}
Expand All @@ -227,7 +227,7 @@ func Test_write_int32(t *testing.T) {
}
should := require.New(t)
e := GetEncoder()
e.Raw("a")
e.RawStr("a")
e.Int32(-0x7fffffff) // should clear buffer
should.Equal("a-2147483647", e.String())
}
Expand All @@ -246,7 +246,7 @@ func Test_write_uint64(t *testing.T) {
}
should := require.New(t)
e := GetEncoder()
e.Raw("a")
e.RawStr("a")
e.Uint64(0xffffffff) // should clear buffer
should.Equal("a4294967295", e.String())
}
Expand All @@ -265,7 +265,7 @@ func Test_write_int64(t *testing.T) {
}
should := require.New(t)
e := GetEncoder()
e.Raw("a")
e.RawStr("a")
e.Int64(0xffffffff) // should clear buffer
should.Equal("a4294967295", e.String())
}
Expand Down
2 changes: 1 addition & 1 deletion jx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestPutEncoder(t *testing.T) {
defer wg.Done()
for i := 0; i < 1024; i++ {
e := GetEncoder()
e.Raw("false")
e.RawStr("false")
assert.Equal(t, "false", e.String())
PutEncoder(e)
}
Expand Down

0 comments on commit 01c601c

Please sign in to comment.