parse_int_radix
fn parse_int_radix(string s, int radix) -> Result<int, string> Import
Source: use conv::{parse_int_radix}; src/conv.hy Parses an integer written in base radix, which must be 10 or 16.
Surrounding ASCII whitespace and one leading + or - are accepted. Hex
digits may be either case; there is no 0x prefix.
Parameters#
| Name | Type |
|---|---|
s | string |
radix | int |
Returns#
Result<int, string>
Errors#
Err("invalid integer") for empty or non-digit text and Err("invalid radix")
for any other radix. A value that does not fit in an int currently panics
instead of returning an error (coil-stdlib#53).
Examples#
use conv::{parse_int_radix};
use tests::assert;
assert!((parse_int_radix("ff", 16) ?? 0) == 255);
assert!((parse_int_radix("-10", 10) ?? 0) == -10);
assert!(parse_int_radix("12", 8).is_err());
See also#
intint_to_dec: Formatsnin decimal; the same asformat("%i", n).int_to_hex: Formatsnin lowercase hexadecimal without a prefix; a negativengets a leading-.int_to_bin: Formatsnin binary without a prefix; a negativengets a leading-.parse_int: Parses a decimal integer, such as"42"," -7 "or"+3".parse_float: Parses a decimal float such as"3.5","-0.25","1e3"or"42".