ocean.text.convert.Integer_tango

A set of functions for converting between string and integer values.

Applying the D "import alias" mechanism to this module is highly recommended, in order to limit namespace pollution:

import Integer = ocean.text.convert.Integer_tango;

auto i = Integer.parse ("32767");

Members

Functions

atoi
uint atoi(T[] s, int radix)

quick & dirty text-to-unsigned int converter. Use only when you know what the content is, or use parse() or convert() instead.

consume
T[] consume(T[] src, bool fp)

Consume a number from the input without converting it. Argument 'fp' enables floating-point consumption. Supports hex input for numbers which are prefixed appropriately

convert
ulong convert(T[] digits, uint radix, uint* ate)

Convert the provided 'digits' into an integer value, without checking for a sign or radix. The radix defaults to decimal (10).

format
const(T)[] format(T[] dst, N i, T[] fmt)

Supports format specifications via an array, where format follows the notation given below:

formatter
const(T)[] formatter(T[] dst, N i_, char type, char pre, int width)
Undocumented in source. Be warned that the author may not have intended to support it.
itoa
T[] itoa(T[] output, uint value, int radix)

quick & dirty unsigned to text converter, where the provided output must be large enough to house the result (10 digits in the largest case). For mainstream use, consider utilizing format() instead.

main
void main()
parse
long parse(T[] digits, uint radix, uint* ate)

Parse an integer value from the provided 'digits' string.

toInt
int toInt(T[] digits, uint radix)

Parse an integer value from the provided 'digits' string.

toLong
long toLong(T[] digits, uint radix)

Parse an integer value from the provided 'digits' string.

toString
char[] toString(long i, char[] fmt)

Wrapper to make life simpler. Returns a text version of the provided value.

toString16
wchar[] toString16(long i, wchar[] fmt)

Wrapper to make life simpler. Returns a text version of the provided value.

toString32
dchar[] toString32(long i, dchar[] fmt)

Wrapper to make life simpler. Returns a text version of the provided value.

toUlong
ulong toUlong(T[] digits, uint radix)

Parse an unsignedinteger value from the provided 'digits' string.

trim
uint trim(T[] digits, bool sign, uint radix)

Strip leading whitespace, extract an optional +/- sign, and an optional radix prefix. If the radix value matches an optional prefix, or the radix is zero, the prefix will be consumed and assigned. Where the radix is non zero and does not match an explicit prefix, the latter will remain unconsumed. Otherwise, radix will default to 10.

Meta

License

Tango Dual License: 3-Clause BSD License / Academic Free License v3.0. See LICENSE_TANGO.txt for details.

Version

Initial release: Nov 2005

Authors

Kris