-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
62 lines (53 loc) · 1.34 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package jst
import (
"fmt"
"io"
"github.com/ipld/go-ipld-prime/datamodel"
)
func max(a, b int) int { // honestly golang
if a > b {
return a
}
return b
}
func mustFirstKeyAsString(mapNode datamodel.Node) string {
itr := mapNode.MapIterator()
k, _, err := itr.Next()
if err != nil {
panic(err)
}
ks, err := k.AsString()
if err != nil {
panic(err)
}
return ks
}
func indexOf(list []columnName, cn columnName) int {
for i, v := range list {
if v == cn {
return i
}
}
return -1
}
type codecAborted struct {
p datamodel.Path
e error
}
func (e codecAborted) Error() string {
return fmt.Sprintf("codec aborted: %s", e.e)
}
// attempt to record where the codec efforts encountered an error.
// this is currently a bit slapdash.
// a better system might also count byte and line offsets in the serial form (but this would require also integrating with the serial code pretty closely).
// a spectacularly general system might be ready to count serial offsets *twice* *or* path offsets *twice* (but this is simply waiting for someone's enthusiasm).
func recordErrorPosition(ctx *state, e error) error {
return codecAborted{datamodel.Path{ /*TODO*/ }, e}
}
// not yet used, but you'd probably want this for better error position purposes.
type writerNanny struct {
totalOffset int
lineOffset int
offsetInLine int
w io.Writer
}