Documentation
¶
Index ¶
- func FastRound(x float64) (rounded float64, ok bool)
- func IsBlank[S ~string](s S) bool
- func JoinCurrencyAmount(currency, amount string, currencyFirst bool) string
- func MarshalJSONNormalized[S ~string](s S, nullable bool, normalize func(S) (S, error), isBlank func(S) bool) ([]byte, error)
- func MarshalTextNormalized[S ~string](s S, normalize func(S) (S, error), isBlank func(S) bool) ([]byte, error)
- func MarshalXMLAttrText[T encoding.TextMarshaler](v *T, name xml.Name) (xml.Attr, error)
- func NormalizedOrRaw[S ~string](s S, normalize func(S) (S, error), isBlank func(S) bool) S
- func ParseFloatArray(src []byte, typeName string) ([]float64, error)
- func ParseIntArray(src []byte, typeName string) ([]int64, error)
- func SQLArrayLiteral(s []string) string
- func ScanNormalized[S ~string](dst *S, value any, normalize func(S) (S, error), isBlank func(S) bool) error
- func ScanStringNormalized[S ~string](dst *S, source string, validate, nullable bool, normalize func(S) (S, error), ...) error
- func SplitArray(array string) ([]string, error)
- func SplitArrayValues(array string) ([]string, error)
- func Trim[S ~string](s S) (S, error)
- func TrimUpper[S ~string](s S) (S, error)
- func UnmarshalJSONNormalized[S ~string](dst *S, data []byte, nullable bool, normalize func(S) (S, error), ...) error
- func UnmarshalXMLAttrNormalized[S ~string](dst *S, attr xml.Attr, normalize func(S) (S, error), isBlank func(S) bool) error
- func UnmarshalXMLNormalized[S ~string](dst *S, d *xml.Decoder, start xml.StartElement, normalize func(S) (S, error), ...) error
- func ValueNormalized[S ~string](s S, normalize func(S) (S, error), isBlank func(S) bool) (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FastRound ¶
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 JoinCurrencyAmount ¶
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 ¶
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 ¶
NormalizedOrRaw returns "" for a blank s, the result of normalize when that succeeds, or else s unchanged.
func ParseFloatArray ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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. |
|
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. |