toAlphaInto

Translates an integer into an alphanumeric string. Assumes ASCII. Overload that takes an output range sink.

@safe
void
toAlphaInto
(
size_t maxDigits = 19
uint leadingZeroes = 0
Num
Sink
)
(
const Num num
,
auto ref Sink sink
)

Parameters

maxDigits

The maximum number of digits to expect input of.

leadingZeroes

The minimum amount of leading zeroes to include in the output, mirroring the format specifier "%0nd".

num Num

Integer to translate into string.

sink Sink

Output range sink.

Examples

Appender!(char[]) sink;
int num = 12345;
num.toAlphaInto(sink);
assert(sink.data == "12345");
assert(sink.data == num.to!string);
import std.array : Appender;

Appender!(char[]) sink;

{
    enum num = 123_456;
    num.toAlphaInto(sink);
    assert((sink.data == "123456"), sink.data);
    sink.clear();
}
{
    enum num = 0;
    num.toAlphaInto(sink);
    assert((sink.data == "0"), sink.data);
    sink.clear();
}
{
    enum num = 999;
    num.toAlphaInto(sink);
    assert((sink.data == "999"), sink.data);
    sink.clear();
}
{
    enum num = -987;
    num.toAlphaInto(sink);
    assert((sink.data == "-987"), sink.data);
    sink.clear();
}
{
    enum num = 123;
    num.toAlphaInto!(12, 6)(sink);
    assert((sink.data == "000123"), sink.data);
    sink.clear();
}
{
    enum num = -1;
    num.toAlphaInto!(3, 3)(sink);
    assert((sink.data == "-001"), sink.data);
    sink.clear();
}
{
    enum num = -123_456_789_012_345L;
    num.toAlphaInto!15(sink);
    assert((sink.data == "-123456789012345"), sink.data);
    sink.clear();
}
{
    enum num = long.min;
    num.toAlphaInto(sink);
    assert((sink.data == "-9223372036854775808"), sink.data);
    //sink.clear();
}