## strconv+x86_64 +linux

The strconv module provides functions for parsing strings into numeric datatypes and formatting numbers into strings.

### Index

#### Types

type base = enum uint { DEFAULT = 0, // Default base - decimal BIN = 2, // Base 2, binary OCT = 8, // Base 8, octal DEC = 10, // Base 10, decimal HEX_UPPER = 16, // Base 16, UPPERCASE hexadecimal HEX = 16, // Alias for HEX_UPPER HEX_LOWER = 17, // Base 16, lowercase hexadecimal }; type fflags = enum uint { NONE = 0, SHOW_POS = 1 << 0, // Use a sign for both positive and negative numbers. SHOW_POINT = 1 << 1, // Include at least one decimal digit. UPPERCASE = 1 << 2, // Uppercase INFINITY and NAN. UPPER_EXP = 1 << 3, // Uppercase exponent symbols E and P rather than e and p. SHOW_POS_EXP = 1 << 4, // Use a sign for both positive and negative exponents. SHOW_TWO_EXP_DIGITS = 1 << 5, // Show at least two digits of the exponent. }; type ffmt = enum { // General format. Uses whichever of E and F is shortest, not accounting // for flags. G, // Scientific notation. Consists of a number in [1, 10), an 'e' (or 'E', // if UPPER_EXP flag is present), then an exponent. E, F, // Fixed-point notation. };

#### Errors

type error = !(invalid | overflow); type invalid = !size; type overflow = !void;

#### Functions

fn f32tos(n: f32) const str; fn f64tos(n: f64) const str; fn fftosf(h: io::handle, n: types::floating, f: ffmt, prec: (void | uint), flag: fflags) (size | io::error); fn floatingtos(n: types::floating, b: base = base::DEC) const str; fn ftosf(n: types::floating, f: ffmt, prec: (void | uint), flag: fflags) str; fn i16tos(i: i16, b: base = base::DEC) const str; fn i32tos(i: i32, b: base = base::DEC) const str; fn i64tos(i: i64, b: base = base::DEC) const str; fn i8tos(i: i8, b: base = base::DEC) const str; fn integertos(n: types::integer, b: base = base::DEC) const str; fn itos(i: int, b: base = base::DEC) const str; fn numerictos(n: types::numeric, b: base = base::DEC) const str; fn signedtos(n: types::signed, b: base = base::DEC) const str; fn stof32(s: str, b: base = base::DEC) (f32 | invalid | overflow); fn stof64(s: str, b: base = base::DEC) (f64 | invalid | overflow); fn stoi(s: str, base: base = base::DEC) (int | invalid | overflow); fn stoi16(s: str, base: base = base::DEC) (i16 | invalid | overflow); fn stoi32(s: str, base: base = base::DEC) (i32 | invalid | overflow); fn stoi64(s: str, base: base = base::DEC) (i64 | invalid | overflow); fn stoi8(s: str, base: base = base::DEC) (i8 | invalid | overflow); fn stou(s: str, base: base = base::DEC) (uint | invalid | overflow); fn stou16(s: str, base: base = base::DEC) (u16 | invalid | overflow); fn stou32(s: str, base: base = base::DEC) (u32 | invalid | overflow); fn stou64(s: str, base: base = base::DEC) (u64 | invalid | overflow); fn stou8(s: str, base: base = base::DEC) (u8 | invalid | overflow); fn stoz(s: str, base: base = base::DEC) (size | invalid | overflow); fn strerror(err: error) str; fn u16tos(u: u16, b: base = base::DEC) const str; fn u32tos(u: u32, b: base = base::DEC) const str; fn u64tos(u: u64, b: base = base::DEC) const str; fn u8tos(u: u8, b: base = base::DEC) const str; fn unsignedtos(n: types::unsigned, b: base = base::DEC) const str; fn uptrtos(uptr: uintptr, b: base = base::DEC) const str; fn utos(u: uint, b: base = base::DEC) const str; fn ztos(u: size, b: base = base::DEC) const str;

### Types

#### type base[link]

type base = enum uint { DEFAULT = 0, // Default base - decimal BIN = 2, // Base 2, binary OCT = 8, // Base 8, octal DEC = 10, // Base 10, decimal HEX_UPPER = 16, // Base 16, UPPERCASE hexadecimal HEX = 16, // Alias for HEX_UPPER HEX_LOWER = 17, // Base 16, lowercase hexadecimal };

The valid numeric bases for numeric conversions.

#### type fflags[link]

type fflags = enum uint { NONE = 0, SHOW_POS = 1 << 0, // Use a sign for both positive and negative numbers. SHOW_POINT = 1 << 1, // Include at least one decimal digit. UPPERCASE = 1 << 2, // Uppercase INFINITY and NAN. UPPER_EXP = 1 << 3, // Uppercase exponent symbols E and P rather than e and p. SHOW_POS_EXP = 1 << 4, // Use a sign for both positive and negative exponents. SHOW_TWO_EXP_DIGITS = 1 << 5, // Show at least two digits of the exponent. };

Flags for the ftosf functions.

#### type ffmt[link]

type ffmt = enum { // General format. Uses whichever of E and F is shortest, not accounting // for flags. G, // Scientific notation. Consists of a number in [1, 10), an 'e' (or 'E', // if UPPER_EXP flag is present), then an exponent. E, F, // Fixed-point notation. };

Format styles for the ftosf functions.

### Errors

#### type error[link]

type error = !(invalid | overflow);

Any error which may be returned from a strconv function.

#### type invalid[link]

type invalid = !size;

Indicates that the input string doesn't have the requested number format (integer or float). Contains the index of the first invalid rune.

#### type overflow[link]

type overflow = !void;

Indicates that the input member can't be represented by the requested data type.

### Functions

#### fn f32tos[link]

fn f32tos(n: f32) const str;

Converts a f32 to a string in base 10. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result. The result is equivalent to ftosf with format G and precision void.

#### fn f64tos[link]

fn f64tos(n: f64) const str;

Converts a f64 to a string in base 10. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result. The result is equivalent to ftosf with format G and precision void.

#### fn fftosf[link]

fn fftosf(h: io::handle, n: types::floating, f: ffmt, prec: (void | uint), flag: fflags) (size | io::error);

Converts a types::floating to a string in base 10 and writes the result to the provided handle. Format parameters are as in ftosf.

#### fn floatingtos[link]

fn floatingtos(n: types::floating, b: base = base::DEC) const str;

Converts any types::floating to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result. If base is not specified, base 10 is used.

#### fn ftosf[link]

fn ftosf(n: types::floating, f: ffmt, prec: (void | uint), flag: fflags) str;

Converts any types::floating to a string in base 10. The return value must be freed.

A precision of void yields the smallest number of digits that can be parsed into the exact same number. Otherwise, the meaning depends on f:

- ffmt::F, ffmt::E: Number of digits after the decimal point.
- ffmt::G: Number of significant digits. 0 is equivalent to 1 precision, and trailing zeros are removed.

#### fn i16tos[link]

fn i16tos(i: i16, b: base = base::DEC) const str;

Converts an i16 to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn i32tos[link]

fn i32tos(i: i32, b: base = base::DEC) const str;

Converts an i32 to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn i64tos[link]

fn i64tos(i: i64, b: base = base::DEC) const str;

Converts an i64 to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn i8tos[link]

fn i8tos(i: i8, b: base = base::DEC) const str;

Converts an i8 to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn integertos[link]

fn integertos(n: types::integer, b: base = base::DEC) const str;

Converts any types::integer to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result. If base is not specified, base 10 is used.

#### fn itos[link]

fn itos(i: int, b: base = base::DEC) const str;

Converts an int to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn numerictos[link]

fn numerictos(n: types::numeric, b: base = base::DEC) const str;

Converts any types::numeric to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result. If base is not specified, base 10 is used.

#### fn signedtos[link]

fn signedtos(n: types::signed, b: base = base::DEC) const str;

Converts any types::signed to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result. If base is not specified, base 10 is used.

#### fn stof32[link]

fn stof32(s: str, b: base = base::DEC) (f32 | invalid | overflow);

Converts a string to a f32 in base::DEC or base::HEX. If base is not provided, base::DEC is used. If the string is not a syntactically well-formed floating-point number, invalid is returned. If the string represents a floating-point number that is larger than the largest finite f32 number, overflow is returned. Zero is returned if the string represents a floating-point number that is smaller than the f32 number nearest to zero with respective sign. Recognizes "Infinity", "+Infinity", "-Infinity", and "NaN", case insensitive.

#### fn stof64[link]

fn stof64(s: str, b: base = base::DEC) (f64 | invalid | overflow);

Converts a string to a f64 in base::DEC or base::HEX. If base is not provided, base::DEC is used. If the string is not a syntactically well-formed floating-point number, invalid is returned. If the string represents a floating-point number that is larger than the largest finite f64 number, overflow is returned. Zero is returned if the string represents a floating-point number that is smaller than the f64 number nearest to zero with respective sign. Recognizes "Infinity", "+Infinity", "-Infinity", and "NaN", case insensitive.

#### fn stoi[link]

fn stoi(s: str, base: base = base::DEC) (int | invalid | overflow);

Converts a string to an int. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by an int.

#### fn stoi16[link]

fn stoi16(s: str, base: base = base::DEC) (i16 | invalid | overflow);

Converts a string to an i16. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by an i16.

#### fn stoi32[link]

fn stoi32(s: str, base: base = base::DEC) (i32 | invalid | overflow);

Converts a string to an i32. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by an i32.

#### fn stoi64[link]

fn stoi64(s: str, base: base = base::DEC) (i64 | invalid | overflow);

Converts a string to an i64. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by an i64.

#### fn stoi8[link]

fn stoi8(s: str, base: base = base::DEC) (i8 | invalid | overflow);

Converts a string to an i8. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by an i8.

#### fn stou[link]

fn stou(s: str, base: base = base::DEC) (uint | invalid | overflow);

Converts a string to a uint in the given base. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by a uint.

#### fn stou16[link]

fn stou16(s: str, base: base = base::DEC) (u16 | invalid | overflow);

Converts a string to a u16. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by a u16.

#### fn stou32[link]

fn stou32(s: str, base: base = base::DEC) (u32 | invalid | overflow);

Converts a string to a u32. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by a u32.

#### fn stou64[link]

fn stou64(s: str, base: base = base::DEC) (u64 | invalid | overflow);

Converts a string to a u64. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by a u64.

#### fn stou8[link]

fn stou8(s: str, base: base = base::DEC) (u8 | invalid | overflow);

Converts a string to a u8. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by a u8.

#### fn stoz[link]

fn stoz(s: str, base: base = base::DEC) (size | invalid | overflow);

Converts a string to a size. Returns invalid if the string is empty or contains invalid characters. Returns overflow if the number is too large to be represented by a size.

#### fn strerror[link]

fn strerror(err: error) str;

Converts an strconv error into a user-friendly string.

#### fn u16tos[link]

fn u16tos(u: u16, b: base = base::DEC) const str;

Converts a u16 to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn u32tos[link]

fn u32tos(u: u32, b: base = base::DEC) const str;

Converts a u32 to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn u64tos[link]

fn u64tos(u: u64, b: base = base::DEC) const str;

Converts a u64 to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn u8tos[link]

fn u8tos(u: u8, b: base = base::DEC) const str;

Converts a u8 to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn unsignedtos[link]

fn unsignedtos(n: types::unsigned, b: base = base::DEC) const str;

Converts any types::unsigned to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result. If base is not specified, base 10 is used.

#### fn uptrtos[link]

fn uptrtos(uptr: uintptr, b: base = base::DEC) const str;

Converts a uintptr to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn utos[link]

fn utos(u: uint, b: base = base::DEC) const str;

Converts a uint to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.

#### fn ztos[link]

fn ztos(u: size, b: base = base::DEC) const str;

Converts a size to a string. The return value is statically allocated and will be overwritten on subsequent calls; see strings::dup to duplicate the result.