strconv+x86_64 +linux
strconv: conversion between strings and numeric types
The strconv module provides functions for parsing strings into numeric datatypes and formatting numbers into strings.
Index
Types
type base; type fflags; type ffmt;
Errors
type error; type invalid; type overflow;
Functions
fn f32tos(n: f32) str; fn f64tos(n: f64) str; fn fftosf(h: io::handle, n: types::floating, f: ffmt = ffmt::G, prec: (void | uint) = void, flag: fflags = fflags::NONE) (size | io::error); fn ftosf(n: types::floating, f: ffmt = ffmt::G, prec: (void | uint) = void, flag: fflags = fflags::NONE) (str | nomem); fn i16tos(i: i16, b: base = base::DEC) str; fn i32tos(i: i32, b: base = base::DEC) str; fn i64tos(i: i64, b: base = base::DEC) str; fn i8tos(i: i8, b: base = base::DEC) str; fn itos(i: int, b: base = base::DEC) 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) str; fn u32tos(u: u32, b: base = base::DEC) str; fn u64tos(u: u64, b: base = base::DEC) str; fn u8tos(u: u8, b: base = base::DEC) str; fn uptrtos(uptr: uintptr, b: base = base::DEC) str; fn utos(u: uint, b: base = base::DEC) str; fn ztos(u: size, b: base = base::DEC) str;
Types
type base[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
type error = !(invalid | overflow);
Any error which may be returned from a strconv function.
type invalid[permalink] [source]
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[permalink] [source]
type overflow = !void;
Indicates that the input member can't be represented by the requested data type.
Functions
fn f32tos[permalink] [source]
fn f32tos(n: f32) 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[permalink] [source]
fn f64tos(n: f64) 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[permalink] [source]
fn fftosf(h: io::handle, n: types::floating, f: ffmt = ffmt::G, prec: (void | uint) = void, flag: fflags = fflags::NONE) (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 ftosf[permalink] [source]
fn ftosf(n: types::floating, f: ffmt = ffmt::G, prec: (void | uint) = void, flag: fflags = fflags::NONE) (str | nomem);
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[permalink] [source]
fn i16tos(i: i16, b: base = base::DEC) 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[permalink] [source]
fn i32tos(i: i32, b: base = base::DEC) 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[permalink] [source]
fn i64tos(i: i64, b: base = base::DEC) 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[permalink] [source]
fn i8tos(i: i8, b: base = base::DEC) 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 itos[permalink] [source]
fn itos(i: int, b: base = base::DEC) 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 stof32[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
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[permalink] [source]
fn strerror(err: error) str;
Converts an strconv error into a user-friendly string.
fn u16tos[permalink] [source]
fn u16tos(u: u16, b: base = base::DEC) 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[permalink] [source]
fn u32tos(u: u32, b: base = base::DEC) 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[permalink] [source]
fn u64tos(u: u64, b: base = base::DEC) 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[permalink] [source]
fn u8tos(u: u8, b: base = base::DEC) 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 uptrtos[permalink] [source]
fn uptrtos(uptr: uintptr, b: base = base::DEC) 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[permalink] [source]
fn utos(u: uint, b: base = base::DEC) 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[permalink] [source]
fn ztos(u: size, b: base = base::DEC) 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.