internal

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FastRound

func FastRound(x float64) (rounded float64, ok bool)

FastRound returns x rounded half away from zero to an integer and whether that provably equals rounding the exact value that x approximates, given that x differs from the exact value by less than |x|·2^-51. Callers get that bound from a few float64 roundings by a factor of at most 1±2^-53 each, and fall back to an order of magnitude slower exact computation, like rounding decimal digits or big.Rat arithmetic, if ok is false. The relative bound doesn't hold for subnormal floats, so a caller has to show that they round the same way or never make ok true.

If the distance of x to the nearest half-integer exceeds the four times larger |x|·2^-49, x and the exact value lie strictly between the same two half-integers and round to the same integer. The distance x-rounded is exact (Sterbenz lemma), and 0.5 minus it is either exact or above 1/4, which exceeds the error below 2^48, the only range where the condition can hold. It never holds for NaN and ±Inf. If Go fuses the final multiplication that computed x into the distance, the distance is computed from the exact product and rounded once by at most 2^-54 instead, which is far below the bound for a nonzero rounded and changes nothing for a zero one.

func IsBlank

func IsBlank[S ~string](s S) bool

IsBlank reports whether s is empty after strutil.TrimSpace.

func JoinCurrencyAmount

func JoinCurrencyAmount(currency, amount string, currencyFirst bool) string

JoinCurrencyAmount returns the formatted amount with the currency code and a space before it if currencyFirst is true, else after it, or the amount alone for an empty currency. It is the text format of money.CurrencyAmount and money.CurrencyDecimalAmount, which the strfmt money formats write too.

func MarshalJSONNormalized

func MarshalJSONNormalized[S ~string](s S, nullable bool, normalize func(S) (S, error), isBlank func(S) bool) ([]byte, error)

MarshalJSONNormalized implements encoding/json.Marshaler for a normalizing string type by writing NormalizedOrRaw as JSON string, or JSON null instead of "" for a blank value if nullable is true.

func MarshalTextNormalized

func MarshalTextNormalized[S ~string](s S, normalize func(S) (S, error), isBlank func(S) bool) ([]byte, error)

MarshalTextNormalized implements encoding.TextMarshaler for a normalizing string type by returning NormalizedOrRaw.

func MarshalXMLAttrText

func MarshalXMLAttrText[T encoding.TextMarshaler](v *T, name xml.Name) (xml.Attr, error)

MarshalXMLAttrText implements encoding/xml.MarshalerAttr for a pointer to a type with a value receiver MarshalText: it writes the text of MarshalText like encoding/xml does, and no attribute for a nil v. encoding/xml calls a value receiver MarshalText through a nil pointer attribute field and panics, but checks for MarshalerAttr first.

func NormalizedOrRaw

func NormalizedOrRaw[S ~string](s S, normalize func(S) (S, error), isBlank func(S) bool) S

NormalizedOrRaw returns "" for a blank s, the result of normalize when that succeeds, or else s unchanged.

func ParseFloatArray

func ParseFloatArray(src []byte, typeName string) ([]float64, error)

ParseFloatArray parses a PostgreSQL float array literal like {1.5,2,3}, naming typeName in errors. An empty src and the empty array {} return an empty, non-nil slice.

func ParseIntArray

func ParseIntArray(src []byte, typeName string) ([]int64, error)

ParseIntArray parses a PostgreSQL integer array literal like {1,2,3}, naming typeName in errors. An empty src and the empty array {} return an empty, non-nil slice.

func SQLArrayLiteral

func SQLArrayLiteral(s []string) string

SQLArrayLiteral joins the passed strings as an SQL array literal A nil slice will produce NULL, pass an empty non nil slice to get the empty SQL array literal {}.

func ScanNormalized

func ScanNormalized[S ~string](dst *S, value any, normalize func(S) (S, error), isBlank func(S) bool) error

ScanNormalized implements database/sql.Scanner for a normalizing string type: a string or []byte is stored with NormalizedOrRaw, SQL NULL as "". Other types are an error.

func ScanStringNormalized

func ScanStringNormalized[S ~string](dst *S, source string, validate, nullable bool, normalize func(S) (S, error), isBlank func(S) bool) error

ScanStringNormalized implements the ScanString method of a normalizing string type used by the strfmt package. The strings "NULL", "null" and "nil" set a nullable type to null. Without validate it stores like NormalizedOrRaw, with validate it stores the normalized value or returns the error of normalize, also for a blank value of a type whose normalize rejects blank values.

