value

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package value parses lexical forms, canonicalizes values, and derives XSD value-space keys.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIndeterminate reports that duration contains years or months.
	ErrIndeterminate = errors.New("duration conversion indeterminate")
	// ErrOverflow reports that duration cannot fit in time.Duration.
	ErrOverflow = errors.New("duration conversion overflow")
	// ErrComponentRange reports that one duration component is out of range.
	ErrComponentRange = errors.New("duration component out of range")
)
View Source
var ErrIndeterminateComparison = errors.New("time comparison indeterminate")

ErrIndeterminateComparison matches XSD indeterminate temporal ordering.

View Source
var ErrIndeterminateDurationComparison = errors.New("duration comparison indeterminate")

ErrIndeterminateDurationComparison reports that two durations are incomparable in XSD value space.

Functions

func AnyValueEqual added in v0.0.29

func AnyValueEqual[V any](left, right []V, equal func(V, V) bool) bool

AnyValueEqual reports whether any value in left equals any in right.

func Canonical added in v0.0.29

func Canonical(v Value) string

Canonical returns the canonical lexical representation for temporal values.

func CanonicalDateTimeString

func CanonicalDateTimeString(value time.Time, kind string, tzKind TimezoneKind) string

CanonicalDateTimeString formats a time value into the canonical lexical form for the given XML Schema temporal kind.

func CanonicalDurationString added in v0.0.29

func CanonicalDurationString(dur Duration) string

CanonicalDurationString formats a parsed duration in canonical lexical form used by validators.

func CanonicalFloat

func CanonicalFloat(value float64, bits int) string

CanonicalFloat returns the canonical lexical form for float/double values.

func CanonicalQName

func CanonicalQName(value []byte, resolver NSResolver, dst []byte) ([]byte, error)

CanonicalQName resolves a lexical QName to canonical bytes (uri + 0 + local).

func CanonicalizeBoolean added in v0.0.29

func CanonicalizeBoolean(normalized []byte) (bool, []byte, error)

CanonicalizeBoolean parses and canonicalizes XSD boolean lexical values.

func CanonicalizeDecimal added in v0.0.29

func CanonicalizeDecimal(normalized []byte) (num.Dec, []byte, error)

CanonicalizeDecimal parses and canonicalizes XSD decimal lexical values.

func CanonicalizeFloat32 added in v0.0.29

func CanonicalizeFloat32(normalized []byte) (float32, num.FloatClass, []byte, error)

CanonicalizeFloat32 parses and canonicalizes XSD float lexical values.

func CanonicalizeFloat64 added in v0.0.29

func CanonicalizeFloat64(normalized []byte) (float64, num.FloatClass, []byte, error)

CanonicalizeFloat64 parses and canonicalizes XSD double lexical values.

func CanonicalizeInteger added in v0.0.29

func CanonicalizeInteger(normalized []byte, validate func(num.Int) error) (num.Int, []byte, error)

CanonicalizeInteger parses and canonicalizes XSD integer lexical values.

func Compare added in v0.0.29

func Compare(left, right Value) (int, error)

Compare compares temporal values in XSD order.

func CompareDuration added in v0.0.29

func CompareDuration(left, right Duration) (int, error)

CompareDuration orders durations using the XSD 1.0 order relation for duration.

func Equal added in v0.0.29

func Equal(left, right Value) bool

Equal compares temporal values in XSD value space for the same primitive.

func FieldsXMLWhitespaceSeq added in v0.0.22

func FieldsXMLWhitespaceSeq(in []byte) iter.Seq[[]byte]

FieldsXMLWhitespaceSeq yields XML whitespace-separated fields without allocation.

func FieldsXMLWhitespaceStringSeq added in v0.0.24

func FieldsXMLWhitespaceStringSeq(in string) iter.Seq[string]

FieldsXMLWhitespaceStringSeq yields XML whitespace-separated string fields.

func ForEachXMLWhitespaceField added in v0.0.22

func ForEachXMLWhitespaceField(in []byte, fn func([]byte) error) (int, error)

ForEachXMLWhitespaceField splits input on XML whitespace and calls fn per field. It returns the number of fields seen; iteration itself does not allocate.

func FormatFraction added in v0.0.23

func FormatFraction(nanos int) string

FormatFraction renders fractional seconds without trailing zeros.

func HasTimezone

func HasTimezone(lexical []byte) bool

HasTimezone reports whether a lexical temporal value includes a timezone.

func IsValidDate added in v0.0.29

func IsValidDate(year, month, day int) bool

IsValidDate reports whether the date is valid in the Gregorian calendar.

func IsXMLWhitespaceByte added in v0.0.22

func IsXMLWhitespaceByte(b byte) bool

IsXMLWhitespaceByte reports whether the byte is XML whitespace.

func ListValuesEqual added in v0.0.29

func ListValuesEqual[V any](left, right [][]V, equal func(V, V) bool) bool

ListValuesEqual reports whether two lists of value variants are equal item-by-item.

func NormalizeWhitespace

func NormalizeWhitespace(mode WhitespaceMode, in, dst []byte) []byte

