Documentation
¶
Overview ¶
Package value is the typed value model of evaluation: what queries return, filters transform, predicates compare and templates render.
A Value is one of Null, Bool, Int, BigInt, Float, String, Bytes, List, Object, Date, Nodeset, Unit, Regex or HTTPResponse. Numbers compare across representations (Int 1 equals Float 1.0). Objects keep the member order they were built with; DecodeJSON sorts members by key.
Values have three textual forms: Display (plain text, used inside lists and messages), Repr (`kind <display>`, the actual side of an assert failure) and Expected (the expected side). Render is the form a template placeholder produces; only scalar values are renderable.
Index ¶
- Variables
- func Display(v Value) string
- func Equal(a, b Value) bool
- func Expected(v Value) string
- func FormatFloat(f float64) string
- func FormatYear(y int) string
- func Render(v Value) (string, bool)
- func Repr(v Value) string
- func TranslateRegex(pattern string) string
- type BigInt
- type Bool
- type Bytes
- type Date
- type Float
- type HTTPResponse
- type Int
- type Kind
- type List
- type Member
- type Nodeset
- type Null
- type Object
- type Ordering
- type Regex
- type String
- type Unit
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrType = errors.New("types between actual and expected are not consistent")
ErrType reports values whose kinds cannot be compared.
Functions ¶
func Equal ¶
Equal reports whether a and b are equal. Numbers compare by value across representations; lists and objects compare member by member, in order. Regex and HTTPResponse values are never equal to anything.
func FormatFloat ¶
FormatFloat formats f in the shortest form that reads back exactly, without exponent; whole numbers keep a ".0" suffix ("1.0", "-2.0", "1e21" prints "1000000000000000000000.0"). Non-finite values print "inf", "-inf", "NaN".
func FormatYear ¶
FormatYear writes a year with at least four digits; years outside 0..9999 carry an explicit sign.
func Render ¶
Render returns the text a template placeholder produces for v. Only null, booleans, numbers, strings and dates are renderable.
func TranslateRegex ¶
TranslateRegex rewrites \d, \D, \w, \W, \s and \S to their Unicode definitions. Inside a bracket class \W and \S cannot be expressed as a union and keep their ASCII meaning; \b stays ASCII as well.
Types ¶
type BigInt ¶
type BigInt string
BigInt is a number too large for Int or Float, kept as its decimal text (for example a 30-digit JSON integer).
type HTTPResponse ¶
type HTTPResponse struct {
// Location is the absolute URL of the next hop, "" when HasLocation is false.
Location string
HasLocation bool
Status int
}
HTTPResponse is one hop of a redirect chain.
func (HTTPResponse) Kind ¶
func (HTTPResponse) Kind() Kind
type Kind ¶
type Kind int
Kind is the type of a value as shown in messages.
type Object ¶
type Object []Member
Object is a list of members.
type Ordering ¶
type Ordering int
Ordering is the result of comparing two values.
Orderings. Same means equal; Unordered is returned when a NaN is involved.
type Regex ¶
Regex is a compiled regular expression with its source.
type Unit ¶
type Unit struct{}
Unit is the value of a query that matched without producing data, such as a cookie attribute flag.
type Value ¶
type Value interface {
Kind() Kind
// contains filtered or unexported methods
}
Value is a typed evaluation value. The set of implementations is closed.
func DecodeJSON ¶
DecodeJSON parses a complete JSON document. Numbers are classified by NumberFromText without precision loss; object members are sorted by key (byte-wise) and a duplicated key keeps its last value.
func FromJSON ¶
FromJSON converts a value produced by encoding/json (decoded with UseNumber) into a Value.
func NumberFromText ¶
NumberFromText classifies a JSON number by its text: a fraction or exponent makes a Float (BigInt when not finite), an integer that fits 64 bits makes an Int, anything else a BigInt. A BigInt keeps the text with its exponent written `e+N` or `e-N`.