func SplitArray

func SplitArray(array string) ([]string, error)

SplitArray splits an SQL or JSON array into its top level elements. Array elements that are quoted strings will not be unquoted, use SplitArrayValues to get the values of quoted string elements. Returns nil in case of an empty array ("{}" or "[]"). Passing "null" or "NULL" as array will return nil without an error.

A trailing comma announces an element that is not there and yields an empty string as last element. PostgreSQL rejects such a literal, this parser reports the announced element instead of dropping it silently.

func SplitArrayValues

func SplitArrayValues(array string) ([]string, error)

SplitArrayValues splits an SQL or JSON array into its top level elements like SplitArray and returns the value of every element that is a double quoted string with the quotes removed and the escape sequences of the parsed array syntax undone.

A backslash escapes the following character in a PostgreSQL array element whether it is quoted or not, so every element of an SQL array is unescaped. In a JSON array only double quoted strings are, every other element, like the objects of a JSON array of objects, is returned unchanged.

Returns an error for a quoted element of a JSON array that is not a valid JSON string, like one with an invalid escape sequence.

An unquoted NULL element of an SQL array (null in a JSON array) is returned as the string "NULL" ("null") and is indistinguishable from a quoted "NULL" ("null") string element. Use SplitArray to tell them apart, its elements correspond by index and a quoted element still has its quotes there.

func Trim

func Trim[S ~string](s S) (S, error)

Trim returns s with surrounding whitespace removed. The error is always nil, so the reading and writing helpers apply it to every value, including one the type's Normalized rejects.

func TrimUpper

func TrimUpper[S ~string](s S) (S, error)

TrimUpper returns s with surrounding whitespace removed and letters uppercased. The error is always nil, like Trim.

func UnmarshalJSONNormalized

func UnmarshalJSONNormalized[S ~string](dst *S, data []byte, nullable bool, normalize func(S) (S, error), isBlank func(S) bool) error

UnmarshalJSONNormalized implements encoding/json.Unmarshaler for a normalizing string type by storing a JSON string with NormalizedOrRaw. JSON null sets "" if nullable is true, which a nullable type needs to reset a field that holds a value, else it is a no-op like encoding/json does for null and a non-pointer value. Any other JSON value is an error that names the type S.

func UnmarshalXMLAttrNormalized

func UnmarshalXMLAttrNormalized[S ~string](dst *S, attr xml.Attr, normalize func(S) (S, error), isBlank func(S) bool) error

UnmarshalXMLAttrNormalized implements encoding/xml.UnmarshalerAttr for a normalizing string type by storing the attribute value with NormalizedOrRaw.

func UnmarshalXMLNormalized

func UnmarshalXMLNormalized[S ~string](dst *S, d *xml.Decoder, start xml.StartElement, normalize func(S) (S, error), isBlank func(S) bool) error

UnmarshalXMLNormalized implements encoding/xml.Unmarshaler for a normalizing string type by storing the text of the element with NormalizedOrRaw.

func ValueNormalized

func ValueNormalized[S ~string](s S, normalize func(S) (S, error), isBlank func(S) bool) (driver.Value, error)

ValueNormalized implements database/sql/driver.Valuer for a normalizing string type: SQL NULL for a blank value, the result of normalize as string, or the error of normalize when it fails.

Types

This section is empty.

Directories

Path Synopsis
Package collections reproduces the abstract collection interfaces documented by the Go 1.28 collections proposal, https://go.dev/issue/80590.
Package collections reproduces the abstract collection interfaces documented by the Go 1.28 collections proposal, https://go.dev/issue/80590.
settest
Package settest provides a reusable conformance test for the abstract set interface of the Go 1.28 collections proposal, https://go.dev/issue/80590.
Package settest provides a reusable conformance test for the abstract set interface of the Go 1.28 collections proposal, https://go.dev/issue/80590.
Package normtest provides a reusable conformance test for the reading and writing contract of the string types of this module, like country.Code, vat.ID or date.Date.
Package normtest provides a reusable conformance test for the reading and writing contract of the string types of this module, like country.Code, vat.ID or date.Date.
pq
oid
Package oid contains OID constants as defined by the Postgres server.
Package oid contains OID constants as defined by the Postgres server.
Package xmlattrtest checks how encoding/xml writes a type as attribute.
Package xmlattrtest checks how encoding/xml writes a type as attribute.

Jump to

Keyboard shortcuts

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