Writing integers v0.1.0
MaxDecimalDigits
pub const MaxDecimalDigits: uint = 20;
The most digits a uint64 ever needs, for 18446744073709551615.
WriteUint
pub func WriteUint(cursor: &var ByteCursor, value: uint64)
Writes the decimal digits of an unsigned value. A division loop produces them least significant first, so they land in a small buffer and go back reversed.
Parameters
| Name | Type | Description |
|---|---|---|
cursor | &var ByteCursor | the buffer the digits are written into |
value | uint64 | the value to act on |
WriteInt
pub func WriteInt(cursor: &var ByteCursor, value: int64)
Writes the sign, then the magnitude.
The magnitude is taken in uint64 rather than by negating within int64, because the most negative int64 has
no positive counterpart there: negating it overflows straight back to itself. Two's complement gives the right
answer for that value and for every other one.
Parameters
| Name | Type | Description |
|---|---|---|
cursor | &var ByteCursor | the buffer the digits are written into |
value | int64 | the value to act on |
WriteIntegerDigits
pub func WriteIntegerDigits(
writer: &var TextWriter,
spec: FormatSpec,
digits: char8[..],
count: uint,
negative: bool
) -> ! FormatError
Writes an integer whose digits are already produced, applying sign, prefix, zero-padding and alignment.
digits holds the digits least significant first, which is the order a division loop makes them; count says
how many. Zero-padding puts its zeros between the sign and the digits and wins over alignment when both are
asked for. Nothing here allocates or copies the digits: each piece goes to the writer as it is reached.
Reports whatever the writer reported, stopping at the first refusal.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
digits | char8[..] | the decimal or based digits, least significant first |
count | uint | how many entries of digits are meaningful |
negative | bool | whether a minus sign precedes the digits |
Returns: success when the complete rendering was accepted
WriteIntegerSpec
pub func WriteIntegerSpec(
writer: &var TextWriter,
spec: FormatSpec,
magnitude: uint64,
negative: bool
) -> ! FormatError
Writes an integer under the whole of spec: base, sign, alternate prefix, zero-padding and alignment.
magnitude is the absolute value and negative its sign, kept apart because the most negative value of a
signed width has no positive counterpart to negate into.
Reports whatever the writer reported.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
magnitude | uint64 | the absolute value to render |
negative | bool | whether the value is negative |
Returns: success when the complete rendering was accepted