numeric

package
v0.0.0-...-2bc12df Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DurationRegex = regexp.MustCompile(
	"^(" + durationChunkRegex.String() + ")+$",
)

DurationRegex describes a valid duration value. See DurationOf for more details on what the individual units represent.

View Source
var SizeRegex = regexp.MustCompile(`^\d+[ckMGTP]$`)

SizeRegex describes a valid size value. See BytesOf for more details on what the individual units represent.

Functions

func BytesOf

func BytesOf(unit byte) int64

BytesOf returns the number of bytes specified by the given size unit. Valid size units are:

c => character (byte)
k => kibibyte
M => mebibyte
G => gibibyte
T => tebibyte
P => pebibyte

func DurationOf

func DurationOf(unit byte) int64

DurationOf returns the number of seconds specified by the given duration unit. Valid duration units are:

s => second
m => minute
h => hour
d => day
w => week

func ParseDuration

func ParseDuration(str string) (int64, error)

ParseDuration parses a duration value as an int64. Duration values are described by DurationRegex.

func ParsePositiveInt

func ParsePositiveInt(str string) (int64, error)

ParsePositiveInt parses a positive integer.

func ParseSize

func ParseSize(str string) (int64, error)

ParseSize parses a size value. Size values are described by SizeRegex.

Types

type Parser

type Parser func(string) (int64, error)

Parser parses numeric values.

func Bracket

func Bracket(p Parser) Parser

Bracket returns a new parser g that parses all numbers satifying the regex `{<number>}` where <number> is s.t. p(<number>) does not return an error. For example, if p parses "15" as the number 15, then g parses "{15}" as the number "15". Bracket's typically used to implement negation semantics. For example, Bracket(Negate(ParsePositiveInt)) returns a parser that parses all n <= 0, where each n is represented as {m} where m = -n.

Note that g returns a syntax error if p(<number>) returns a match error.

func Negate

func Negate(p Parser) Parser

Negate returns a new parser g that negates any number parsed by p. For example, if p parses "15" as "15", then g parses "15" as "-15".

type Predicate

type Predicate func(int64) bool

Predicate represents a Numeric predicate

func ParsePredicate

func ParsePredicate(str string, parsers ...Parser) (Predicate, int, error)

ParsePredicate parses a numeric predicate from str. Str should satisfy the regex `(\+|\-)?<number>`, where <number> is s.t. that parser(<number>) does not return an error for at least one parser in parsers. The returned value is the parsed predicate and the id of the parser that parsed <number>.

func (Predicate) IsSatisfiedBy

func (p1 Predicate) IsSatisfiedBy(v interface{}) bool

IsSatisfiedBy returns true if v satisfies the predicate, false otherwise

func (Predicate) Negate

func (p1 Predicate) Negate() predicate.Predicate

Negate returns Not(p1)

Jump to

Keyboard shortcuts

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