-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathstring.go
More file actions
60 lines (48 loc) · 1.04 KB
/
string.go
File metadata and controls
60 lines (48 loc) · 1.04 KB
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
package vector
import (
"github.com/brimdata/super"
"github.com/brimdata/super/scode"
)
type String struct {
table BytesTable
}
func NewString(table BytesTable) *String {
return &String{table}
}
func NewStringEmpty(cap uint32) *String {
return NewString(NewBytesTableEmpty(cap))
}
func (s *String) Append(v string) {
s.table.Append([]byte(v))
}
func (*String) Kind() Kind {
return KindString
}
func (s *String) Type() super.Type {
return super.TypeString
}
func (s *String) Len() uint32 {
return s.table.Len()
}
func (s *String) Value(slot uint32) string {
return s.table.String(slot)
}
func (s *String) Table() BytesTable {
return s.table
}
func (s *String) Serialize(b *scode.Builder, slot uint32) {
b.Append(s.table.Bytes(slot))
}
func StringValue(val Any, slot uint32) string {
switch val := val.(type) {
case *String:
return val.Value(slot)
case *Const:
return StringValue(val.Any, 0)
case *Dict:
return StringValue(val.Any, uint32(val.Index[slot]))
case *View:
return StringValue(val.Any, val.Index[slot])
}
panic(val)
}