NormalizeWhitespace applies the whitespace mode using dst as scratch. It returns a slice that may alias the input when no changes are needed.

func ParseAnyURI added in v0.0.22

func ParseAnyURI(lexical []byte) (string, error)

ParseAnyURI parses an xs:anyURI lexical value and validates its syntax.

func ParseBase64Binary added in v0.0.22

func ParseBase64Binary(lexical []byte) ([]byte, error)

ParseBase64Binary parses an xs:base64Binary lexical value into bytes.

func ParseBoolean

func ParseBoolean(lexical []byte) (bool, error)

ParseBoolean parses a boolean lexical value into a bool.

func ParseByte added in v0.0.22

func ParseByte(lexical []byte) (int8, error)

ParseByte parses an xs:byte lexical value into int8.

func ParseDate

func ParseDate(lexical []byte) (time.Time, error)

ParseDate parses an xs:date lexical value.

func ParseDateParts added in v0.0.29

func ParseDateParts(value string) (int, int, int, bool)

ParseDateParts parses YYYY-MM-DD into year, month, day.

func ParseDateTime

func ParseDateTime(lexical []byte) (time.Time, error)

ParseDateTime parses an xs:dateTime lexical value.

func ParseDecimal

func ParseDecimal(lexical []byte) (num.Dec, error)

ParseDecimal parses a decimal lexical value into num.Dec.

func ParseDouble

func ParseDouble(lexical []byte) (float64, error)

ParseDouble parses a double lexical value into float64.

func ParseFixedDigits added in v0.0.29

func ParseFixedDigits(value string, start, length int) (int, bool)

ParseFixedDigits parses a fixed-width digit sequence from value.

func ParseFloat

func ParseFloat(lexical []byte) (float32, error)

ParseFloat parses a float lexical value into float32.

func ParseGDay

func ParseGDay(lexical []byte) (time.Time, error)

ParseGDay parses an xs:gDay lexical value.

func ParseGMonth

func ParseGMonth(lexical []byte) (time.Time, error)

ParseGMonth parses an xs:gMonth lexical value.

func ParseGMonthDay

func ParseGMonthDay(lexical []byte) (time.Time, error)

ParseGMonthDay parses an xs:gMonthDay lexical value.

func ParseGYear

func ParseGYear(lexical []byte) (time.Time, error)

ParseGYear parses an xs:gYear lexical value.

func ParseGYearMonth

func ParseGYearMonth(lexical []byte) (time.Time, error)

ParseGYearMonth parses an xs:gYearMonth lexical value.

func ParseHexBinary added in v0.0.22

func ParseHexBinary(lexical []byte) ([]byte, error)

ParseHexBinary parses an xs:hexBinary lexical value into bytes.

func ParseInt added in v0.0.22

func ParseInt(lexical []byte) (int32, error)

ParseInt parses an xs:int lexical value into int32.

func ParseInteger

func ParseInteger(lexical []byte) (num.Int, error)

ParseInteger parses an integer lexical value into num.Int.

func ParseListValueVariants added in v0.0.29

func ParseListValueVariants[V any](lexical string, parseItem func(string) ([]V, error)) ([][]V, error)

ParseListValueVariants parses list items into per-item variants using XML whitespace splitting.

func ParseLong added in v0.0.22

func ParseLong(lexical []byte) (int64, error)

ParseLong parses an xs:long lexical value into int64.

func ParseShort added in v0.0.22

func ParseShort(lexical []byte) (int16, error)

ParseShort parses an xs:short lexical value into int16.

func ParseTime

func ParseTime(lexical []byte) (time.Time, error)

ParseTime parses an xs:time lexical value.

func ParseTimeParts added in v0.0.29

func ParseTimeParts(value string) (int, int, int, int, bool)

ParseTimeParts parses hh:mm:ss[.fff] into time parts and fractional length.

func ParseToStdDuration added in v0.0.29

func ParseToStdDuration(text string) (time.Duration, error)

ParseToStdDuration parses an XSD duration and converts it to time.Duration.

func ParseUnionValueVariants added in v0.0.29

func ParseUnionValueVariants[T any, V any](lexical string, members []T, parseMember func(string, T) ([]V, error)) ([]V, error)

ParseUnionValueVariants parses a value against union members and returns all matching variants.

func ParseUnsignedByte added in v0.0.22

func ParseUnsignedByte(lexical []byte) (uint8, error)

ParseUnsignedByte parses an xs:unsignedByte lexical value into uint8.

func ParseUnsignedInt added in v0.0.22

func ParseUnsignedInt(lexical []byte) (uint32, error)

ParseUnsignedInt parses an xs:unsignedInt lexical value into uint32.

func ParseUnsignedLong added in v0.0.22

func ParseUnsignedLong(lexical []byte) (uint64, error)

ParseUnsignedLong parses an xs:unsignedLong lexical value into uint64.

func ParseUnsignedShort added in v0.0.22

func ParseUnsignedShort(lexical []byte) (uint16, error)

ParseUnsignedShort parses an xs:unsignedShort lexical value into uint16.

