forked from plandem/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bounds_list.go
69 lines (53 loc) · 1.46 KB
/
bounds_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
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
63
64
65
66
67
68
69
// 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 (
"encoding/xml"
"strings"
)
//BoundsList is implementation of RefList
type BoundsList []Bounds
//BoundsListFromRefs returns BoundsList for provided refs
func BoundsListFromRefs(refs ...Ref) BoundsList {
list := make([]Bounds, 0, len(refs))
for _, r := range refs {
list = append(list, r.ToBounds())
}
return list
}
//ToRefList returns refs. Alias of String() method
func (bl *BoundsList) ToRefList() RefList {
return RefList(bl.String())
}
//String return textual version of BoundsList
func (bl BoundsList) String() string {
refs := make([]string, 0, len(bl))
for _, b := range bl {
refs = append(refs, b.String())
}
return strings.Join(refs, " ")
}
//Add adds a new ref into the BoundsList
func (bl *BoundsList) Add(ref Ref) {
*bl = append(*bl, ref.ToBounds())
}
//IsEmpty return true if type was not initialized
func (bl BoundsList) IsEmpty() bool {
return len(bl) == 0
}
//MarshalXMLAttr marshal BoundsList
func (bl *BoundsList) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
attr := xml.Attr{Name: name}
if bl.IsEmpty() {
attr = xml.Attr{}
} else {
attr.Value = bl.String()
}
return attr, nil
}
//UnmarshalXMLAttr unmarshal BoundsList
func (bl *BoundsList) UnmarshalXMLAttr(attr xml.Attr) error {
*bl = RefList(attr.Value).ToBoundsList()
return nil
}