File: logical_value.go

package info (click to toggle)
golang-github-knqyf263-go-cpe 0.0~git20180327.659663f6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, experimental, sid, trixie
  • size: 18,036 kB
  • sloc: sh: 11; makefile: 4
file content (51 lines) | stat: -rw-r--r-- 955 bytes parent folder | download | duplicates (2)
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
package common

import (
	"errors"
	"strings"
)

var (
	// ErrIllegalArgument is returned when illegal argument
	ErrIllegalArgument = errors.New("Illegal argument")
)

// LogicalValue represents a Logical Value.
// @see <a href="http://cpe.mitre.org">cpe.mitre.org</a> for more information.
// @author JKRAUNELIS
// @email jkraunelis@mitre.org
type LogicalValue struct {
	Any bool
	Na  bool
}

// NewLogicalValue returns Logicalvalue
func NewLogicalValue(t string) (lv LogicalValue, err error) {
	t = strings.ToUpper(t)
	if t == "ANY" {
		lv.Any = true
	} else if t == "NA" {
		lv.Na = true
	} else {
		return LogicalValue{}, ErrIllegalArgument
	}
	return lv, nil
}

// IsANY returns whether any is true
func (lv LogicalValue) IsANY() bool {
	return lv.Any
}

// IsNA returns whether na is true
func (lv LogicalValue) IsNA() bool {
	return lv.Na
}

// String : String
func (lv LogicalValue) String() string {
	if lv.Any {
		return "ANY"
	}
	return "NA"
}