func SplitTimezone added in v0.0.29

func SplitTimezone(value string) (string, string)

SplitTimezone separates a lexical date/time value into the main portion and timezone suffix.

func SplitXMLWhitespace added in v0.0.22

func SplitXMLWhitespace(in []byte) [][]byte

SplitXMLWhitespace splits input on XML whitespace and skips empty fields.

func ToStdDuration added in v0.0.29

func ToStdDuration(parsed Duration) (time.Duration, error)

ToStdDuration converts a parsed XSD duration to time.Duration.

func TrimXMLWhitespace

func TrimXMLWhitespace(in []byte) []byte

TrimXMLWhitespace removes leading and trailing XML whitespace without allocation.

func TrimXMLWhitespaceString added in v0.0.22

func TrimXMLWhitespaceString(in string) string

TrimXMLWhitespaceString removes leading and trailing XML whitespace. It returns the original string when no trimming is needed.

func UpperHex added in v0.0.24

func UpperHex(dst, src []byte) []byte

UpperHex renders src as uppercase hexadecimal into dst. It reuses dst when capacity allows and returns the resulting slice.

func ValidateAnyURI

func ValidateAnyURI(value []byte) error

ValidateAnyURI validates xs:anyURI lexical constraints.

func ValidateLanguage

func ValidateLanguage(value []byte) error

ValidateLanguage validates xs:language lexical constraints.

func ValidateNCName

func ValidateNCName(value []byte) error

ValidateNCName validates xs:NCName lexical constraints.

func ValidateNMTOKEN

func ValidateNMTOKEN(value []byte) error

ValidateNMTOKEN validates xs:NMTOKEN lexical constraints.

func ValidateName

func ValidateName(value []byte) error

ValidateName validates xs:Name lexical constraints.

func ValidateQName added in v0.0.22

func ValidateQName(value []byte) error

ValidateQName validates xs:QName lexical constraints.

func ValidateTimezoneOffset added in v0.0.29

func ValidateTimezoneOffset(tz string) error

ValidateTimezoneOffset validates a timezone offset suffix.

func ValidateToken

func ValidateToken(value []byte) error

ValidateToken validates xs:token lexical constraints.

Types

type Duration added in v0.0.29

type Duration struct {
	Seconds  num.Dec
	Years    int
	Months   int
	Days     int
	Hours    int
	Minutes  int
	Negative bool
}

Duration is a parsed XSD duration lexical value.

func CanonicalizeDuration added in v0.0.29

func CanonicalizeDuration(normalized []byte) (Duration, []byte, error)

CanonicalizeDuration parses and canonicalizes XSD duration lexical values.

func ParseDuration added in v0.0.29

func ParseDuration(s string) (Duration, error)

ParseDuration parses an XSD duration lexical value.

type Kind added in v0.0.29

type Kind uint8

Kind identifies an XSD temporal primitive.

const (
	KindInvalid Kind = iota
	KindDateTime
	KindDate
	KindTime
	KindGYearMonth
	KindGYear
	KindGMonthDay
	KindGDay
	KindGMonth
)

func KindFromPrimitiveName added in v0.0.29

func KindFromPrimitiveName(name string) (Kind, bool)

KindFromPrimitiveName resolves an XSD primitive name to a temporal kind.

func (Kind) String added in v0.0.29

func (k Kind) String() string

String returns the XSD primitive name for the temporal kind.

type NSResolver

type NSResolver interface {
	ResolvePrefix(prefix []byte) ([]byte, bool)
}

NSResolver resolves QName prefixes to namespace URIs. The empty prefix uses the default namespace when present.

type TimezoneKind added in v0.0.22

type TimezoneKind uint8

TimezoneKind describes whether a lexical value included a timezone.

const (
	TZNone TimezoneKind = iota
	TZKnown
)

func TimezoneKindFromLexical added in v0.0.22

func TimezoneKindFromLexical(lexical []byte) TimezoneKind

TimezoneKindFromLexical reports the timezone kind for a lexical value.

type Value added in v0.0.29

type Value struct {
	Time         time.Time
	Kind         Kind
	TimezoneKind TimezoneKind
	LeapSecond   bool
}

Value stores temporal semantics used for equality, ordering, and keying.

func Parse added in v0.0.29

func Parse(kind Kind, lexical []byte) (Value, error)

Parse parses an XSD temporal lexical value into semantic representation.

func ParsePrimitive added in v0.0.29

func ParsePrimitive(primitiveName string, lexical []byte) (Value, error)

ParsePrimitive parses an XSD temporal lexical value by primitive name.

type WhitespaceMode added in v0.0.23

type WhitespaceMode uint8

WhitespaceMode controls XML whitespace normalization.

const (
	// WhitespacePreserve keeps lexical whitespace unchanged.
	WhitespacePreserve WhitespaceMode = iota
	// WhitespaceReplace converts XML whitespace characters to spaces.
	WhitespaceReplace
	// WhitespaceCollapse replaces XML whitespace with single spaces and trims edges.
	WhitespaceCollapse
)

Jump to

Keyboard shortcuts

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