-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
ref_list.go
32 lines (26 loc) · 992 Bytes
/
ref_list.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
// Copyright (c) 2017 Andrey Gayvoronsky <plandem@gmail.com>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package primitives
import (
"strings"
"unsafe"
)
//RefList is a type to encode XSD ST_Sqref, a reference that identifies list of cells or ranges of cells. E.g.: "N28 B5:N10 C10"
type RefList string
//ToRefs returns refs of RefList
func (r RefList) ToRefs() []Ref {
//N.B.: even it's unsafe way, it still should be safe, because Ref is string
var refs = strings.Split(string(r), " ")
return *(*[]Ref)(unsafe.Pointer(&refs))
}
//ToBoundsList returns related bounds of RefList
func (r RefList) ToBoundsList() BoundsList {
return BoundsListFromRefs(r.ToRefs()...)
}
//RefListFromRefs returns RefList for refs
func RefListFromRefs(refs ...Ref) RefList {
//N.B.: even it's unsafe way, it still should be safe, because Ref is string
list := *(*[]string)(unsafe.Pointer(&refs))
return RefList(strings.Join(list, " "))
}