-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfield.go
37 lines (33 loc) · 894 Bytes
/
field.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
package hl7
// Field is a slice of components.
type Field []Component
// GetComponent is used to get the component at the given index.
func (f Field) GetComponent(idx int) (Component, bool) {
if idx >= len(f) {
return nil, false
}
return f[idx], true
}
// GetSubComponent is used to get the sub-component at the given index.
func (f Field) GetSubComponent(compIdx, subCompIdx int) (SubComponent, bool) {
if comp, ok := f.GetComponent(compIdx); ok {
return comp.GetSubComponent(subCompIdx)
}
return nil, false
}
func newField(compSep, subCompSep, escape byte, data []byte) Field {
var (
field Field
start int
)
for i := range data {
if data[i] == compSep {
field = append(field, newComponent(subCompSep, escape, data[start:i]))
start = i + 1
}
if i == len(data)-1 {
field = append(field, newComponent(subCompSep, escape, data[start:]))
}
}
return field
}