Canonical
in package
The canonical form of a value (DXN.md §1.5): one `.dxn` rendering, fixed down to the byte, so values from different implementations can be compared as text.
Not Dextrin::encode(). The printer chooses what reads best;
this chooses nothing. One space between items, maps and sets in
canonical order (by code point of each canonical form, which is the
byte order of their UTF-8, so strcmp is exactly right), floats by
one exact algorithm, strings with one fixed set of escapes: the rules
every DXN implementation follows, which is what lets the Dextrin
Conformance Suite compare two strings instead of two values.
Nothing is normalised. A decimal keeps its scale and its sign, a
rational is not reduced. Keyed structs and ordered maps keep the order
they hold: in a %schema body the order of entries is the order of
the fields.
Table of Contents
Methods
- float() : string
- A float by DXN.md §1.5: the shortest digits that read back exactly, ECMAScript's thresholds, `.0` on a whole number, no `+` in an exponent, and the sign of negative zero kept. The digits are PHP's own shortest conversion, under a `serialize_precision` of -1 set for the moment and put back as it was ({@see self::shortest()}), so no ini setting changes them. Public so {@see Text\Printer} writes a float the same way.
- print() : string
- The canonical form of `$value`.
- __construct() : mixed
- charBody() : string
- decimal() : string
- A decimal as it was given: its digits with exactly its scale and its sign, negative zero included; a positive exponent written out.
- entries() : string
- Entries as written, in canonical order of their keys when `$sort`, in the order held otherwise: shorthand for a keyword whose name is an identifier, the arrow for every other key.
- escaped() : string
- items() : string
- keyword() : string
- laidOut() : string
- The digits with value 0.d1..dk × 10^n, laid out by DXN.md §1.5.
- mapPairs() : array<int, array{0: mixed, 1: mixed}>
- A native map's entries as DXN keys and values, recovering each key the way {@see MapBuilder} stored it.
- quoted() : string
- shortest() : array{string, int}
- The fewest significant digits that read back as `$magnitude`, and the n of 0.d1..dk × 10^n: PHP's own shortest conversion (`serialize_precision` -1), as every other implementation writes it.
- sorted() : array<int, string>
- Canonical order: by code point, which is the byte order of UTF-8.
- struct() : string
- A keyed struct's extra fields follow its declared ones in the order they were written; a positional struct's follow its items in canonical order of their keys (DXN.md §1.5).
- temporal() : string
- text() : string
Methods
float()
A float by DXN.md §1.5: the shortest digits that read back exactly, ECMAScript's thresholds, `.0` on a whole number, no `+` in an exponent, and the sign of negative zero kept. The digits are PHP's own shortest conversion, under a `serialize_precision` of -1 set for the moment and put back as it was ({@see self::shortest()}), so no ini setting changes them. Public so {@see Text\Printer} writes a float the same way.
public
static float(float $n) : string
Parameters
- $n : float
Return values
stringprint()
The canonical form of `$value`.
public
static print(mixed $value) : string
Parameters
- $value : mixed
Tags
Return values
string__construct()
private
__construct() : mixed
charBody()
private
static charBody(int $cp) : string
Parameters
- $cp : int
Return values
stringdecimal()
A decimal as it was given: its digits with exactly its scale and its sign, negative zero included; a positive exponent written out.
private
static decimal(DXNDecimal $d) : string
Parameters
- $d : DXNDecimal
Return values
stringentries()
Entries as written, in canonical order of their keys when `$sort`, in the order held otherwise: shorthand for a keyword whose name is an identifier, the arrow for every other key.
private
static entries(array<string|int, array{0: mixed, 1: mixed}> $pairs, bool $sort) : string
Parameters
- $pairs : array<string|int, array{0: mixed, 1: mixed}>
- $sort : bool
Return values
stringescaped()
private
static escaped(int $cp) : string
Parameters
- $cp : int
Return values
stringitems()
private
static items(array<string|int, mixed> $values) : string
Parameters
- $values : array<string|int, mixed>
Return values
stringkeyword()
private
static keyword(string $name) : string
Parameters
- $name : string
Return values
stringlaidOut()
The digits with value 0.d1..dk × 10^n, laid out by DXN.md §1.5.
private
static laidOut(string $digits, int $n) : string
Parameters
- $digits : string
- $n : int
Return values
stringmapPairs()
A native map's entries as DXN keys and values, recovering each key the way {@see MapBuilder} stored it.
private
static mapPairs(array<int|string, mixed> $map) : array<int, array{0: mixed, 1: mixed}>
Parameters
- $map : array<int|string, mixed>
Return values
array<int, array{0: mixed, 1: mixed}>quoted()
private
static quoted(string $s) : string
Parameters
- $s : string
Return values
stringshortest()
The fewest significant digits that read back as `$magnitude`, and the n of 0.d1..dk × 10^n: PHP's own shortest conversion (`serialize_precision` -1), as every other implementation writes it.
private
static shortest(float $magnitude) : array{string, int}
Trying %.Ne widths instead misses a power of two, where the
nearest N digits need not be the ones that read back.
Parameters
- $magnitude : float
Return values
array{string, int}sorted()
Canonical order: by code point, which is the byte order of UTF-8.
private
static sorted(array<int, string> $texts) : array<int, string>
Parameters
- $texts : array<int, string>
Return values
array<int, string>struct()
A keyed struct's extra fields follow its declared ones in the order they were written; a positional struct's follow its items in canonical order of their keys (DXN.md §1.5).
private
static struct(DXNStruct $value) : string
Parameters
- $value : DXNStruct
Return values
stringtemporal()
private
static temporal(mixed $value) : string
Parameters
- $value : mixed
Return values
stringtext()
private
static text(mixed $value) : string
Parameters
- $value : mixed