strconv
The strconv module provides functions for parsing strings into numeric datatypes
and formatting numbers into strings.
Index
Types
type base;
Errors
type error;
type invalid;
type overflow;
Functions
fn f32tos(f32) const str;
fn f64tos(f64) const str;
fn floatingtos(types::floating) const str;
fn floatingtosb(types::floating, base) const str;
fn i16tos(i16) const str;
fn i16tosb(i16, base) const str;
fn i32tos(i32) const str;
fn i32tosb(i32, base) const str;
fn i64tos(i64) const str;
fn i64tosb(i64, base) const str;
fn i8tos(i8) const str;
fn i8tosb(i8, base) const str;
fn integertos(types::integer) const str;
fn integertosb(types::integer, base) const str;
fn itos(int) const str;
fn itosb(int, base) const str;
fn numerictos(types::numeric) const str;
fn numerictosb(types::numeric, base) const str;
fn signedtos(types::signed) const str;
fn signedtosb(types::signed, base) const str;
fn stof32(str) (f32 | invalid | overflow);
fn stof64(str) (f64 | invalid | overflow);
fn stoi(str) (int | invalid | overflow);
fn stoi16(str) (i16 | invalid | overflow);
fn stoi16b(str, base) (i16 | invalid | overflow);
fn stoi32(str) (i32 | invalid | overflow);
fn stoi32b(str, base) (i32 | invalid | overflow);
fn stoi64(str) (i64 | invalid | overflow);
fn stoi64b(str, base) (i64 | invalid | overflow);
fn stoi8(str) (i8 | invalid | overflow);
fn stoi8b(str, base) (i8 | invalid | overflow);
fn stoib(str, base) (int | invalid | overflow);
fn stou(str) (uint | invalid | overflow);
fn stou16(str) (u16 | invalid | overflow);
fn stou16b(str, base) (u16 | invalid | overflow);
fn stou32(str) (u32 | invalid | overflow);
fn stou32b(str, base) (u32 | invalid | overflow);
fn stou64(str) (u64 | invalid | overflow);
fn stou64b(str, base) (u64 | invalid | overflow);
fn stou8(str) (u8 | invalid | overflow);
fn stou8b(str, base) (u8 | invalid | overflow);
fn stoub(str, base) (uint | invalid | overflow);
fn stoz(str) (size | invalid | overflow);
fn stozb(str, base) (size | invalid | overflow);
fn strerror(error) str;
fn u16tos(u16) const str;
fn u16tosb(u16, base) const str;
fn u32tos(u32) const str;
fn u32tosb(u32, base) const str;
fn u64tos(u64) const str;
fn u64tosb(u64, base) const str;
fn u8tos(u8) const str;
fn u8tosb(u8, base) const str;
fn unsignedtos(types::unsigned) const str;
fn unsignedtosb(types::unsigned, base) const str;
fn uptrtos(uintptr) const str;
fn uptrtosb(uintptr, base) const str;
fn utos(uint) const str;
fn utosb(uint, base) const str;
fn ztos(size) const str;
fn ztosb(size, base) const str;
Types
type base
type base = enum uint {
DEFAULT = 0,
BIN = 2,
OCT = 8,
DEC = 10,
HEX_UPPER = 16,
HEX = 16,
HEX_LOWER = 17,
};
The valid numeric bases for numeric conversions.
Errors
type error
type error = !(invalid | overflow);
Any error which may be returned from a strconv function.
type invalid
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
type overflow = !void;
Indicates that the input member can't be represented by the requested data
type.
Functions
fn f32tos
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.
fn f64tos
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.
fn floatingtos
fn floatingtos(n: types::floating) const str;
Converts any types::floating 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.
fn floatingtosb
fn floatingtosb(n: types::floating, b: base) const str;
Converts any types::floating to a string in a given base. The return value
is statically allocated and will be overwritten on subsequent calls; see
strings::dup to duplicate the result.
fn i16tos
fn i16tos(i: i16) const str;
Converts an i16 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.
fn i16tosb
fn i16tosb(i: i16, b: base) const str;
Converts an i16 to a string in the given base. The return value is statically
allocated and will be overwritten on subsequent calls; see strings::dup to
duplicate the result.
fn i32tos
fn i32tos(i: i32) const str;
Converts an i32 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.
fn i32tosb
fn i32tosb(i: i32, b: base) const str;
Converts an i32 to a string in the given base. The return value is statically
allocated and will be overwritten on subsequent calls; see strings::dup to
duplicate the result.
fn i64tos
fn i64tos(i: i64) const str;
Converts an i64 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.
fn i64tosb
fn i64tosb(i: i64, b: base) const str;
Converts an i64 to a string in the given base. The return value is statically
allocated and will be overwritten on subsequent calls; see strings::dup to
duplicate the result.
fn i8tos
fn i8tos(i: i8) const str;
Converts an i8 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.
fn i8tosb
fn i8tosb(i: i8, b: base) const str;
Converts an i8 to a string in the given base. The return value is statically
allocated and will be overwritten on subsequent calls; see strings::dup to
duplicate the result.
fn integertos
fn integertos(n: types::integer) const str;
Converts any types::integer 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.
fn integertosb
fn integertosb(n: types::integer, b: base) const str;
Converts any types::integer to a string in a given base, which must be 2,
8, 10, or 16. The return value is statically allocated and will be
overwritten on subsequent calls; see strings::dup to duplicate the result.
fn itos
fn itos(i: int) const str;
Converts an int 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.
fn itosb
fn itosb(i: int, b: base) const str;
Converts an int to a string in the given base. The return value is
statically allocated and will be overwritten on subsequent calls; see
strings::dup to duplicate the result.
fn numerictos
fn numerictos(n: types::numeric) const str;
Converts any types::numeric 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.
fn numerictosb
fn numerictosb(n: types::numeric, b: base) const str;
Converts any types::numeric to a string in a given base. The return value
is statically allocated and will be overwritten on subsequent calls; see
strings::dup to duplicate the result.
fn signedtos
fn signedtos(n: types::signed) const str;
Converts any types::signed 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.
fn signedtosb
fn signedtosb(n: types::signed, b: base) const str;
Converts any types::signed to a string in a given base. The return value is
statically allocated and will be overwritten on subsequent calls; see
strings::dup to duplicate the result.
fn stof32
fn stof32(s: str) (f32 | invalid | overflow);
Converts a string to a f32. If the string is not syntactically well-formed
floating-point number in base 10, 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 f32 number nearest to zero
with respective sign.
Recognizes "Infinity", "+Infinity", "-Infinity", and "NaN", case insensitive.
fn stof64
fn stof64(s: str) (f64 | invalid | overflow);
Converts a string to a f64. If the string is not syntactically well-formed
floating-point number in base 10, 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
fn stoi(s: str) (int | invalid | overflow);
Converts a string to an int in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by an int, overflow is
returned.
fn stoi16
fn stoi16(s: str) (i16 | invalid | overflow);
Converts a string to an i16 in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by an i16, overflow is
returned.
fn stoi16b
fn stoi16b(s: str, base: base) (i16 | invalid | overflow);
Converts a string to an i16 in the given base. If the string contains any
non-numeric characters, except '-' or '+' at the start, or if it's empty,
invalid is returned. If the number is too large to be represented by an
i16, overflow is returned.
fn stoi32
fn stoi32(s: str) (i32 | invalid | overflow);
Converts a string to an i32 in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by an i32, overflow is
returned.
fn stoi32b
fn stoi32b(s: str, base: base) (i32 | invalid | overflow);
Converts a string to an i32 in the given base. If the string contains any
non-numeric characters, except '-' or '+' at the start, or if it's empty,
invalid is returned. If the number is too large to be represented by an
i32, overflow is returned.
fn stoi64
fn stoi64(s: str) (i64 | invalid | overflow);
Converts a string to an i64 in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by an i64, overflow is
returned.
fn stoi64b
fn stoi64b(s: str, base: base) (i64 | invalid | overflow);
Converts a string to an i64 in the given base. If the string contains any
non-numeric characters, except '-' or '+' at the start, or if it's empty,
invalid is returned. If the number is too large to be represented by an
i64, overflow is returned.
fn stoi8
fn stoi8(s: str) (i8 | invalid | overflow);
Converts a string to an i8 in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by an i8, overflow is
returned.
fn stoi8b
fn stoi8b(s: str, base: base) (i8 | invalid | overflow);
Converts a string to an i8 in the given base. If the string contains any
non-numeric characters, except '-' or '+' at the start, or if it's empty,
invalid is returned. If the number is too large to be represented by an
i8, overflow is returned.
fn stoib
fn stoib(s: str, base: base) (int | invalid | overflow);
Converts a string to an int in the given base. If the string contains any
non-numeric characters, except '-' or '+' at the start, or if it's empty,
invalid is returned. If the number is too large to be represented by an
int, overflow is returned.
fn stou
fn stou(s: str) (uint | invalid | overflow);
Converts a string to a uint in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a uint, overflow is returned.
fn stou16
fn stou16(s: str) (u16 | invalid | overflow);
Converts a string to a u16 in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a u16, overflow is returned.
fn stou16b
fn stou16b(s: str, base: base) (u16 | invalid | overflow);
Converts a string to a u16 in the given base, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a u16, overflow is returned.
fn stou32
fn stou32(s: str) (u32 | invalid | overflow);
Converts a string to a u32 in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a u32, overflow is returned.
fn stou32b
fn stou32b(s: str, base: base) (u32 | invalid | overflow);
Converts a string to a u32 in the given base, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a u32, overflow is returned.
fn stou64
fn stou64(s: str) (u64 | invalid | overflow);
Converts a string to a u64 in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a u64, overflow is returned.
fn stou64b
fn stou64b(s: str, base: base) (u64 | invalid | overflow);
Converts a string to a u64 in the given base, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a u64, overflow is returned.
fn stou8
fn stou8(s: str) (u8 | invalid | overflow);
Converts a string to a u8 in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a u8, overflow is returned.
fn stou8b
fn stou8b(s: str, base: base) (u8 | invalid | overflow);
Converts a string to a u8 in the given base, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a u8, overflow is returned.
fn stoub
fn stoub(s: str, base: base) (uint | invalid | overflow);
Converts a string to a uint in the given base, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a uint, overflow is returned.
fn stoz
fn stoz(s: str) (size | invalid | overflow);
Converts a string to a size in base 10, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a size, overflow is returned.
fn stozb
fn stozb(s: str, base: base) (size | invalid | overflow);
Converts a string to a size in the given base, If the string contains any
non-numeric characters, or if it's empty, invalid is returned. If the
number is too large to be represented by a size, overflow is returned.
fn strerror
fn strerror(err: error) str;
Converts an strconv error into a user-friendly string.
fn u16tos
fn u16tos(u: u16) const str;
Converts a u16 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.
fn u16tosb
fn u16tosb(u: u16, b: base) const str;
Converts a u16 to a string in the given base. The return value is statically
allocated and will be overwritten on subsequent calls; see strings::dup to
duplicate the result.
fn u32tos
fn u32tos(u: u32) const str;
Converts a u32 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.
fn u32tosb
fn u32tosb(u: u32, b: base) const str;
Converts a u32 to a string in the given base. The return value is statically
allocated and will be overwritten on subsequent calls; see strings::dup to
duplicate the result.
fn u64tos
fn u64tos(u: u64) const str;
Converts a u64 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.
fn u64tosb
fn u64tosb(u: u64, b: base) const str;
Converts a u64 to a string in the given base. The return value is statically
allocated and will be overwritten on subsequent calls; see strings::dup to
duplicate the result.
fn u8tos
fn u8tos(u: u8) const str;
Converts a u8 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.
fn u8tosb
fn u8tosb(u: u8, b: base) const str;
Converts a u8 to a string in the given base. The return value is statically
allocated and will be overwritten on subsequent calls; see strings::dup to
duplicate the result.
fn unsignedtos
fn unsignedtos(n: types::unsigned) const str;
Converts any types::unsigned 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.
fn unsignedtosb
fn unsignedtosb(n: types::unsigned, b: base) const str;
Converts any types::unsigned to a string in a given base. The return value
is statically allocated and will be overwritten on subsequent calls; see
strings::dup to duplicate the result.
fn uptrtos
fn uptrtos(uptr: uintptr) const str;
Converts a uintptr 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.
fn uptrtosb
fn uptrtosb(uptr: uintptr, b: base) const str;
Converts a uintptr to a string in the given base. The return value is
statically allocated and will be overwritten on subsequent calls; see
strings::dup to duplicate the result.
fn utos
fn utos(u: uint) const str;
Converts a uint 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.
fn utosb
fn utosb(u: uint, b: base) const str;
Converts a uint to a string in the given base. The return value is
statically allocated and will be overwritten on subsequent calls; see
strings::dup to duplicate the result.
fn ztos
fn ztos(z: size) const str;
Converts a size 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, or itosb to pass your own string buffer.
fn ztosb
fn ztosb(u: size, b: base) const str;
Converts a size to a string in the given base. The return value is
statically allocated and will be overwritten on subsequent calls; see
strings::dup to duplicate the result.