Skip to content

Commit afa7142

Browse files
committed
housekeep
1 parent 5ba848e commit afa7142

9 files changed

+20
-58
lines changed

buffer_reader.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (b BufferReader) IsSimple(off Off, specials ...Off) (ok bool) {
106106
}
107107

108108
func (b BufferReader) BytesChecked(off Off) ([]byte, error) {
109-
if err := b.Check2(off, cbor.String, cbor.Bytes); err != nil {
109+
if err := b.check2(off, cbor.String, cbor.Bytes); err != nil {
110110
return nil, err
111111
}
112112

@@ -123,7 +123,7 @@ func (b BufferReader) Bytes(off Off) []byte {
123123
}
124124

125125
func (b BufferReader) StringChecked(off Off) (string, error) {
126-
if err := b.Check2(off, cbor.String, cbor.Bytes); err != nil {
126+
if err := b.check2(off, cbor.String, cbor.Bytes); err != nil {
127127
return "", err
128128
}
129129

@@ -168,7 +168,7 @@ func (b BufferReader) ArrayMap(off Off, arr []Off) []Off {
168168
}
169169

170170
func (b BufferReader) IntChecked(off Off) (int, error) {
171-
if err := b.Check2(off, cbor.Int, cbor.Neg); err != nil {
171+
if err := b.check2(off, cbor.Int, cbor.Neg); err != nil {
172172
return 0, err
173173
}
174174

@@ -180,7 +180,7 @@ func (b BufferReader) Int(off Off) int {
180180
}
181181

182182
func (b BufferReader) SignedChecked(off Off) (int64, error) {
183-
if err := b.Check2(off, cbor.Int, cbor.Neg); err != nil {
183+
if err := b.check2(off, cbor.Int, cbor.Neg); err != nil {
184184
return 0, err
185185
}
186186

@@ -200,7 +200,7 @@ func (b BufferReader) Signed(off Off) int64 {
200200
}
201201

202202
func (b BufferReader) UnsignedChecked(off Off) (uint64, error) {
203-
if err := b.Check2(off, cbor.Int, cbor.Neg); err != nil {
203+
if err := b.check2(off, cbor.Int, cbor.Neg); err != nil {
204204
return 0, err
205205
}
206206

@@ -219,7 +219,7 @@ func (b BufferReader) Unsigned(off Off) uint64 {
219219
return v
220220
}
221221

222-
func (b BufferReader) Check(off Off, want Tag) error {
222+
func (b BufferReader) check(off Off, want Tag) error {
223223
tag := b.Tag(off)
224224
if tag != want {
225225
return NewTypeError(tag, want)
@@ -228,7 +228,7 @@ func (b BufferReader) Check(off Off, want Tag) error {
228228
return nil
229229
}
230230

231-
func (b BufferReader) Check2(off Off, want, want2 Tag) error {
231+
func (b BufferReader) check2(off Off, want, want2 Tag) error {
232232
tag := b.Tag(off)
233233
if tag != want {
234234
return NewTypeError(tag, want, want2)

buffer_writer.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ type bufferIOWriter struct {
169169
tag Tag
170170
}
171171

172-
func (b BufferWriter) StringWriter(tag Tag) (Off, io.Writer) {
173-
return b.Off(), bufferIOWriter{b, tag}
172+
func (b BufferWriter) StringWriter(tag Tag) io.Writer {
173+
return bufferIOWriter{b, tag}
174174
}
175175

176-
func (b BufferWriter) RawWriter() (Off, io.Writer) {
177-
return b.Off(), bufferIOWriter{b, 0}
176+
func (b BufferWriter) RawWriter() io.Writer {
177+
return bufferIOWriter{b, 0}
178178
}
179179

180180
func (w bufferIOWriter) Write(p []byte) (int, error) {

dump.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type (
1919
}
2020
)
2121

22-
func DumpBytes(b []byte) string {
22+
func Dump(b []byte) string {
2323
return (&Dumper{Base: -1}).DumpBytes(b)
2424
}
2525

jq.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ func (e TypeError) Format(s fmt.State, v rune) {
268268
return
269269
}
270270

271-
tag := byte(e)
271+
tag := Tag(e)
272272

273-
fmt.Fprintf(s, "type error: %s (%x)", tagString(tag), tag)
273+
fmt.Fprintf(s, "type error: %s (%x)", tagString(tag), byte(tag))
274274

275275
if e&0xff00 == 0 {
276276
return
@@ -280,7 +280,7 @@ func (e TypeError) Format(s fmt.State, v rune) {
280280
fmt.Fprintf(s, ", wanted: ")
281281
comma := false
282282

283-
for t := range byte(8) {
283+
for t := range Tag(8) {
284284
if e&(1<<(8+t)) == 0 {
285285
continue
286286
}
@@ -300,7 +300,7 @@ func (e TypeError) Format(s fmt.State, v rune) {
300300
comma := false
301301

302302
for j := 2; j < 6; j++ {
303-
t := byte(e >> (8 * j))
303+
t := Tag(e >> (8 * j))
304304

305305
if comma {
306306
fmt.Fprintf(s, ", ")
@@ -316,8 +316,8 @@ func (e TypeError) Error() string {
316316
return fmt.Sprintf("%v", e)
317317
}
318318

319-
func tagString(tag byte) string {
320-
if tag&cbor.TagMask != byte(cbor.Simple) {
319+
func tagString(tag Tag) string {
320+
if tag&cbor.TagMask != cbor.Simple {
321321
return tag2str[tag>>5]
322322
}
323323

object.go

-14
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ type (
1818
Value Filter
1919
}
2020

21-
ObjectCopyKey string
22-
2321
objectState struct {
2422
next bool
2523
}
@@ -46,18 +44,6 @@ func NewObject(kvs ...any) *Object {
4644
key = Literal{b[st:]}
4745
} else if k, ok := kvs[i].(Filter); ok {
4846
key = k
49-
} else if s, ok := kvs[i].(ObjectCopyKey); ok {
50-
st := len(b)
51-
b = e.AppendString(b, string(s))
52-
53-
key = Literal{b[st:]}
54-
55-
obj = append(obj, ObjectKey{
56-
Key: key,
57-
Value: Key(s),
58-
})
59-
60-
continue
6147
} else {
6248
panic(kvs[i])
6349
}

object_test.go

-13
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,3 @@ func TestObjectIterMulti(tb *testing.T) {
6666
obj{"a", "e", "e", "val2"},
6767
})
6868
}
69-
70-
func TestObjectCopyKeys(tb *testing.T) {
71-
b := NewBuffer()
72-
root := b.appendVal(obj{"a", 1, "b", 2})
73-
74-
f := NewObject(
75-
ObjectCopyKey("a"),
76-
ObjectCopyKey("b"),
77-
ObjectCopyKey("c"),
78-
)
79-
80-
testOne(tb, f, b, root, obj{"a", 1, "b", 2, "c", nil})
81-
}

plus.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,5 @@ func (f Plus) String() string {
167167
}
168168

169169
func (e PlusError) Error() string {
170-
return fmt.Sprintf("plus: unsupported types %v and %v", tagString(byte(e)), tagString(byte(e>>8)))
170+
return fmt.Sprintf("plus: unsupported types %v and %v", tagString(Tag(e)), tagString(Tag(e>>8)))
171171
}

try.go

-11
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ type (
2020
ErrorExpr struct {
2121
Expr Filter
2222
}
23-
24-
ErrorErr struct {
25-
Err error
26-
}
2723
)
2824

2925
func NewTry(expr, catch Filter) *Try { return &Try{Expr: expr, Catch: catch} }
@@ -86,12 +82,6 @@ func (f ErrorExpr) ApplyTo(b *Buffer, off Off, next bool) (res Off, more bool, e
8682
return None, false, fmt.Errorf("not a string error: %+v", res)
8783
}
8884

89-
func NewErrorErr(err error) ErrorErr { return ErrorErr{Err: err} }
90-
91-
func (f ErrorErr) ApplyTo(b *Buffer, off Off, next bool) (res Off, more bool, err error) {
92-
return None, false, f.Err
93-
}
94-
9585
func (f ErrorText) ApplyTo(b *Buffer, off Off, next bool) (res Off, more bool, err error) {
9686
return None, false, errors.New(string(f))
9787
}
@@ -106,4 +96,3 @@ func (f Try) String() string {
10696

10797
func (f ErrorText) String() string { return fmt.Sprintf(`error(%q)`, string(f)) }
10898
func (f ErrorExpr) String() string { return fmt.Sprintf(`error(%+v)`, f.Expr) }
109-
func (f ErrorErr) String() string { return fmt.Sprintf(`error(%q)`, f.Err) }

try_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestTryCatch(tb *testing.T) {
1313
testOne(tb, NewTry(ErrorText("some error"), Dot{}), b, Null, "some error")
1414

1515
e := errors.New("some err")
16-
testError(tb, NewErrorExpr(NewErrorErr(e)), b, Null, e)
16+
testError(tb, NewErrorExpr(NewHalt(e)), b, Null, e)
1717

1818
testIter(tb, NewErrorExpr(NewIter()), b, EmptyArray, []any{})
1919

0 commit comments

Comments
 (0)