WriteUint v0.1.0

Source
Appends the decimal digits of an unsigned integer to a builder.

Package: Format

Signature

func WriteUint(
    builder: *StringBuilder,
    value: uint64
);

Parameters

NameTypeDescription
builder*StringBuilderThe builder to append to.
valueuint64The value to write.

As with WriteInt, there is one overload rather than one per width: a narrower unsigned value widens to uint64 on the way in, which loses nothing.

Remarks

Writes the digits and nothing else — there is no sign on an unsigned value. Zero is the single digit 0, and the largest uint64, 18446744073709551615, is the longest output there is at twenty digits.

Nothing is allocated beyond whatever growth the builder needs. This is the function to reach for while accumulating; ToString is the one that hands back a String of its own.

Example

import Format::WriteUint;
import Text::StringBuilder;

func Main() -> int {
    var builder = StringBuilder::New();
    builder.Append("read ");
    WriteUint(@builder, 4096u64);
    builder.Append(" bytes");

    var line = builder.IntoString(); // "read 4096 bytes"

    line.Free();
    return 0;
}

See also