forked from plandem/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
condition_operator.go
83 lines (70 loc) · 2.38 KB
/
condition_operator.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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"
)
//ConditionOperatorType is a direct mapping of XSD ST_ConditionalFormattingOperator
type ConditionOperatorType byte
//ConditionOperatorType maps for marshal/unmarshal process
var (
ToConditionOperatorType map[string]ConditionOperatorType
FromConditionOperatorType map[ConditionOperatorType]string
)
//List of all possible values for OperatorType
const (
_ ConditionOperatorType = iota
ConditionOperatorLessThan
ConditionOperatorLessThanOrEqual
ConditionOperatorEqual
ConditionOperatorNotEqual
ConditionOperatorGreaterThanOrEqual
ConditionOperatorGreaterThan
ConditionOperatorBetween
ConditionOperatorNotBetween
ConditionOperatorContainsText
ConditionOperatorNotContains
ConditionOperatorBeginsWith
ConditionOperatorEndsWith
)
func init() {
FromConditionOperatorType = map[ConditionOperatorType]string{
ConditionOperatorLessThan: "lessThan",
ConditionOperatorLessThanOrEqual: "lessThanOrEqual",
ConditionOperatorEqual: "equal",
ConditionOperatorNotEqual: "notEqual",
ConditionOperatorGreaterThanOrEqual: "greaterThanOrEqual",
ConditionOperatorGreaterThan: "greaterThan",
ConditionOperatorBetween: "between",
ConditionOperatorNotBetween: "notBetween",
ConditionOperatorContainsText: "containsText",
ConditionOperatorNotContains: "notContains",
ConditionOperatorBeginsWith: "beginsWith",
ConditionOperatorEndsWith: "endsWith",
}
ToConditionOperatorType = make(map[string]ConditionOperatorType, len(FromConditionOperatorType))
for k, v := range FromConditionOperatorType {
ToConditionOperatorType[v] = k
}
}
func (t ConditionOperatorType) String() string {
return FromConditionOperatorType[t]
}
//MarshalXMLAttr marshal ConditionOperatorType
func (t *ConditionOperatorType) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
attr := xml.Attr{Name: name}
if v, ok := FromConditionOperatorType[*t]; ok {
attr.Value = v
} else {
attr = xml.Attr{}
}
return attr, nil
}
//UnmarshalXMLAttr unmarshal ConditionOperatorType
func (t *ConditionOperatorType) UnmarshalXMLAttr(attr xml.Attr) error {
if v, ok := ToConditionOperatorType[attr.Value]; ok {
*t = v
}
return nil
}