common

package
v0.0.0-...-cb0794d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 5 Imported by: 25

Documentation

Index

Constants

View Source
const (
	AttributePart      = "part"
	AttributeVendor    = "vendor"
	AttributeProduct   = "product"
	AttributeVersion   = "version"
	AttributeUpdate    = "update"
	AttributeEdition   = "edition"
	AttributeLanguage  = "language"
	AttributeSwEdition = "sw_edition"
	AttributeTargetSw  = "target_sw"
	AttributeTargetHw  = "target_hw"
	AttributeOther     = "other"
)

Variables

View Source
var (

	// ErrIllegalAttribute is returned when illegal argument
	ErrIllegalAttribute = errors.New("Illegal attribute")
	// ErrParse is returned when parse error
	ErrParse = errors.New("Parse error")
)
View Source
var (
	// ErrIllegalArgument is returned when illegal argument
	ErrIllegalArgument = errors.New("Illegal argument")
)

Functions

func ContainsQuestions

func ContainsQuestions(str string) bool

ContainsQuestions searches string for special characters ? @param string String to be searched @return true if string contains wildcard, false otherwise

func ContainsWildcards

func ContainsWildcards(str string) bool

ContainsWildcards searches string for special characters * and ? @param string String to be searched @return true if string contains wildcard, false otherwise

func CountEscapeCharacters

func CountEscapeCharacters(str string) (result int)

CountEscapeCharacters counts the number of escape characters in the string beginning and ending at the given indices @param str string to search @param start beginning index @param end ending index @return number of escape characters in string

func GetUnescapedColonIndex

func GetUnescapedColonIndex(str string) (idx int)

GetUnescapedColonIndex searches a string for the first unescaped colon and returns the index of that colon @param str string to search @return index of first unescaped colon, or 0 if not found

func IndexOf

func IndexOf(str1, str2 string, off int) int

IndexOf searches a string for the first occurrence of another string, starting at a given offset. @param str1 String to search. @param str2 String to search for. @param off Integer offset or -1 if not found.

func IsAlpha

func IsAlpha(r rune) bool

IsAlpha returns true if the rune contains only 'a'..'z' and 'A'..'Z'.

func IsAlphanum

func IsAlphanum(s string) bool

IsAlphanum returns true if the string contains only alphanumeric characters or the underscore character, false otherwise. @param c the string in question @return true if c is alphanumeric or underscore, false if not

func IsValidAttribute

func IsValidAttribute(attribute string) (valid bool)

IsValidAttribute validates an attribute name

func LengthWithEscapeCharacters

func LengthWithEscapeCharacters(str string) (result int)

LengthWithEscapeCharacters counts the number of characters with escape characters

func ValidateFS

func ValidateFS(in string) error

ValidateFS is not part of the reference implementation pseudo code found in the CPE 2.3 specification. It enforces three rules found in the specification:

Formatted string must start with the characters "cpe:2.3:"
A formatted string must contain 11 components
A formatted string must not contain empty components

If any rule is violated, a ParseException is thrown.

func ValidateStringValue

func ValidateStringValue(svalue string) (err error)

ValidateStringValue validates an string value

func ValidateURI

func ValidateURI(in string) error

ValidateURI is not part of the reference implementation pseudo code found in the CPE 2.3 specification. It enforces two rules in the specification:

URI must start with the characters "cpe:/"
A URI may not contain more than 7 components

If either rule is violated, a ParseErr is thrown.

Types

type LogicalValue

type LogicalValue struct {
	Any bool
	Na  bool
}

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

func NewLogicalValue

func NewLogicalValue(t string) (lv LogicalValue, err error)

NewLogicalValue returns Logicalvalue

func (LogicalValue) IsANY

func (lv LogicalValue) IsANY() bool

IsANY returns whether any is true

func (LogicalValue) IsNA

func (lv LogicalValue) IsNA() bool

IsNA returns whether na is true

func (LogicalValue) String

func (lv LogicalValue) String() string

String : String

type WellFormedName

type WellFormedName map[string]interface{}

WellFormedName represents a Well Formed Name, as defined in the CPE Specification version 2.3.

@see <a href="http://cpe.mitre.org">cpe.mitre.org</a> for details.

func NewWellFormedName

func NewWellFormedName() WellFormedName

NewWellFormedName constructs a new WellFormedName object, with all components set to the default value "ANY".

func (WellFormedName) Get

func (wfn WellFormedName) Get(attribute string) interface{}

Get gets attribute @param attribute String representing the component value to get @return the String value of the given component, or default value "ANY" if the component does not exist

func (WellFormedName) GetString

func (wfn WellFormedName) GetString(attribute string) string

GetString gets attribute as string @param attribute String representing the component value to get @return the String value of the given component, or default value "ANY" if the component does not exist

func (WellFormedName) Initialize

func (wfn WellFormedName) Initialize(part, vendor, product, version, update, edition, language, swEdition, targetSw, targetHw, other interface{})

Initialize sets each component to the given parameter value. If a parameter is null, the component is set to the default value "ANY". @param part string representing the part component @param vendor string representing the vendor component @param product string representing the product component @param version string representing the version component @param update string representing the update component @param edition string representing the edition component @param language string representing the language component @param sw_edition string representing the sw_edition component @param target_sw string representing the target_sw component @param target_hw string representing the target_hw component @param other string representing the other component

func (WellFormedName) Set

func (wfn WellFormedName) Set(attribute string, value interface{}) (err error)

Set sets the given attribute to value, if the attribute is in the list of permissible components @param attribute String representing the component to set @param value Object representing the value of the given component

func (WellFormedName) String

func (wfn WellFormedName) String() string

String returns string representation of the WellFormedName

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL